require 'gruff/base' class Gruff::Bar < Gruff::Base def draw super # Setup spacing. # # Columns sit side-by-side. spacing_factor = 0.9 @bar_width = @graph_width / (@column_count * @data.length).to_f @d = @d.stroke_opacity 0.0 @norm_data.each_with_index do |data_row, row_index| @d = @d.fill current_color data_row[1].each_with_index do |data_point, point_index| # Use incremented x and scaled y left_x = @graph_left + (@bar_width * (row_index + point_index + ((@data.length - 1) * point_index))) left_y = @graph_top + (@graph_height - data_point * @graph_height) + 1 right_x = left_x + @bar_width * spacing_factor right_y = @graph_top + @graph_height - 1 @d = @d.rectangle(left_x, left_y, right_x, right_y) # Calculate center based on bar_width and current row label_center = @graph_left + (@data.length * @bar_width * point_index) + (@data.length * @bar_width / 2.0) draw_label(label_center, point_index) end increment_color() end @d.draw(@base_image) end end