What algorithm can I use to sort tags for tag cloud?

837 Views Asked by At

So I am creating a tag cloud containing X amount of tags. Something like this http://upload.wikimedia.org/wikipedia/commons/a/a7/Web_2.0_Map.svg The more often a keyword is used the bigger then font size it will have. For my tag cloud, I have X amount of tags which I will need to group by font size. I have a structure called a FacetBucket which contains the tag and its frequency. Most commonly used phrases will have the largest font size and least frequently used terms will have the smallest font size. The moderately used terms will all have font sizes between the largest and smallest. SO my problem is that I have X amount of tags and Y amount of font sizes, what kind of algorithm should I be looking for to solve my problem?

2

There are 2 best solutions below

2
On
  1. You need to decide on the limited set of font sizes you intend to use (which depends on your GUI implementation).

  2. Then you will assign each size to ranges of tag frequencies. Ranges will depend on X and Y values.

That will determine which font size each frequency get, with the understanding that close in value frequencies are to be displayed in the same size as long as number of tags exceeds the available amount of font sizes.

There is not much of algorithm actually needed.

0
On

For anyone else looking to do something simillar heres an equation that helps.

We will use the following variables, namely:
a = the smallest count (or occurrence).
b = the count of the tag being computed.
c = the largest count.
w = the smallest font-size.
x = the font-size for the tag. It is the unknown.
y = the largest font-size.


Now let's substitute the given values to their respective variables. Assuming that we are solving for the "thanksgiving" font-size.
a = 88
b = 168
c = 211
w = 12
x = ?
y = 50

And here's the formula:


x =   (b-a) (y-w)
    ----------- + w
      (c-a)


Or to put it in one liner (using c-like syntax):


x =  ( ((b-a) * (y-w)) / (c-a) ) + w

Taken from http://blog.16codes.com/2007/12/how-to-create-tag-cloud-with-formula.html