Permalink
Browse files

Added side bar labels

  • Loading branch information...
BRIMIL01 committed Mar 8, 2011
1 parent ab8359d commit 4160d665b254434425fde17d1db86e08c69b3d1b
Showing with 19 additions and 0 deletions.
  1. +4 −0 lib/gruff/side_bar.rb
  2. +1 −0 test/gruff_test_case.rb
  3. +14 −0 test/test_side_bar.rb
View
@@ -59,6 +59,10 @@ def draw_bars
# Calculate center based on bar_width and current row
label_center = @graph_top + (@bars_width * point_index + @bars_width / 2)
draw_label(label_center, point_index)
+ if @show_labels_for_bar_values
+ val = (@label_formatting || "%.2f") % @norm_data[row_index][3][point_index]
+ draw_value_label(right_x+40, (@graph_top + (((row_index+point_index+1) * @bar_width) - (@bar_width / 2)))-12, val.commify, true)
+ end
end
end
View
@@ -124,6 +124,7 @@ def setup_basic_graph(*args)
g = klass.new(size)
g.title = "My Bar Graph"
g.labels = @labels
+ g.font = "/Library/Fonts/Verdana.ttf"
@datasets.each do |data|
View
@@ -38,6 +38,20 @@ def test_x_axis_range
g.labels = {0 => '2003', 2 => '2004', 4 => '2005'}
g.write("test/output/side_bar_data_range.png")
end
+
+ def test_bar_labels
+ g = Gruff::SideBar.new('400x300')
+ g.title = 'Should show labels for each bar'
+ g.font = "/Library/Fonts/Verdana.ttf"
+ 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.show_labels_for_bar_values = true
+ g.write("test/output/side_bar_labels.png")
+ end
end

0 comments on commit 4160d66

Please sign in to comment.