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
- Options: stroke_width
-
numeric value for width of line (0.1 - 10, default: 1).
- #process(svg, options = {}) ⇒ Object
- #render(svg, bounds, options = {}) ⇒ Object
Constructor Details
#initialize(id, options = {}) ⇒ Base
Options:
- stroke_width
-
numeric value for width of line (0.1 - 10, default: 1)
18 19 20 21 22 23 24 25 |
# File 'lib/scruffy/components/base.rb', line 18 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
43 44 45 |
# File 'lib/scruffy/components/base.rb', line 43 def draw(svg, bounds, ={}) # Override this if visual component end |
#process(svg, options = {}) ⇒ Object
47 48 49 |
# File 'lib/scruffy/components/base.rb', line 47 def process(svg, ={}) # Override this NOT a visual component end |
#render(svg, bounds, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/scruffy/components/base.rb', line 27 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 |