lib/gruff/base.rb
# Draws horizontal background lines and labels
Draws horizontal background lines and labels
Draws horizontal background lines and labels
def draw_line_markers
      return if @hide_line_markers
      @d = @d.stroke_antialias false
      if @y_axis_increment.nil?
         TODO Do the same for larger numbers...100, 75, 50, 25
        if @marker_count.nil?
          (3..7).each do |lines|
            if @spread % lines == 0.0
              @marker_count = lines
              break
            end
          end
          @marker_count ||= 4
        end
        @increment = (@spread > 0) ? significant(@spread / @marker_count) : 1
      else
         TODO Make this work for negative values
        @maximum_value = [@maximum_value.ceil, @y_axis_increment].max
        @minimum_value = @minimum_value.floor
        calculate_spread
        normalize(true)
        @marker_count = (@spread / @y_axis_increment).to_i
        @increment = @y_axis_increment
      end
      @increment_scaled = @graph_height.to_f / (@spread / @increment)
       Draw horizontal line markers and annotate with numbers
      (0..@marker_count).each do |index|
        y = @graph_top + @graph_height - index.to_f * @increment_scaled
        @d = @d.stroke(@marker_color)
        @d = @d.stroke_width 1
        @d = @d.line(@graph_left, y, @graph_right, y)
        marker_label = index * @increment + @minimum_value.to_f
        unless @hide_line_numbers
          @d.fill = @font_color
          @d.font = @font if @font
          @d.stroke('transparent')
          @d.pointsize = scale_fontsize(@marker_font_size)
          @d.gravity = EastGravity
           Vertically center with 1.0 for the height
          @d = @d.annotate_scaled( @base_image,
          @graph_left - LABEL_MARGIN, 1.0,
          0.0, y,
          label(marker_label), @scale)
        end
      end
        Submitted by a contibutor...the utility escapes me
       i = 0
       @additional_line_values.each do |value|
         @increment_scaled = @graph_height.to_f / (@maximum_value.to_f / value)
         y = @graph_top + @graph_height - @increment_scaled
         @d = @d.stroke(@additional_line_colors[i])
         @d = @d.line(@graph_left, y, @graph_right, y)
         @d.fill = @additional_line_colors[i]
         @d.font = @font if @font
         @d.stroke('transparent')
         @d.pointsize = scale_fontsize(@marker_font_size)
         @d.gravity = EastGravity
         @d = @d.annotate_scaled( @base_image,
                           100, 20,
                           -10, y - (@marker_font_size/2.0),
                           "", @scale)
         i += 1
       end
      @d = @d.stroke_antialias true
    end
def draw_line_markers return if @hide_line_markers @d = @d . stroke_antialias false if @y_axis_increment . nil? if @marker_count . nil? ( 3 .. 7 ) . each do | lines | if @spread % lines == 0.0 @marker_count = lines break end end @marker_count ||= 4 end @increment = ( @spread > 0 ) ? significant ( @spread / @marker_count ) : 1 else @maximum_value = [ @maximum_value . ceil , @y_axis_increment ] . max @minimum_value = @minimum_value . floor calculate_spread normalize ( true ) @marker_count = ( @spread / @y_axis_increment ) . to_i @increment = @y_axis_increment end @increment_scaled = @graph_height . to_f / ( @spread / @increment ) ( 0 .. @marker_count ) . each do | index | y = @graph_top + @graph_height - index . to_f * @increment_scaled @d = @d . stroke ( @marker_color ) @d = @d . stroke_width 1 @d = @d . line ( @graph_left , y , @graph_right , y ) marker_label = index * @increment + @minimum_value . to_f unless @hide_line_numbers @d . fill = @font_color @d . font = @font if @font @d . stroke ( 'transparent' ) @d . pointsize = scale_fontsize ( @marker_font_size ) @d . gravity = EastGravity @d = @d . annotate_scaled ( @base_image , @graph_left - LABEL_MARGIN , 1.0 , 0.0 , y , label ( marker_label ) , @scale ) end end @d = @d . stroke_antialias true end
Draws horizontal background lines and labels
Draws horizontal background lines and labels
# Try to use a number of horizontal lines that will come out even. # # TODO Do the same for larger numbers...100, 75, 50, 25 # TODO Make this work for negative values # Draw horizontal line markers and annotate with numbers # Vertically center with 1.0 for the height # # Submitted by a contibutor...the utility escapes me # i = 0 # @additional_line_values.each do |value| #   @increment_scaled = @graph_height.to_f / (@maximum_value.to_f / value) # #   y = @graph_top + @graph_height - @increment_scaled # #   @d = @d.stroke(@additional_line_colors[i]) #   @d = @d.line(@graph_left, y, @graph_right, y) # # #   @d.fill = @additional_line_colors[i] #   @d.font = @font if @font #   @d.stroke('transparent') #   @d.pointsize = scale_fontsize(@marker_font_size) #   @d.gravity = EastGravity #   @d = @d.annotate_scaled( @base_image, #                     100, 20, #                     -10, y - (@marker_font_size/2.0), #                     "", @scale) #   i += 1 # end