瀏覽代碼

Better tags repartition with TAG_CLOUD_MAX_ITEMS

WhiteWinterWolf 6 年之前
父節點
當前提交
9c38b814b1
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      tag_cloud/tag_cloud.py

+ 4 - 3
tag_cloud/tag_cloud.py

@@ -43,15 +43,16 @@ def generate_tag_cloud(generator):
 
     tags = list(map(itemgetter(1), tag_cloud))
     if tags:
-        max_count = max(tags)
+        max_count = tags[0]
+        min_count = tags[-1]
     steps = generator.settings.get('TAG_CLOUD_STEPS')
 
     # calculate word sizes
     def generate_tag(tag, count):
         tag = (
             tag,
-            int(math.floor(steps - (steps - 1) * math.log(count)
-                / (math.log(max_count)or 1)))
+            int(math.floor(steps - (steps - 1) * math.log(count - min_count + 1)
+                / (math.log(max_count - min_count + 1) or 1)))
         )
         if generator.settings.get('TAG_CLOUD_BADGE'):
             tag += (count,)