From 0f5b4024275bbd9d70f16b724a7f8f9d5298825c Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Fri, 1 Mar 2013 00:13:41 -0500 Subject: [PATCH] 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](https://github.com/TracksApp/tracks/commit/8c26ea7cb596c97e37213c0cc994e66ee5fd27b0#commitcomment-2719199). --- app/controllers/stats_controller.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 2bd20d4a..d5d70478 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -569,12 +569,9 @@ class StatsController < ApplicationController query << " ORDER BY count DESC, name" query << " LIMIT 100" @tags_for_cloud = Tag.find_by_sql(query).sort_by { |tag| tag.name.downcase } - - max, @tags_min = 0, 0 - @tags_for_cloud.each { |t| - max = [t.count.to_i, max].max - @tags_min = [t.count.to_i, @tags_min].min - } + tag_counts = @tags_for_cloud.map(&:count) + max = tag_counts.max || 0 + @tags_min = tag_counts.min || 0 @tags_divisor = ((max - @tags_min) / levels) + 1 @@ -594,12 +591,9 @@ class StatsController < ApplicationController [query, current_user.id, @cut_off_3months, @cut_off_3months] ).sort_by { |tag| tag.name.downcase } - max_90days, @tags_min_90days = 0, 0 - @tags_for_cloud_90days.each { |t| - max_90days = [t.count.to_i, max_90days].max - @tags_min_90days = [t.count.to_i, @tags_min_90days].min - } - + tag_counts_90days = @tags_for_cloud_90days.map(&:count) + max_90days = tag_counts_90days.max || 0 + @tags_min_90days = tag_counts_90days.min || 0 @tags_divisor_90days = ((max_90days - @tags_min_90days) / levels) + 1 end