best practice with tagclouds or tagCloud logic? [closed]

僤鯓⒐⒋嵵緔 提交于 2020-01-01 12:08:10

问题


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


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!