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