Permalink
Browse files

A little bit of cleanup in the chart helper

  • Loading branch information...
1 parent b82c63a commit 26d4db78e3b83e0f4fd1a6d6657f5f25ae7be6e9 @qrush qrush committed Oct 9, 2010
Showing with 14 additions and 11 deletions.
  1. +14 −11 app/helpers/chart_helper.rb
@@ -3,10 +3,10 @@ def most_downloaded_chart(rubygems)
chart = GoogleChart::BarChart.new('530x360', "Most Downloads", :horizontal, false) do |bc|
downloads = rubygems.map(&:downloads)
- bc.axis :y, :labels => rubygems.map { |rubygem| "#{rubygem.name} (#{rubygem.downloads})" }.reverse,
+ bc.axis :y, :labels => rubygems.map(&:with_downloads).reverse,
:font_size => 16,
:alignment => :center
- bc.axis :x, :range => [0,downloads.max],
+ bc.axis :x, :range => [0, downloads.max],
:font_size => 16,
:alignment => :center
bc.data "downloads", downloads, '8B0000'
@@ -16,16 +16,16 @@ def most_downloaded_chart(rubygems)
end
def downloads_over_time_chart(versions, days_ago = 90)
- rubygem = versions.first.rubygem
+ rubygem = versions.first.rubygem
download_counts = Download.counts_by_day_for_versions(versions, days_ago)
range = [nil, 0]
- chart = GoogleChart::LineChart.new('630x250', "Downloads Over the last #{pluralize(days_ago, 'day')}") do |lc|
+ chart = GoogleChart::LineChart.new('630x250', "Downloads over the last #{pluralize(days_ago, 'day')}") do |lc|
versions.each_with_index do |version, idx|
counts = []
days_ago.times do |t|
- date = t.days.ago.to_date
- count = download_counts["#{version.id}-#{date}"] || 0
+ date = t.days.ago.to_date
+ count = download_counts["#{version.id}-#{date}"] || 0
range[0] = count if !range[0] || (count < range[0])
range[1] = count if count > range[1]
counts << count
@@ -36,17 +36,20 @@ def downloads_over_time_chart(versions, days_ago = 90)
lc.axis :y, :range => range
lc.axis :x, :labels => [60, 40, 20, 0].map { |t| t.days.ago.to_date }
- lc.grid :x_step => 100.0/12.0, :y_step => 100.0/15.0, :length_segment => 1, :length_blank => 5
+ lc.grid :x_step => 100.0 / 12.0,
+ :y_step => 100.0 / 15.0,
+ :length_segment => 1,
+ :length_blank => 5
end
image_tag(chart.to_url(:chf => 'bg,s,FFFFFF00'), :alt => 'title')
end
def color_from_cycle(idx, length)
- hex = "0123456789ABCDEF"
+ hex = "0123456789ABCDEF"
center = 128
- width = 55 #127
- freq = Math::PI*2/length
- phase = {:r => 0, :g => 1, :b => 3}
+ width = 55 #127
+ freq = Math::PI * 2 / length
+ phase = {:r => 0, :g => 1, :b => 3}
[ Math.sin(freq*idx+phase[:r]) * width + center,
Math.sin(freq*idx+phase[:g]) * width + center,

0 comments on commit 26d4db7

Please sign in to comment.