Common attributes for all components, and a standard render method that calls draw after setting up the drawing transformations.
In terms of percentages: [10, 10] == 10% by 10%
Options:
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
# File lib/scruffy/components/base.rb, line 43 def draw(svg, bounds, options={}) # Override this if visual component end
# File lib/scruffy/components/base.rb, line 47 def process(svg, options={}) # Override this NOT a visual component end
# 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
# File lib/scruffy/components/base.rb, line 52 def relative(pct) @render_height * ( pct / 100.to_f ) end