Sha256: 28c391a296a050d1c84c49702a7b743845a505e61185784cf406a27344a95b37

Contents?: true

Size: 1.75 KB

Versions: 28

Compression:

Stored size: 1.75 KB

Contents

require File.dirname(__FILE__) + '/base'
require File.dirname(__FILE__) + '/stacked_mixin'

class Gruff::StackedArea < Gruff::Base
  include StackedMixin
  attr_accessor :last_series_goes_on_bottom
  
  def draw
    get_maximum_by_stack
    super

    return unless @has_data

    @x_increment = @graph_width / (@column_count - 1).to_f
    @d = @d.stroke 'transparent'

    height = Array.new(@column_count, 0)

    data_points = nil
    iterator = last_series_goes_on_bottom ? :reverse_each : :each
    @norm_data.send(iterator) do |data_row|
      prev_data_points = data_points
      data_points = Array.new
        
      @d = @d.fill data_row[DATA_COLOR_INDEX]

      data_row[DATA_VALUES_INDEX].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 - height[index])

        height[index] += (data_point * @graph_height)
        
        data_points << new_x
        data_points << new_y
          
        draw_label(new_x, index)

      end

      if prev_data_points
        poly_points = data_points.dup
        (prev_data_points.length/2 - 1).downto(0) do |i|
          poly_points << prev_data_points[2*i] 
          poly_points << prev_data_points[2*i+1]
        end
        poly_points << data_points[0] 
        poly_points << data_points[1] 
      else
        poly_points = data_points.dup
        poly_points << @graph_right
        poly_points << @graph_bottom - 1
        poly_points << @graph_left
        poly_points << @graph_bottom - 1
        poly_points << data_points[0] 
        poly_points << data_points[1] 
      end
      @d = @d.polyline(*poly_points)

    end

    @d.draw(@base_image)
  end
   
 
end

Version data entries

28 entries across 28 versions & 11 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/gruff-0.7.0/lib/gruff/stacked_area.rb
gruff-0.7.0-java lib/gruff/stacked_area.rb
gruff-0.7.0 lib/gruff/stacked_area.rb
gruff-0.6.0-java lib/gruff/stacked_area.rb
gruff-0.6.0 lib/gruff/stacked_area.rb
jslade-gruff-0.3.5 lib/gruff/stacked_area.rb
schapht-gruff-0.3.5 lib/gruff/stacked_area.rb
topfunky-gruff-0.3.3 lib/gruff/stacked_area.rb
topfunky-gruff-0.3.5 lib/gruff/stacked_area.rb
umang-gruff-0.3.6 lib/gruff/stacked_area.rb
woodhull-gruff-0.3.5 lib/gruff/stacked_area.rb
gruff-0.5.1-java lib/gruff/stacked_area.rb
gruff-0.5.1 lib/gruff/stacked_area.rb
gruff-0.5.0-java lib/gruff/stacked_area.rb
gruff-0.5.0 lib/gruff/stacked_area.rb
gruff-0.4.0 lib/gruff/stacked_area.rb
gruff-0.4.0-java lib/gruff/stacked_area.rb
gruff-0.3.7 lib/gruff/stacked_area.rb
fhs-gruff-0.3.6.2 lib/gruff/stacked_area.rb
pfsc_gruff-0.3.6 lib/gruff/stacked_area.rb