lib/gruff/mini/legend.rb
##
# Draw the legend beneath the existing graph.
Draw the legend beneath the existing graph.
Draw the legend beneath the existing graph .
def draw_vertical_legend
        return if @hide_mini_legend
        legend_square_width = 40.0 
        @legend_left_margin = 100.0
        legend_top_margin = 40.0
        case @legend_position
        when :right
          current_x_offset = @original_columns + @left_margin
          current_y_offset = @top_margin + legend_top_margin
        else
          current_x_offset = @legend_left_margin
          current_y_offset = @original_rows + legend_top_margin
        end
        @legend_labels.each_with_index do |legend_label, index|
          label = truncate_legend_label(legend_label)
          text_renderer = Gruff::Renderer::Text.new(renderer, label, font: @legend_font)
          x_offset = current_x_offset + (legend_square_width * 1.7)
          text_renderer.add_to_render_queue(@raw_columns, 1.0, x_offset, current_y_offset, Magick::WestGravity)
          rect_renderer = Gruff::Renderer::Rectangle.new(renderer, color: store.data[index].color)
          rect_renderer.render(current_x_offset,
                               current_y_offset - legend_square_width / 2.0,
                               current_x_offset + legend_square_width,
                               current_y_offset + legend_square_width / 2.0)
          current_y_offset += calculate_line_height
        end
      end
def draw_vertical_legend return if @hide_mini_legend legend_square_width = 40.0 @legend_left_margin = 100.0 legend_top_margin = 40.0 case @legend_position when :right current_x_offset = @original_columns + @left_margin current_y_offset = @top_margin + legend_top_margin else current_x_offset = @legend_left_margin current_y_offset = @original_rows + legend_top_margin end @legend_labels . each_with_index do | legend_label , index | label = truncate_legend_label ( legend_label ) text_renderer = Gruff :: Renderer :: Text . new ( renderer , label , font : @legend_font ) x_offset = current_x_offset + ( legend_square_width * 1.7 ) text_renderer . add_to_render_queue ( @raw_columns , 1.0 , x_offset , current_y_offset , Magick :: WestGravity ) rect_renderer = Gruff :: Renderer :: Rectangle . new ( renderer , color : store . data [ index ] . color ) rect_renderer . render ( current_x_offset , current_y_offset - legend_square_width / 2.0 , current_x_offset + legend_square_width , current_y_offset + legend_square_width / 2.0 ) current_y_offset += calculate_line_height end end
Draw the legend beneath the existing graph.
Draw the legend beneath the existing graph .
# small square with color of this item # Draw label # Now draw box with color of this dataset