Permalink
Browse files

Use the data range correctly when rendering SideBar x-axis labels.

  • Loading branch information...
1 parent 6eca1cd commit 683592e51bf6d7963750d955856340072e1eb75e @jcoglan jcoglan committed Aug 15, 2010
Showing with 18 additions and 2 deletions.
  1. +2 −2 lib/gruff/side_bar.rb
  2. +2 −0 test/gruff_test_case.rb
  3. +14 −0 test/test_side_bar.rb
View
@@ -71,14 +71,14 @@ def draw_line_markers
number_of_lines = 5
# TODO Round maximum marker value to a round number like 100, 0.1, 0.5, etc.
- increment = significant(@maximum_value.to_f / number_of_lines)
+ increment = significant(@spread.to_f / number_of_lines)
(0..number_of_lines).each do |index|
line_diff = (@graph_right - @graph_left) / number_of_lines
x = @graph_right - (line_diff * index) - 1
@d = @d.line(x, @graph_bottom, x, @graph_top)
diff = index - number_of_lines
- marker_label = diff.abs * increment
+ marker_label = diff.abs * increment + @minimum_value
unless @hide_line_numbers
@d.fill = @font_color
View
@@ -1,6 +1,8 @@
$:.unshift(File.dirname(__FILE__) + "/../lib/")
# require 'rubygems'
+RMAGICK_BYPASS_VERSION_TEST = true
+
require 'test/unit'
require 'gruff'
require 'fileutils'
View
@@ -24,6 +24,20 @@ def test_bar_spacing
g.title = "0% spacing between bars"
g.write("test/output/side_bar_spacing_none.png")
end
+
+ def test_x_axis_range
+ g = Gruff::SideBar.new('400x300')
+ g.title = 'Should run from 8 to 32'
+ g.hide_line_numbers = false
+ g.theme_37signals
+ g.data("Grapes", [8])
+ g.data("Apples", [24])
+ g.data("Oranges", [32])
+ g.data("Watermelon", [8])
+ g.data("Peaches", [12])
+ g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
+ g.write("test/output/side_bar_data_range.png")
+ end
end

0 comments on commit 683592e

Please sign in to comment.