Class Gruff::SideStackedBar
In: lib/gruff/side_stacked_bar.rb
Parent: Gruff::SideBar
StackedMixin StackedBar SideStackedBar StackedArea AccumulatorBar Base Scene Pie Area PhotoBar Bullet Spider SideBar Net Bar Line Pie Observable Group SideBar StandardError IncorrectNumberOfDatasetsException Magick Bar Layer BarConversion lib/gruff/stacked_area.rb lib/gruff/scene.rb lib/gruff/spider.rb lib/gruff/pie.rb lib/gruff/bullet.rb lib/gruff/area.rb lib/gruff/net.rb lib/gruff/bar_conversion.rb lib/gruff/bar.rb lib/gruff/side_bar.rb lib/gruff/line.rb lib/gruff/stacked_bar.rb lib/gruff/side_stacked_bar.rb lib/gruff/photo_bar.rb lib/gruff/base.rb lib/gruff/accumulator_bar.rb lib/gruff/mini/bar.rb lib/gruff/mini/side_bar.rb lib/gruff/mini/pie.rb Legend Mini Deprecated Gruff dot/m_11_0.png

New gruff graph type added to enable sideways stacking bar charts (basically looks like a x/y flip of a standard stacking bar chart)

alun.eyre@googlemail.com

Methods

draw   larger_than_max?   max  

Included Modules

StackedMixin

Public Instance methods

[Source]

    # File lib/gruff/side_stacked_bar.rb, line 14
14:   def draw
15:     @has_left_labels = true
16:     get_maximum_by_stack
17:     super
18: 
19:     return unless @has_data
20: 
21:     # Setup spacing.
22:     #
23:     # Columns sit stacked.
24:     spacing_factor = 0.9
25: 
26:     @bar_width = @graph_height / @column_count.to_f
27:     @d = @d.stroke_opacity 0.0
28:     height = Array.new(@column_count, 0)
29:     length = Array.new(@column_count, @graph_left)
30: 
31:     @norm_data.each_with_index do |data_row, row_index|
32:       @d = @d.fill data_row[DATA_COLOR_INDEX]
33: 
34:       data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
35: 
36:           ## using the original calcs from the stacked bar chart to get the difference between
37:           ## part of the bart chart we wish to stack.
38:           temp1 = @graph_left + (@graph_width -
39:                                     data_point * @graph_width - 
40:                                     height[point_index]) + 1
41:           temp2 = @graph_left + @graph_width - height[point_index] - 1
42:           difference = temp2 - temp1
43: 
44:           left_x = length[point_index] #+ 1
45:               left_y = @graph_top + (@bar_width * point_index)
46:           right_x = left_x + difference
47:               right_y = left_y + @bar_width * spacing_factor
48:           length[point_index] += difference
49:         height[point_index] += (data_point * @graph_width - 2)
50: 
51:         @d = @d.rectangle(left_x, left_y, right_x, right_y)
52: 
53:         # Calculate center based on bar_width and current row
54:         label_center = @graph_top + (@bar_width * point_index) + (@bar_width * spacing_factor / 2.0)
55:         draw_label(label_center, point_index)
56:       end
57: 
58:     end
59: 
60:     @d.draw(@base_image)    
61:   end

Protected Instance methods

[Source]

    # File lib/gruff/side_stacked_bar.rb, line 65
65:   def larger_than_max?(data_point, index=0)
66:     max(data_point, index) > @maximum_value
67:   end

[Source]

    # File lib/gruff/side_stacked_bar.rb, line 69
69:   def max(data_point, index)
70:     @data.inject(0) {|sum, item| sum + item[DATA_VALUES_INDEX][index]}
71:   end

[Validate]