Skip to content

Commit

Permalink
Merge branch 'bezier'
Browse files Browse the repository at this point in the history
  • Loading branch information
donv committed Oct 16, 2012
2 parents f5854bb + 67f0218 commit e50f327
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gruff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
base
area
bar
bezier
line
dot
pie
Expand Down
54 changes: 54 additions & 0 deletions lib/gruff/bezier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

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

class Gruff::Bezier < Gruff::Base

def draw
super

return unless @has_data

@x_increment = @graph_width / (@column_count - 1).to_f


@norm_data.each do |data_row|
poly_points = Array.new
prev_x = prev_y = 0.0
@d = @d.fill data_row[DATA_COLOR_INDEX]


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)

if prev_x >= 0 and prev_y >= 0 then
poly_points << new_x
poly_points << new_y

else
poly_points << @graph_left
poly_points << @graph_bottom - 1
poly_points << new_x
poly_points << new_y

end

draw_label(new_x, index)

prev_x = new_x
prev_y = new_y
end

@d = @d.fill_opacity 0.0
@d = @d.stroke data_row[DATA_COLOR_INDEX]
@d = @d.stroke_width clip_value_if_greater_than(@columns / (@norm_data.first[1].size * 4), 5.0)

@d = @d.bezier(*poly_points)
end

@d.draw(@base_image)
end


end

0 comments on commit e50f327

Please sign in to comment.