Class: Scruffy::Components::Viewport

Inherits:
Base
  • Object
show all
Includes:
Helpers::Canvas
Defined in:
lib/scruffy/components/viewport.rb

Overview

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

Instance Attribute Summary

Attributes included from Helpers::Canvas

#components

Attributes inherited from Base

#id, #options, #position, #size, #visible

Instance Method Summary collapse

Methods included from Helpers::Canvas

#component, #remove, #reset_settings!

Methods inherited from Base

#process, #render

Constructor Details

#initialize(*args, &block) ⇒ Viewport

Returns a new instance of Viewport.



6
7
8
9
10
11
# File 'lib/scruffy/components/viewport.rb', line 6

def initialize(*args, &block)
  super(*args)
  
  self.components = []
  block.call(self.components) if block
end

Instance Method Details

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



13
14
15
16
17
18
19
20
21
22
23
# 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