class Scruffy::Components::Viewport

Component used to limit other visual components to a certain area on the graph.

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method Scruffy::Components::Base::new
# File lib/scruffy/components/viewport.rb, line 6
def initialize(*args, &block)
  super(*args)
  
  self.components = []
  block.call(self.components) if block
end

Public Instance Methods

draw(svg, bounds, options={}) click to toggle source
# File lib/scruffy/components/viewport.rb, line 13
def draw(svg, bounds, options={})
  svg.g(options_for) {
    self.components.each do |component|
      component.render(svg, 
        bounds_for([bounds[:width], bounds[:height]], 
          component.position, 
          component.size), 
        options)
    end
  }
end

Private Instance Methods

options_for() click to toggle source
# File lib/scruffy/components/viewport.rb, line 26
def options_for
  options = {}
  %w(skewX skewY).each do |option|
    if @options[option.to_sym]
      options[:transform] ||= ''
      options[:transform] = options[:transform] + "#{option.to_s}(#{@options[option.to_sym]})"
    end
  end
  options
end