Datengrundlage
1 2 3 4 5 6 7 8 9 10 |
// Array mit den Tags $tags=array('keyword'=>5,'banane'=>10); // count tags $count = count($tags); // calculate min/max font-size $mincount = min(array_values($tags)); $maxcount = max(array_values($tags)); // define min/max font-size $minsize = 11; $maxsize = 30; |
Linear 1 – normale Geradengleichung
1 2 3 4 5 |
function calcFontSize_Linear1($count, $mincount, $maxcount, $minsize, $maxsize) { $fix = ($maxcount - $mincount == 0) ? 1 : $maxcount - $mincount; $size = $minsize + ($count - $mincount) * ($maxsize - $minsize) / $fix; return $size; } |
Linear 2 – FontsizeDistribution
1 2 3 4 |
function calcFontSize_Linear2($count, $mincount, $maxcount, $minsize, $maxsize) { $size = ( ( ($maxsize - $minsize) * ($count - $mincount) ) / ($maxcount - $mincount) ) + $minsize; return round($size, 0); } |
Logarithmisch
1 2 3 4 5 6 7 8 9 10 |
function calcFontSize_Log( $count, $mincount, $maxcount, $minsize, $maxsize, $tresholds ) { if( empty($tresholds) ) : $tresholds = $maxsize-$minsize; $treshold = 1; else : $treshold = ($maxsize-$minsize)/($tresholds-1); endif; $a = $tresholds*log($count - $mincount+2)/log($maxcount - $mincount+2)-1; return round($minsize+round($a)*$treshold); } |