Browse files

Apply bar_spacing correctly to SideBar graphs.

  • Loading branch information...
1 parent 683592e commit 0fc48ac4928a6c562ce47f9588887686d83dad6f @jcoglan jcoglan committed Aug 15, 2010
Showing with 14 additions and 11 deletions.
  1. +8 −5 lib/gruff/side_bar.rb
  2. +6 −6 lib/gruff/side_stacked_bar.rb
View
13 lib/gruff/side_bar.rb
@@ -13,17 +13,22 @@ def draw
super
return unless @has_data
+ draw_bars
+ end
+
+protected
+ def draw_bars
# Setup spacing.
#
@bar_spacing ||= 0.9
@bars_width = @graph_height / @column_count.to_f
- @bar_width = @bars_width * @bar_spacing / @norm_data.size
+ @bar_width = @bars_width / @norm_data.size
@d = @d.stroke_opacity 0.0
height = Array.new(@column_count, 0)
length = Array.new(@column_count, @graph_left)
- padding = (@bars_width * (1 - @bar_spacing)) / 2
+ padding = (@bar_width * (1 - @bar_spacing)) / 2
@norm_data.each_with_index do |data_row, row_index|
@d = @d.fill data_row[DATA_COLOR_INDEX]
@@ -40,7 +45,7 @@ def draw
left_x = length[point_index] - 1
left_y = @graph_top + (@bars_width * point_index) + (@bar_width * row_index) + padding
right_x = left_x + difference
- right_y = left_y + @bar_width
+ right_y = left_y + @bar_width * @bar_spacing
height[point_index] += (data_point * @graph_width)
@@ -56,8 +61,6 @@ def draw
@d.draw(@base_image)
end
-protected
-
# Instead of base class version, draws vertical background lines and label
def draw_line_markers
View
12 lib/gruff/side_stacked_bar.rb
@@ -18,9 +18,11 @@ def draw
@has_left_labels = true
get_maximum_by_stack
super
+ end
- return unless @has_data
+ protected
+ def draw_bars
# Setup spacing.
#
# Columns sit stacked.
@@ -33,8 +35,6 @@ def draw
padding = (@bar_width * (1 - @bar_spacing)) / 2
@norm_data.each_with_index do |data_row, row_index|
- @d = @d.fill data_row[DATA_COLOR_INDEX]
-
data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
## using the original calcs from the stacked bar chart to get the difference between
@@ -45,7 +45,9 @@ def draw
temp2 = @graph_left + @graph_width - height[point_index] - 1
difference = temp2 - temp1
- left_x = length[point_index] #+ 1
+ @d = @d.fill data_row[DATA_COLOR_INDEX]
+
+ left_x = length[point_index] #+ 1
left_y = @graph_top + (@bar_width * point_index) + padding
right_x = left_x + difference
right_y = left_y + @bar_width * @bar_spacing
@@ -64,8 +66,6 @@ def draw
@d.draw(@base_image)
end
- protected
-
def larger_than_max?(data_point, index=0)
max(data_point, index) > @maximum_value
end

0 comments on commit 0fc48ac

Please sign in to comment.