lib/gruff/scatter.rb
# Maximum X Value. The value will get overwritten by the max in the
# datasets.
Maximum X Value. The value will get overwritten by the max in the
datasets.
Maximum X Value . The value will get overwritten by the max in the datasets .
def draw_line_markers
    super
    return if @hide_line_markers
    if @x_axis_increment.nil?
      if @marker_x_count.nil?
        (3..7).each do |lines|
          if @x_spread % lines == 0.0
            @marker_x_count = lines
            break
          end
        end
        @marker_x_count ||= 4
      end
      @x_increment = (@x_spread > 0) ? (@x_spread / @marker_x_count) : 1
      unless @disable_significant_rounding_x_axis
        @x_increment = significant(@x_increment)
      end
    else
      @maximum_x_value = [@maximum_x_value.ceil, @x_axis_increment].max
      @minimum_x_value = @minimum_x_value.floor
      calculate_spread
      normalize
      @marker_x_count = (@x_spread / @x_axis_increment).to_i
      @x_increment = @x_axis_increment
    end
    increment_x_scaled = @graph_width.to_f / (@x_spread / @x_increment)
    (0..@marker_x_count).each do |index|
      if @show_vertical_markers
        x = @graph_left + @graph_width - index.to_f * increment_x_scaled
        line_renderer = Gruff::Renderer::Line.new(renderer, color: @marker_color, shadow_color: @marker_shadow_color)
        line_renderer.render(x, @graph_top, x, @graph_bottom)
      end
      unless @hide_line_numbers
        marker_label = BigDecimal(index.to_s) * BigDecimal(@x_increment.to_s) + BigDecimal(@minimum_x_value.to_s)
        y_offset = @graph_bottom + (@x_label_margin || LABEL_MARGIN)
        x_offset = get_x_coord(index.to_f, increment_x_scaled, @graph_left)
        label = x_axis_label(marker_label, @x_increment)
        rotation = -90.0 if @use_vertical_x_labels
        text_renderer = Gruff::Renderer::Text.new(renderer, label, font: @marker_font, rotation: rotation)
        text_renderer.add_to_render_queue(1.0, 1.0, x_offset, y_offset)
      end
    end
  end
def draw_line_markers super return if @hide_line_markers if @x_axis_increment . nil? if @marker_x_count . nil? ( 3 .. 7 ) . each do | lines | if @x_spread % lines == 0.0 @marker_x_count = lines break end end @marker_x_count ||= 4 end @x_increment = ( @x_spread > 0 ) ? ( @x_spread / @marker_x_count ) : 1 unless @disable_significant_rounding_x_axis @x_increment = significant ( @x_increment ) end else @maximum_x_value = [ @maximum_x_value . ceil , @x_axis_increment ] . max @minimum_x_value = @minimum_x_value . floor calculate_spread normalize @marker_x_count = ( @x_spread / @x_axis_increment ) . to_i @x_increment = @x_axis_increment end increment_x_scaled = @graph_width . to_f / ( @x_spread / @x_increment ) ( 0 .. @marker_x_count ) . each do | index | if @show_vertical_markers x = @graph_left + @graph_width - index . to_f * increment_x_scaled line_renderer = Gruff :: Renderer :: Line . new ( renderer , color : @marker_color , shadow_color : @marker_shadow_color ) line_renderer . render ( x , @graph_top , x , @graph_bottom ) end unless @hide_line_numbers marker_label = BigDecimal ( index . to_s ) * BigDecimal ( @x_increment . to_s ) + BigDecimal ( @minimum_x_value . to_s ) y_offset = @graph_bottom + ( @x_label_margin || LABEL_MARGIN ) x_offset = get_x_coord ( index . to_f , increment_x_scaled , @graph_left ) label = x_axis_label ( marker_label , @x_increment ) rotation = - 90.0 if @use_vertical_x_labels text_renderer = Gruff :: Renderer :: Text . new ( renderer , label , font : @marker_font , rotation : rotation ) text_renderer . add_to_render_queue ( 1.0 , 1.0 , x_offset , y_offset ) end end end
Maximum X Value.
Maximum X Value .
# do all of the stuff for the horizontal lines on the y-axis # TODO: Do the same for larger numbers...100, 75, 50, 25 # TODO: Make this work for negative values # Draw vertical line markers and annotate with numbers # TODO: Fix the vertical lines, and enable them by default. Not pretty when they don't match up with top y-axis line