Class: Ziya::Charts::Support::Draw
- Includes:
- HtmlHelpers::Charts
- Defined in:
- lib/ziya/charts/support/draw.rb
Overview
Sets up a drawing area on the chart to draw text, rect, circles…
Holds any number of elements to draw. A draw element can be a circle, image (JPEG or SWF), line, rectangle, or text. Use draw “image” to include SWF flash file with animation, roll-over buttons, sounds, scripts, etc.
:
See www.maani.us/xml_charts/index.php?menu=Reference&submenu=draw for additional documentation, examples and futher detail.
Instance Method Summary collapse
-
#flatten(xml, composite_urls = nil) ⇒ Object
————————————————————————- Dump has_attribute into xml element.
-
#gen_composites(xml, composite_urls) ⇒ Object
————————————————————————- Generates Draw component for composite charts.
-
#merge(parent_attributes, override = false) ⇒ Object
————————————————————————- Override merge attributes enhance component definitions vs override.
-
#opts_as_string(opts) ⇒ Object
————————————————————————- Turns options hash into string representation.
Methods included from HtmlHelpers::Charts
#_ziya_chart, #chart_path, #charts_swf, #charts_swf_base, #class_id, #codebase, #composite_base_url, #composite_url, #default_chart_options, #gen_composite_path, #gen_swf_path, #ziya_chart, #ziya_chart_js, #ziya_javascript_include_tag
Methods included from HtmlHelpers::Base
#escape_chars, #escape_once, #escape_url, #mime, #plugin_url, #setup_movie_size, #setup_wmode, #tag_options, #ziya_tag
Methods inherited from Base
#==, attributes, #attributes_for, #configured?, has_attribute, #has_sub_components, #initialize, #options, #options_as_string
Constructor Details
This class inherits a constructor from Ziya::Charts::Support::Base
Instance Method Details
#flatten(xml, composite_urls = nil) ⇒ Object
Dump has_attribute into xml element
35 36 37 38 39 40 41 42 |
# File 'lib/ziya/charts/support/draw.rb', line 35 def flatten( xml, composite_urls=nil ) if components or composite_urls xml.draw do components.each { |comp| comp.flatten( xml ) } if components gen_composites( xml, composite_urls ) if composite_urls end end end |
#gen_composites(xml, composite_urls) ⇒ Object
Generates Draw component for composite charts
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ziya/charts/support/draw.rb', line 46 def gen_composites( xml, composite_urls ) composite_urls.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |chart_id| # composite descriptor can either be a string for the comp url or a pair for the swf lib_path and url raise "You must specify a hash of options" unless composite_urls[chart_id].is_a? Hash opts = composite_urls[chart_id].clone url = opts.delete( :url ) raise "Unable to find composite chart url" unless url path = opts.delete(:path ) || chart_path opts[:url] = gen_composite_path( path, url, chart_id ) self.class.module_eval <<-XML xml.image( #{opts_as_string( opts )} ) XML # xml.image( opts ) end end |
#merge(parent_attributes, override = false) ⇒ Object
Override merge attributes enhance component definitions vs override
27 28 29 30 31 |
# File 'lib/ziya/charts/support/draw.rb', line 27 def merge( parent_attributes, override=false ) comps = send( :components ) || [] comps = comps + parent_attributes.send( :components ) if parent_attributes.send( :components ) send( "components=", comps ) end |
#opts_as_string(opts) ⇒ Object
Turns options hash into string representation
66 67 68 69 70 71 72 73 |
# File 'lib/ziya/charts/support/draw.rb', line 66 def opts_as_string( opts ) buff = [] opts.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |k| value = opts[k] buff << sprintf( ":%s => '%s'", k, value.to_s ) if value end buff.join( "," ) end |