Use minimum of tag count for tag cloud

The tag cloud minimum used to start at 0, then repeatedly compared to
the lowest count and chose the smallest, which is bound to be zero in
every case.

Discussed
[here](8c26ea7cb5 (commitcomment-2719199)).
This commit is contained in:
Katrina Owen 2013-03-01 00:13:41 -05:00
parent 14a47f0480
commit 0f5b402427

View file

@ -569,12 +569,9 @@ class StatsController < ApplicationController
query << " ORDER BY count DESC, name" query << " ORDER BY count DESC, name"
query << " LIMIT 100" query << " LIMIT 100"
@tags_for_cloud = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase } @tags_for_cloud = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase }
tag_counts = @tags_for_cloud.map(&:count)
max, @tags_min = 0, 0 max = tag_counts.max || 0
@tags_for_cloud.each { |t| @tags_min = tag_counts.min || 0
max = [t.count.to_i, max].max
@tags_min = [t.count.to_i, @tags_min].min
}
@tags_divisor = ((max - @tags_min) / levels) + 1 @tags_divisor = ((max - @tags_min) / levels) + 1
@ -594,12 +591,9 @@ class StatsController < ApplicationController
[query, current_user.id, @cut_off_3months, @cut_off_3months] [query, current_user.id, @cut_off_3months, @cut_off_3months]
).sort_by { |tag| tag.name.downcase } ).sort_by { |tag| tag.name.downcase }
max_90days, @tags_min_90days = 0, 0 tag_counts_90days = @tags_for_cloud_90days.map(&:count)
@tags_for_cloud_90days.each { |t| max_90days = tag_counts_90days.max || 0
max_90days = [t.count.to_i, max_90days].max @tags_min_90days = tag_counts_90days.min || 0
@tags_min_90days = [t.count.to_i, @tags_min_90days].min
}
@tags_divisor_90days = ((max_90days - @tags_min_90days) / levels) + 1 @tags_divisor_90days = ((max_90days - @tags_min_90days) / levels) + 1
end end