Class: Scruffy::Renderers::Base
- Inherits:
-
Object
- Object
- Scruffy::Renderers::Base
- Includes:
- Helpers::Canvas
- Defined in:
- lib/scruffy/renderers/base.rb
Overview
Scruffy::Renderers::Base
- Author
-
Brasten Sager
- Date
-
August 14th, 2006
Provides all the base functionality needed to render a graph, but does not provide a default layout.
For a basic layout, see Scruffy::Renderers::Standard.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes included from Helpers::Canvas
Instance Method Summary collapse
- #before_render ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #method_missing(sym, *args) ⇒ Object
-
#render(options = {}) ⇒ Object
Renders the graph and all components.
Methods included from Helpers::Canvas
#component, #remove, #reset_settings!
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 |
# File 'lib/scruffy/renderers/base.rb', line 17 def initialize( = {}) self.components = [] self. = define_layout end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/scruffy/renderers/base.rb', line 56 def method_missing(sym, *args) self. = {} if self..nil? if args.size > 0 self.[sym] = args[0] else return self.[sym] end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/scruffy/renderers/base.rb', line 15 def @options end |
Instance Method Details
#before_render ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/scruffy/renderers/base.rb', line 47 def before_render if self. set_values(self.[:values]) if (self.[:values] && self.[:values] != :hide) hide_grid if (self.[:grid] == :hide) hide_values if (self.[:values] == :hide) hide_labels if (self.[:labels] == :hide) end end |
#render(options = {}) ⇒ Object
Renders the graph and all components.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/scruffy/renderers/base.rb', line 24 def render( = {}) [:graph_id] ||= 'scruffy_graph' [:complexity] ||= (global_complexity || :normal) # Allow subclasses to muck with components prior to renders. rendertime_renderer = self.clone rendertime_renderer.instance_eval { before_render if respond_to?(:before_render) } svg = Builder::XmlMarkup.new(:indent => 2) svg.instruct! svg.instruct! 'DOCTYPE', 'svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" type' svg.svg(:xmlns => "http://www.w3.org/2000/svg", 'xmlns:xlink' => "http://www.w3.org/1999/xlink", :width => [:size].first, :height => [:size].last) { svg.g(:id => [:graph_id]) { rendertime_renderer.components.each do |component| component.render(svg, bounds_for( [:size], component.position, component.size ), ) end } } svg.target! end |