lib/gruff/side_bar.rb
# Spacing factor applied between bars.
Spacing factor applied between bars.
Spacing factor applied between bars .
def draw_graph
    bars_width = (@graph_height - calculate_spacing) / column_count.to_f
    bar_width = bars_width / store.length
    padding = (bar_width * (1 - @bar_spacing)) / 2
     Setup the BarConversion Object
    conversion = Gruff::BarConversion.new(
      top: @graph_right, bottom: @graph_left,
      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_y = @graph_top + (bars_width * point_index) + (bar_width * row_index) + padding + group_spacing
        right_y = left_y + bar_width * @bar_spacing
        left_x, right_x = conversion.get_top_bottom_scaled(data_point).sort
        rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: data_row.color)
        rect_renderer.render(left_x + AXIS_MARGIN, left_y, right_x + AXIS_MARGIN, right_y)
         Calculate center based on bar_width and current row
        label_center = left_y + bars_width / 2
         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::SideBar.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
  end
def draw_graph bars_width = ( @graph_height - calculate_spacing ) / column_count . to_f bar_width = bars_width / store . length padding = ( bar_width * ( 1 - @bar_spacing ) ) / 2 conversion = Gruff :: BarConversion . new ( top : @graph_right , bottom : @graph_left , 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_y = @graph_top + ( bars_width * point_index ) + ( bar_width * row_index ) + padding + group_spacing right_y = left_y + bar_width * @bar_spacing left_x , right_x = conversion . get_top_bottom_scaled ( data_point ) . sort rect_renderer = Gruff :: Renderer :: Rectangle . new ( renderer , color : data_row . color ) rect_renderer . render ( left_x + AXIS_MARGIN , left_y , right_x + AXIS_MARGIN , right_y ) label_center = left_y + bars_width / 2 draw_label ( label_center , point_index ) if @show_labels_for_bar_values bar_value_label = Gruff :: BarValueLabel :: SideBar . 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 end
Spacing factor applied between bars.
Spacing factor applied between bars .
# Setup spacing. # # Setup the BarConversion Object # Calculate center based on bar_width and current row # Subtract half a bar width to center left if requested