views:

187

answers:

3

what are some good tag Cloud logic that you had come up with? like fontsize = factor * percentageOfOccurance ....

+3  A: 

You'll need to set a minimum size, so maybe fontsize = minsize + factor * percentage.

You may want to limit the range of sizes; perhaps take the sqrt or log of percentage, but this depends on your distribution.

For another technique, have a look at this blog post from poeticcode on Tag Clouds Algorithms:

Next, in the linear interpolation, how do we set the min and max boundaries for the font size/color intensity? I notice that Amazon.com for example, is ranging it’s font sizes between 80% and 280%. So, the lowest tag in the cloud would get a font size of 80% and the highest tag 280%. I have decided to go with the following formula

150*(1.0+(1.5*m-maxm/2)/maxm)

This nicely gives a font size from 75% to 300% as the metric changes from a potential 0 to maxm.

Skilldrick
A: 

I'd check the occurance for every element and keep track of the "maximum" (the element with the highest count as this will be your measure).

Next calculate the percentage of occurance for each element, compared to the element with the maximum (which is 100%). For instance:

foreach ($elements as $element) {
    $percentage = floor(($element['count'] / $maximum) * 100);
}  

Next create CSS styles for 20 / 40 / 60 / 80 / 100 percentage values and apply the correct CSS style according to the percentage.

Or you could as you suggested calculate the font size.

First get your max. and min and calculate the spread. ($max - $min). Your font-size increment would be the "step" - which is basically ($max - $min) / $spread.

Now you can calculate your font-sizes accordingly:

$min_size + ($element['occurrence'] - $smallest_array_value) * $step  

Don't forget to round of your result.

Tom
A: 

Could write the second part to you tag cloud implementation min and max and spread Im a bit confused.

littleMan