]> projects.mako.cc - selectricity-live/blob - vendor/plugins/gruff/lib/gruff/area.rb
323aff15daa218469ff0a33e79485ff6b35be116
[selectricity-live] / vendor / plugins / gruff / lib / gruff / area.rb
1
2 require File.dirname(__FILE__) + '/base'
3
4 class Gruff::Area < Gruff::Base
5
6   def draw
7     super
8
9     return unless @has_data
10
11     @x_increment = @graph_width / (@column_count - 1).to_f
12     @d = @d.stroke 'transparent'
13
14     @norm_data.each do |data_row|
15       poly_points = Array.new
16       prev_x = prev_y = 0.0
17       @d = @d.fill data_row[DATA_COLOR_INDEX]
18
19       data_row[1].each_with_index do |data_point, index|
20         # Use incremented x and scaled y
21         new_x = @graph_left + (@x_increment * index)
22         new_y = @graph_top + (@graph_height - data_point * @graph_height)
23
24         if prev_x > 0 and prev_y > 0 then
25           poly_points << new_x
26           poly_points << new_y
27           
28           #@d = @d.polyline(prev_x, prev_y, new_x, new_y)
29         else
30           poly_points << @graph_left
31           poly_points << @graph_bottom - 1
32           poly_points << new_x
33           poly_points << new_y
34           
35           #@d = @d.polyline(@graph_left, @graph_bottom, new_x, new_y)
36         end
37
38         draw_label(new_x, index)
39
40         prev_x = new_x
41         prev_y = new_y
42       end
43
44       # Add closing points, draw polygon
45       poly_points << @graph_right
46       poly_points << @graph_bottom - 1
47       poly_points << @graph_left
48       poly_points << @graph_bottom - 1
49
50       @d = @d.polyline(*poly_points)
51
52     end
53
54     @d.draw(@base_image)
55   end
56    
57  
58 end

Benjamin Mako Hill || Want to submit a patch?