Class: Scruffy::Components::Base
- Inherits:
-
Object
- Object
- Scruffy::Components::Base
- Defined in:
- lib/scruffy/components/base.rb
Overview
Scruffy::Components::Base
Common attributes for all components, and a standard render method that calls draw after setting up the drawing transformations.
Direct Known Subclasses
Background, DataMarkers, Graphs, Grid, Label, Legend, StyleInfo, Title, ValueMarkers, Viewport
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#position ⇒ Object
In terms of percentages: [10, 10] == 10% by 10%.
-
#size ⇒ Object
Returns the value of attribute size.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
- #draw(svg, bounds, options = {}) ⇒ Object
-
#initialize(id, options = {}) ⇒ Base
constructor
A new instance of Base.
- #process(svg, options = {}) ⇒ Object
- #render(svg, bounds, options = {}) ⇒ Object
Constructor Details
#initialize(id, options = {}) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 |
# File 'lib/scruffy/components/base.rb', line 16 def initialize(id, = {}) @id = id.to_sym @position = [:position] || [0, 0] @size = [:size] || [100, 100] @visible = [:visible] || true @options = end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/scruffy/components/base.rb', line 8 def id @id end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/scruffy/components/base.rb', line 13 def @options end |
#position ⇒ Object
In terms of percentages: [10, 10] == 10% by 10%
11 12 13 |
# File 'lib/scruffy/components/base.rb', line 11 def position @position end |
#size ⇒ Object
Returns the value of attribute size.
12 13 14 |
# File 'lib/scruffy/components/base.rb', line 12 def size @size end |
#visible ⇒ Object
Returns the value of attribute visible.
14 15 16 |
# File 'lib/scruffy/components/base.rb', line 14 def visible @visible end |
Instance Method Details
#draw(svg, bounds, options = {}) ⇒ Object
40 41 42 |
# File 'lib/scruffy/components/base.rb', line 40 def draw(svg, bounds, ={}) # Override this if visual component end |
#process(svg, options = {}) ⇒ Object
44 45 46 |
# File 'lib/scruffy/components/base.rb', line 44 def process(svg, ={}) # Override this NOT a visual component end |
#render(svg, bounds, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/scruffy/components/base.rb', line 24 def render(svg, bounds, ={}) 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, .merge(@options)) } else process(svg, .merge(@options)) end end end |