X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tags.php;h=3b06df663b898a4a723dca1d4f69497edce83478;hb=373aba15e4a5e4f89a3726f0c49c74127af37313;hp=4a3019ad1d30ccf2b0e93cc6079333e12ec5b720;hpb=77c283456020d1fda4bd127badfac238491edf78;p=contagged
diff --git a/tags.php b/tags.php
index 4a3019a..3b06df6 100644
--- a/tags.php
+++ b/tags.php
@@ -1,5 +1,5 @@
-
- require_once('init.php');
+ $max) $max = $tags[$marker];
+ if($tags[$marker] < $min) $min = $tags[$marker];
}
}
}
ksort($tags);
+ tag_cloud_weight(&$tags,$min,$max,6);
$out = '';
foreach($tags as $tag => $cnt){
- $pct = round($cnt * 20 / $max); // percents from 0 to 20
-
- $out .= '';
+ $out .= '';
$out .= htmlspecialchars($tag).' ';
}
return $out;
}
-?>
+ /**
+ * Calculate weights for a nicer tagcloud distribution
+ */
+ function tag_cloud_weight(&$tags,$min,$max,$levels){
+ // calculate tresholds
+ $tresholds = array();
+ for($i=0; $i<=$levels; $i++){
+ $tresholds[$i] = pow($max - $min + 1, $i/$levels);
+ }
+
+ // assign weights
+ foreach($tags as $tag => $cnt){
+ foreach($tresholds as $tresh => $val){
+ if($cnt <= $val){
+ $tags[$tag] = $tresh;
+ break;
+ }
+ $tags[$tag] = $levels;
+ }
+ }
+ }
+
+