?

Log in

No account? Create an account
[theme] - [component] - [tagcloud component] - S2 Layers — LiveJournal [entries|archive|friends|userinfo]
S2 Layers

[ website | advanced customization ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| how to post tags page ]
[affiliated communities| fblayers ]

[theme] - [component] - [tagcloud component] [Dec. 14th, 2005|01:18 pm]
S2 Layers

s2layers

[kunzite1]
[Tags|, ]

in response to browneyedgirl65's component_help post.
var string      header      = "";
var string      content     = "";

var int         int_groups  =   5; # number of groups
var int         int_percent =  20; # perecentage difference for each interval

$header = "Category Cloud";

var int         adjust      = 0; # font size adjustment
var int         factor      = 0; # factor of font size adjustment
var int         interval    = 0; # tag use count interval per group
var int         max         = 1; # max number of tag uses
var TagDetail[] my_tags     = $p->visible_tag_list(); # list of visible tags

# implement cloudstyle ala delicious, etc
if ($my_tags) {
  $content = $content + """
  <table name="taglist" width="100%" cellpadding="3">
    <tr>
      <td>
  """;

  # get max
  foreach var TagDetail t ($my_tags) {
    if($t.use_count > $max) {
      $max = $t.use_count;
    }
  }

  # now we get tag use count interval per group
  $interval = $max / $int_groups;

  # now print each item, and adjust its
  # fontsize as a function of where in the
  # continuum of $int_groups intervals it is
  foreach var TagDetail t ($my_tags) {
    # if we're not going to divide by 0
    if($interval > 0) {
      # get the proportion based on use_count and interval
      $factor = $t.use_count / $interval;
    } else {
      # if we're dividing by 0, set factor to 0
      $factor = 0;
    }
    $adjust  = ($factor * $int_percent) + 100;
    $content = $content + """<span style="font-size: ${adjust}%"><a rel="tag" href="$t.url">$t.name</a></span> """;
  }
  $content = $content + """
      </td>
    </tr>
  </table>
  """;
} else {
  $content = $content + """<p>There are currently no tags or categories for this journal.</p>""";
}

print_comp_header($header);
print $content;
print_comp_footer();
linkReply

Comments:
[User Picture]From: xtomxfallsx
2005-12-14 10:29 pm (UTC)
Ok, so what's this error all about?
Error running style: Died in S2::run_code running EntryPage::print(): Illegal division by zero at (eval 310) line 310.


I'm getting it when viewing this entry on xmorningxrosex's journal (which you can't see because it's friends only) in my style.

I can have her add you if you need to see it.
(Reply) (Thread)
[User Picture]From: kunzite1
2005-12-14 10:51 pm (UTC)

hmm. the only way that i think that could happen is if $max resolves to 0. which in turn would make $interval 0. which would definitely cause a "divide by 0" error.
(Reply) (Parent) (Thread)
[User Picture]From: xtomxfallsx
2005-12-14 10:56 pm (UTC)
But $max is being set to 1 when it is declared. Why would it then go back to 0?
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-14 10:58 pm (UTC)

you are correct. but 1/5 in integer math is still 0.
(Reply) (Parent) (Thread)
[User Picture]From: browneyedgirl65
2005-12-14 11:06 pm (UTC)
I've probably already fixed this in my version, where I added a check for the current count being one or two and dropping below 100% font size for those. It sounds to me like she may not have any more than one use of each of her tags for max to be 1? Hmmmmm...
(Reply) (Parent) (Thread)
[User Picture]From: xtomxfallsx
2005-12-14 11:12 pm (UTC)
Yes, that's exactly it. You commented before I could finish my reply below. Looks like I was on the right track, though.
(Reply) (Parent) (Thread)
[User Picture]From: xtomxfallsx
2005-12-14 11:11 pm (UTC)
Ok, so the code could be better, then.

As it is, it doesn't allow for viewing entries/journals in your own style where $max would be less than $int_groups. This turns into a big problem when following LJ cuts or reading comments from the friends page.

I added this bit after the section where it gets $max to "fix" it:
if($max < $int_groups) {
 $max = $int_groups;
}


It's far from perfect, but at least it doesn't produce an error.
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-14 11:12 pm (UTC)

that's kinda like the fix i was thinking.

the fix that the other user created for hers isn't as extensible as this. tho, it does do the spiffiness of shrinking the text to below 100%.
(Reply) (Parent) (Thread)
[User Picture]From: xtomxfallsx
2005-12-14 11:14 pm (UTC)
Yeah, my solution results in large text for all tags.
(Reply) (Parent) (Thread)
[User Picture]From: browneyedgirl65
2005-12-14 11:43 pm (UTC)
I'm pondering this as I *was* thinking about it when I wrote this originally (but it worked fine for my code, so I let it be). The real problem is the stretch of the interval. If you go from 1 to say 1,957 on your max because you're such a prolific writer/tagger (heh), the intervals won't be as informative

You really want to do some type of cluster analysis and pick out the high points. But I defy that to be done quickly in these layer things, where I notice anything too computationally intensive turns into "Infinite loop or database problem" signposting on your stuff...

(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-14 11:58 pm (UTC)

i've updated the entry to reflect the new code that i developed. it seems to work pretty well.
(Reply) (Parent) (Thread)
[User Picture]From: browneyedgirl65
2005-12-16 04:32 pm (UTC)
Yeah that looks good. I did a few tweaks myself, where $min becomes adjustable, so anything with a count between 1 and $min go undersize. That way you can pull up the bottom if you like...I'll have to experiment with friend pages; I turn off most side components on friend pages, I didn't find them terribly useful and if I'm looking at a friend's entries in detail, I jump over to their style anyway. Thanks for letting me know where the structural weaknesses were.

It's only as good as your testing sample :pffft: Heh.

(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-16 07:11 pm (UTC)

my code is meant to be taken and tweaked to the user's liking. yay.

just make sure that you know what you're doing when you're tweaking. ;)

altho, it might be nifty to see the different tagclouds and you go from journal to journal.

and yeah, only as good as the group of tags is. some journals have less that are more spread out. others don't have very many at all or even none.

whee. :)
(Reply) (Parent) (Thread)
[User Picture]From: browneyedgirl65
2005-12-16 09:01 pm (UTC)
Exactly. I guess I didn't pop it into any of the friends pages, because...which friend? I mean, the friends page will list all the most recent entries for each friend, so there's multiple on that page and so you put up a tag cloud of ... whose?
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-16 09:10 pm (UTC)

oh! i totally thought you were talking about style=mineing another journal. that would show their tags in a cloud.

FriendsPage is a different story. i did however implement a "tags in this page" box that would show tags on views other than friends. if you do it on FriendsPage you need to make sure to have the url to the corresponding friend. and it would do that if you don't do a hacky job of it. you know, the right way would be to use Entry.tags[i].url.
(Reply) (Parent) (Thread)
[User Picture]From: thaumata
2005-12-17 09:19 pm (UTC)

i heart this.

does this have to go into another component, like a free text box? i am confused and rusty at this.
(Reply) (Thread)
[User Picture]From: thaumata
2005-12-17 10:15 pm (UTC)

Re: i heart this.

never mind. i got it. :) this is so neat and i'm so happy to have it! not being able to conveniently include tags was the reason i had to switch styles before. this rocks!
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-17 10:16 pm (UTC)

Re: i heart this.

awesome. :)
(Reply) (Parent) (Thread)
[User Picture]From: thaumata
2005-12-17 10:52 pm (UTC)

Re: i heart this.

yes. i am mostly self-serve. but you can probably expect a rash of "wait, wtf did i do???" followed by "oh, wait. here." comments from me this weekend.

:D


you are always so helpful, though. you helped me way back in the day when i was still writing in thatdirtyblonde. w00t.
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2005-12-17 10:54 pm (UTC)

Re: i heart this.

good to know that you're learning.

i've been playing with s2 for about 2 years and 4 months now.
(Reply) (Parent) (Thread)
From: respect
2006-07-04 05:31 pm (UTC)
Where do we put this in our layer edit page?
(Reply) (Thread)
From: moveablehistory
2006-09-26 02:47 am (UTC)
I'm sorry for the random question, but do you know if one could apply this to Opal? I've fiddled with it but I haven't had any success, and I was wondering if you knew of a way.

Thanks for any help. :)
(Reply) (Thread)
[User Picture]From: kunzite1
2006-09-26 02:51 am (UTC)
it should go into either function Page::lay_print_sidebar () or function Page::lay_print_freetext ().

you'll need to add var Page p = $this; to near the top of the code.

then the bottom 3 lines need to become:
print_box($header, $content);
(Reply) (Parent) (Thread)
From: moveablehistory
2006-09-26 03:43 am (UTC)
Worked spiffingly, thank you kindly. :)
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-09-26 03:43 am (UTC)
yay. :D
(Reply) (Parent) (Thread)
[User Picture]From: stickykeys633
2007-01-11 02:40 am (UTC)
I know I'm late the to the fame, this is a fantastic tut and worked like a charm. I only have one question, where can I put an image or character to separate the tags? I really want & hearts ; for mini heart between each tag. I'm sure it's something simple, but I couldn't quite figure it out. Thanks!
(Reply) (Thread)
[User Picture]From: kunzite1
2007-01-11 05:46 am (UTC)
basic idea: create a counter that you increment during the loop. check to see if the counter is less than the size of $my_tags and if it's not, append &hearts; to $content.
(Reply) (Parent) (Thread)
[User Picture]From: stickykeys633
2007-01-11 08:52 am (UTC)
Got it! I thank thee.
(Reply) (Parent) (Thread)