Class: Tuttify::BarGraph
- Inherits:
-
Graph
- Object
- Graph
- Tuttify::BarGraph
- Defined in:
- lib/tuftify/bar_graph.rb
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize ⇒ BarGraph
constructor
A new instance of BarGraph.
Constructor Details
#initialize ⇒ BarGraph
Returns a new instance of BarGraph.
6 7 8 |
# File 'lib/tuftify/bar_graph.rb', line 6 def initialize end |
Instance Method Details
#draw ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tuftify/bar_graph.rb', line 10 def draw max_value = @values.collect {|v| v[1]}.max = @width / @values.length x = 0 lh = label_height draw_height = @height - lh @values.each do |key, value| h = draw_height / max_value * value @drawing.fill('black') @drawing.stroke('white') @drawing.rectangle(x, draw_height, x + , draw_height - h) @drawing.annotate(@canvas, , lh, x, draw_height, key.to_s) x += end @drawing.draw(@canvas) return @canvas end |