Improved Tag Clouds
I wrote before about creating tag clouds with Turbogears though the idea is the same in pretty much any language you use : Split the bucket of things that you have into smaller buckets, assign each bucket a size and then display them.
Really it's mostly about how you split the categories into the buckets, how many elements end up in each one.
Lets say you have a bunch of categories and each one has a number of elements within it. You want to display the category names with each name in a size relative to the number of elements in it.
My last attempt looked at the min and max number of categories and divided it into 5 buckets each identified by it's own CSS class. Here are those classes.
so far so good. What gets put into what bucket was determined by whether you were a min value (smallestTag), max value (largestTag) or somewhere between the buckets (small, medium and Large Tags). Here's the code:
The problem with it is that you can get a lot of bunching when your distribution is uneven. If your largest category has 100 items but the others are in the range 1-10 your tag cloud isn't going to have a lot of variation.
This happened to me a lot. So I figured better to split the distribution into an even number of buckets regardless of the distribution.
Enter Recipe 425397 Split a list into roughly equal-sized pieces on ASPN. The code is short if not exactly a simple read :
So now we can split up our categories by the number of buckets we want easily and our old code is changed to (something like, not tested):
Overall the result should be better for uneven distributions and give a more pleasing effect.