Class: Scruffy::Layers::Bar
Overview
Scruffy::Layers::Bar
- Author
-
Brasten Sager
- Date
-
August 6th, 2006
Standard bar graph.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#color, #complexity, #height, #max_value, #min_value, #opacity, #options, #outline, #points, #preferred_color, #preferred_outline, #relevant_data, #title, #width
Instance Method Summary collapse
-
#draw(svg, coords, options = {}) ⇒ Object
Draw bar graph.
Methods inherited from Base
#bottom_key, #bottom_value, #initialize, #legend_data, #relevant_data?, #render, #sum_values, #top_key, #top_value
Constructor Details
This class inherits a constructor from Scruffy::Layers::Base
Instance Method Details
#draw(svg, coords, options = {}) ⇒ Object
Draw bar graph. Now handles positive and negative values gracefully.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/scruffy/layers/bar.rb', line 12 def draw(svg, coords, = {}) coords.each_with_index do |coord,idx| x, y, = (coord.first), coord.last, 1#(height - coord.last) valh = max_value + min_value * -1 #value_height maxh = max_value * height / valh #positive area height minh = min_value * height / valh #negative area height #puts "height = #{height} and max_value = #{max_value} and min_value = #{min_value} and y = #{y} and point = #{points[idx]}" if points[idx] > 0 = points[idx]*maxh/max_value else = points[idx]*minh/min_value end #puts " y = #{y} and point = #{points[idx]}" svg.g(:transform => "translate(-#{relative(0.5)}, -#{relative(0.5)})") { svg.rect( :x => x, :y => y, :width => @bar_width + relative(1), :height => + relative(1), :style => "fill: black; fill-opacity: 0.15; stroke: none;" ) svg.rect( :x => x+relative(0.5), :y => y+relative(2), :width => @bar_width + relative(1), :height => - relative(0.5), :style => "fill: black; fill-opacity: 0.15; stroke: none;" ) } svg.rect( :x => x, :y => y, :width => @bar_width, :height => , :fill => color.to_s, 'style' => "opacity: #{opacity}; stroke: none;" ) end end |