Class: Scruffy::Layers::Bar

Inherits:
Base
  • Object
show all
Defined in:
lib/scruffy/layers/bar.rb

Overview

Scruffy::Layers::Bar

Author

Brasten Sager

Date

August 6th, 2006

Standard bar graph.

Instance Attribute Summary

Attributes inherited from Base

#color, #complexity, #height, #max_value, #min_value, #opacity, #options, #points, #preferred_color, #relevant_data, #title, #width

Instance Method Summary collapse

Methods inherited from Base

#bottom_value, #initialize, #legend_data, #relevant_data?, #render, #sum_values, #top_value

Constructor Details

This class inherits a constructor from Scruffy::Layers::Base

Instance Method Details

#draw(svg, coords, options = {}) ⇒ Object

Draw bar graph.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scruffy/layers/bar.rb', line 11

def draw(svg, coords, options = {})
  coords.each do |coord|
    x, y, bar_height = (coord.first-(@bar_width * 0.5)), coord.last, (height - coord.last)

    svg.g(:transform => "translate(-#{relative(0.5)}, -#{relative(0.5)})") {
      svg.rect( :x => x, :y => y, :width => @bar_width + relative(1), :height => bar_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 => bar_height - relative(0.5), 
                :style => "fill: black; fill-opacity: 0.15; stroke: none;" )

    }
    
    svg.rect( :x => x, :y => y, :width => @bar_width, :height => bar_height, 
              :fill => color.to_s, 'style' => "opacity: #{opacity}; stroke: none;" )
  end
end