lib/gruff/bar.rb
# Spacing factor applied between bars.
Spacing factor applied between bars.
Spacing factor applied between bars .
def draw_graph
     Columns sit side-by-side.
    @bar_spacing ||= @spacing_factor  space between the bars
    bar_width = (@graph_width - calculate_spacing) / (column_count * store.length).to_f
    padding = (bar_width * (1 - @bar_spacing)) / 2
     Setup the BarConversion Object
    conversion = Gruff::BarConversion.new(
      top: @graph_top, bottom: @graph_bottom,
      minimum_value: minimum_value, maximum_value: maximum_value, spread: @spread
    )
     iterate over all normalised data
    store.norm_data.each_with_index do |data_row, row_index|
      data_row.points.each_with_index do |data_point, point_index|
        group_spacing = @group_spacing * @scale * point_index
         Use incremented x and scaled y
         x
        left_x = @graph_left + (bar_width * (row_index + point_index + ((store.length - 1) * point_index))) + padding + group_spacing
        right_x = left_x + bar_width * @bar_spacing
         y
        left_y, right_y = conversion.get_top_bottom_scaled(data_point)
         create new bar
        rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: data_row.color)
        rect_renderer.render(left_x, left_y - AXIS_MARGIN, right_x, right_y - AXIS_MARGIN)
         Calculate center based on bar_width and current row
        label_center = @graph_left + group_spacing + (store.length * bar_width * point_index) + (store.length * bar_width / 2.0)
         Subtract half a bar width to center left if requested
        draw_label(label_center, point_index)
        if @show_labels_for_bar_values
          bar_value_label = Gruff::BarValueLabel::Bar.new([left_x, left_y, right_x, right_y], store.data[row_index].points[point_index])
          bar_value_label.prepare_rendering(@label_formatting, bar_width) do |x, y, text|
            draw_value_label(x, y, text)
          end
        end
      end
    end
     Draw the last label if requested
    draw_label(@graph_right, column_count, Magick::NorthWestGravity) if @center_labels_over_point
  end
def draw_graph @bar_spacing ||= @spacing_factor bar_width = ( @graph_width - calculate_spacing ) / ( column_count * store . length ) . to_f padding = ( bar_width * ( 1 - @bar_spacing ) ) / 2 conversion = Gruff :: BarConversion . new ( top : @graph_top , bottom : @graph_bottom , minimum_value : minimum_value , maximum_value : maximum_value , spread : @spread ) store . norm_data . each_with_index do | data_row , row_index | data_row . points . each_with_index do | data_point , point_index | group_spacing = @group_spacing * @scale * point_index left_x = @graph_left + ( bar_width * ( row_index + point_index + ( ( store . length - 1 ) * point_index ) ) ) + padding + group_spacing right_x = left_x + bar_width * @bar_spacing left_y , right_y = conversion . get_top_bottom_scaled ( data_point ) rect_renderer = Gruff :: Renderer :: Rectangle . new ( renderer , color : data_row . color ) rect_renderer . render ( left_x , left_y - AXIS_MARGIN , right_x , right_y - AXIS_MARGIN ) label_center = @graph_left + group_spacing + ( store . length * bar_width * point_index ) + ( store . length * bar_width / 2.0 ) draw_label ( label_center , point_index ) if @show_labels_for_bar_values bar_value_label = Gruff :: BarValueLabel :: Bar . new ( [ left_x , left_y , right_x , right_y ] , store . data [ row_index ] . points [ point_index ] ) bar_value_label . prepare_rendering ( @label_formatting , bar_width ) do | x , y , text | draw_value_label ( x , y , text ) end end end end draw_label ( @graph_right , column_count , Magick :: NorthWestGravity ) if @center_labels_over_point end
Spacing factor applied between bars.
Spacing factor applied between bars .
# Setup spacing. # # Columns sit side-by-side. # space between the bars # Setup the BarConversion Object # iterate over all normalised data # Use incremented x and scaled y # x # y # create new bar # Calculate center based on bar_width and current row # Subtract half a bar width to center left if requested # Draw the last label if requested