Sha256: 62bd58489a4c48a777a59e5086d1e3498af26f61b7fc132d4611e2f6b1af2a10

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'gruff/base'

module Gruff
  class Line < Base

    def draw
      super

      @x_increment = @graph_width / (@column_count - 1).to_f
      circle_radius = 5.0
    
      @d = @d.stroke_opacity 1.0
      @d = @d.stroke_width 5.0
    
      @norm_data.each do |data_row|
        prev_x = prev_y = 0.0
        @d = @d.stroke current_color
        @d = @d.fill current_color
      
        data_row[1].each_with_index do |data_point, index|
          # Use incremented x and scaled y
          new_x = @graph_left + (@x_increment * index)
          new_y = @graph_top + (@graph_height - data_point * @graph_height)
                
          @d = @d.line(prev_x, prev_y, new_x, new_y) if (prev_x > 0) && (prev_y > 0)
          @d = @d.circle(new_x, new_y, new_x - circle_radius, new_y)

          draw_label(new_x, index)

          prev_x = new_x
          prev_y = new_y
        end
        
        increment_color()
      end
    
      @d.draw(@base_image)    
    end

private

    # Draws column labels below graph
    def draw_label(x_offset, index)
      if !@labels[index].nil? && @labels_seen[index].nil?
        @d.fill = @marker_color
        @d.font = @font
        @d.stroke = 'transparent'
        @d.font_weight = NormalWeight
        @d.pointsize = scale_fontsize(@marker_pointsize)
        @d.gravity = CenterGravity
        @d = @d.annotate_scaled(@base_image,
                                1, 1,
                                #150, 30,
                                x_offset, @raw_rows - 80,
                                @labels[index], @scale)
        @labels_seen[index] = 1
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gruff-0.0.1 lib/gruff/line.rb
gruff-0.0.2 lib/gruff/line.rb