Brown Eyed Girl (browneyedgirl65) wrote in component_help,
Brown Eyed Girl
browneyedgirl65
component_help

  • Mood:

tag cloud

Since I've started using delicious, it occurred to me I'd like to see my lj tags as a cloud as well. It didn't even take me too long to do! :)

Ok the basic code is this. You will need to add it to print_free_text; position it anywhere you'd like for your component ordering.

Add the following variables up in the variable list at the start of print_free_text.
If you have another tags component, which I searched for here but didn't find offhand though I know I got it from here, you might already have some of them. This would be the tags version that made a scrolling, tabled list of tag/count items. If you have that, you'll have the first two vars already. Add in whichever ones you don't have already.


var int tag_count = 0;
var TagDetail[] my_tags = $p->visible_tag_list();
var int used;
var int min=1;
var int max=1;
var int interval;
var int adjust;


Now here's the code for the cloud stuff...this can be simply added in if you have no tag based component at present. If you already have another table component you want to replace this with, comment or delete the old code out first (ALWAYS ALWAYS save off a copy of your current layer stuff that's working into Notepad or Kwrite, or [whatever mac users have]...). Add the code below in the position/order of all the extra components you have in this function the way you want it to show up on your journal.

print_comp_header("Category Cloud");

#implement cloudstyle ala delicious, etc
if ($my_tags)
{
"""
<div style="position:relative; width:100%">
<table name="taglist" width=100% cellpadding=3>
""";

#get max
foreach var TagDetail t ($my_tags)
{
if (viewer_is_owner() or ($t.visibility!="private"))
{
if ($t.use_count > $max)
{
$max=$t.use_count;
}
}
}


#now we get interval, go four stages,
#otherwise fonts too big
#this does depend on your font; feel free
#to try values of three or four to
#change the number of steps based
#on your tag distribution
$interval = $max/4;


#now print each item, and adjust its
#fontsize as a function of where in the
#continuum of four intervals it is
foreach var TagDetail t ($my_tags)
{
if (viewer_is_owner() or ($t.visibility!="private"))
{
$adjust=$t.use_count/$interval*20+100;
"""
<span style="font-size:$adjust%"><a rel="tag" href="$t.url">$t.name</a></span> 
""";
}
}

"""
</table name="taglist">
</div>
""";
}

else
{
"""<p>There are currently no tags or categories for this journal.</p>""";
}

print_comp_footer();



I apologize for the vertical "flattening" of the code....honest, I pasted it in here with good indentation, but I'm not entirely sure how to force this to display that, if I even can...

You can go to my page to see how the end result looks...You can look at my layer too if you like, but be warned that my stuff is packaged up into independent little functions that may or may not make sense to you especially if you're not a programmer (layer id=4818666). As I recall it scared even kunzite1 once :D

:blinkblink: whoa, just looked at your journal, kunzite1...I picked up the borg icon just a few days ago myself...
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic
  • 13 comments