what are some good tag Cloud logic that you had come up with? like fontsize = factor * percentageOfOccurance ....
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.
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.
Could write the second part to you tag cloud implementation min and max and spread Im a bit confused.
I've made tag cloud calculating like this:
$v - incoming value,
$minV - minimal value from dataset,
$maxV - maximal value from dataset,
$minFS - minimum font size,
$maxFS - maximum font size,
function roundFontSize($v, $minV, $maxV, $minFS, $maxFS) {
return $minFS + floor($v / (($maxV - $minV) / ($maxFS - $minFS)));
}
This allow you to round font sizes depending of your need.
Font size will never exceed font size range of $minFSad $maxFS.
来源:https://stackoverflow.com/questions/2378576/best-practice-with-tagclouds-or-tagcloud-logic