Parent

Methods

Included Modules

Gruff::StackedArea

Attributes

last_series_goes_on_bottom[RW]

Public Instance Methods

draw() click to toggle source
    # File lib/gruff/stacked_area.rb, line 9
 9:   def draw
10:     get_maximum_by_stack
11:     super
12: 
13:     return unless @has_data
14: 
15:     @x_increment = @graph_width / (@column_count - 1).to_f
16:     @d = @d.stroke 'transparent'
17: 
18:     height = Array.new(@column_count, 0)
19: 
20:     data_points = nil
21:     iterator = last_series_goes_on_bottom ? :reverse_each : :each
22:     @norm_data.send(iterator) do |data_row|
23:       prev_data_points = data_points
24:       data_points = Array.new
25:         
26:       @d = @d.fill data_row[DATA_COLOR_INDEX]
27: 
28:       data_row[DATA_VALUES_INDEX].each_with_index do |data_point, index|
29:         # Use incremented x and scaled y
30:         new_x = @graph_left + (@x_increment * index)
31:         new_y = @graph_top + (@graph_height - data_point * @graph_height - height[index])
32: 
33:         height[index] += (data_point * @graph_height)
34:         
35:         data_points << new_x
36:         data_points << new_y
37:           
38:         draw_label(new_x, index)
39: 
40:       end
41: 
42:       if prev_data_points
43:         poly_points = data_points.dup
44:         (prev_data_points.length/2 - 1).downto(0) do |i|
45:           poly_points << prev_data_points[2*i] 
46:           poly_points << prev_data_points[2*i+1]
47:         end
48:         poly_points << data_points[0] 
49:         poly_points << data_points[1] 
50:       else
51:         poly_points = data_points.dup
52:         poly_points << @graph_right
53:         poly_points << @graph_bottom - 1
54:         poly_points << @graph_left
55:         poly_points << @graph_bottom - 1
56:         poly_points << data_points[0] 
57:         poly_points << data_points[1] 
58:       end
59:       @d = @d.polyline(*poly_points)
60: 
61:     end
62: 
63:     @d.draw(@base_image)
64:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.