class Scruffy::Components::Base

Scruffy::Components::Base

Common attributes for all components, and a standard render method that calls draw after setting up the drawing transformations.

Attributes

id[R]
options[RW]
position[RW]

In terms of percentages: [10, 10] == 10% by 10%

size[RW]
visible[RW]

Public Class Methods

new(id, options = {}) click to toggle source

Options:

stroke_width

numeric value for width of line (0.1 - 10, default: 1)

# File lib/scruffy/components/base.rb, line 18
def initialize(id, options = {})
  @id = id.to_sym
  @position = options[:position] || [0, 0]
  @size = options[:size] || [100, 100]
  @visible = options[:visible] || true
  
  @options = options
end

Public Instance Methods

draw(svg, bounds, options={}) click to toggle source
# File lib/scruffy/components/base.rb, line 43
def draw(svg, bounds, options={})
  # Override this if visual component
end
process(svg, options={}) click to toggle source
# File lib/scruffy/components/base.rb, line 47
def process(svg, options={})
  # Override this NOT a visual component
end
render(svg, bounds, options={}) click to toggle source
# File lib/scruffy/components/base.rb, line 27
def render(svg, bounds, options={})
  if @visible
    unless bounds.nil?
      @render_height = bounds[:height]
  
      svg.g(:id => id.to_s, 
            :transform => "translate(#{bounds.delete(:x)}, #{bounds.delete(:y)})") {

        draw(svg, bounds, options.merge(@options))
      }
    else
      process(svg, options.merge(@options))
    end
  end
end

Protected Instance Methods

relative(pct) click to toggle source
# File lib/scruffy/components/base.rb, line 52
def relative(pct)
  @render_height * ( pct / 100.to_f )
end