Tag Cloud

Of the growing number of 2.0 related stuff that is appear now-a-days, the tag clouds is an interesting one in that takes a standard list and tranforms it into other visual depictions.

I decide to have go at generating a simple cloud tag, I all ready had a list of news categories and the number of post in each one so I thought it wouldn’t be a step too far.
After quick Google to determine the best methods of displying the information, I decide that i would use a simple font size alteration based on the count of the category.

First tasks to decide on the number of levels I want to have in my cloud. I decided on 3 as this would allow enough differences for the total number I was dealing with.

So now we needed to split out the levels so when needed the highest possible count for 1 category and to divide by the number of levels we are using, this will give us the range of each level.

highest_category_total/number_of_levels = range

Now using the same information that we see in a standard list:
Topic1 = 3
Topic2 = 15
Topic3 = 8

Using a simple section of code to determine the level that each category falls into.

This example shows how it works

(highest_category_total/number_of_levels = range)
Range = 15 / 3

Level1 = 1-5 ( highest_category_total – Range *3)
Level2 = 6-10 ( highest_category_total – Range*2)
Level3 = 11-15 ( highest_category_total – Range)

therefore :
topic1 fails into level1
topic2 fails into level3
topic3 fails into level2