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
# 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: @bar_spacing ||= 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: padding = (@bar_width * (1 - @bar_spacing)) / 2 31: 32: @norm_data.each_with_index do |data_row, row_index| 33: @d = @d.fill data_row[DATA_COLOR_INDEX] 34: 35: data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index| 36: 37: ## using the original calcs from the stacked bar chart to get the difference between 38: ## part of the bart chart we wish to stack. 39: temp1 = @graph_left + (@graph_width - 40: data_point * @graph_width - 41: height[point_index]) + 1 42: temp2 = @graph_left + @graph_width - height[point_index] - 1 43: difference = temp2 - temp1 44: 45: left_x = length[point_index] #+ 1 46: left_y = @graph_top + (@bar_width * point_index) + padding 47: right_x = left_x + difference 48: right_y = left_y + @bar_width * @bar_spacing 49: length[point_index] += difference 50: height[point_index] += (data_point * @graph_width - 2) 51: 52: @d = @d.rectangle(left_x, left_y, right_x, right_y) 53: 54: # Calculate center based on bar_width and current row 55: label_center = @graph_top + (@bar_width * point_index) + (@bar_width * @bar_spacing / 2.0) 56: draw_label(label_center, point_index) 57: end 58: 59: end 60: 61: @d.draw(@base_image) 62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.