Class: Tuftify::GraphAreaPanel
- Defined in:
- lib/tuftify/graph_area_panel.rb
Instance Attribute Summary
Attributes inherited from Panel
#canvas, #height, #width, #x, #y
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(data, x_orig, y_orig, width, height, canvas, options) ⇒ GraphAreaPanel
constructor
A new instance of GraphAreaPanel.
Constructor Details
#initialize(data, x_orig, y_orig, width, height, canvas, options) ⇒ GraphAreaPanel
Returns a new instance of GraphAreaPanel.
5 6 7 8 |
# File 'lib/tuftify/graph_area_panel.rb', line 5 def initialize(data, x_orig, y_orig, width, height, canvas, ) super x_orig, y_orig, width, height, canvas, @data = data end |
Instance Method Details
#draw ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tuftify/graph_area_panel.rb', line 10 def draw max_value = @data.collect {|v| v[1]}.max scaling = @height.to_f / max_value = @width / @data.length x = @x @data.each do |key, value| h = scaling * value @drawing.fill(@options[:fill]) @drawing.stroke(@options[:stroke]) @drawing.rectangle(x, @y + @height, x + , @y + @height - h) x += end @drawing.draw @canvas # @drawing.stroke("red") # @drawing.stroke_width(3) # @drawing.line(@x,@y + @height,@width,@y + @height) # @drawing.draw @canvas end |