Module Ambling::Helper
In: lib/ambling_helper.rb

Methods

Classes and Modules

Class Ambling::Helper::AmblingHelperError

Constants

CHART_PATH = "/amcharts" unless defined? CHART_PATH

Public Instance methods

Generates chart object tag with given url to fetch the xml data. See Ambling for examples Chart Options:

  • :width - The width of the chart
  • :height - The height of the chart
  • :swf_path - The path that contains the chart.swf. Defaults to /amcharts
  • :flash_version - Supported flash version. Defaults to 8
  • :background_color - The chart background color. Defaults to ‘FFFFFF‘
  • :preloader_color - The color of the preloading text. Defaults to ‘000000‘
  • :express_install - Use the swfobject express install if the browser does not have flash installed. Defaults to true
  • :id - The id of the DOM element that will be replaced
  • :settings_file - The path to the xml settings file (could be url)
  • :chart_settings - Inline xml settings. Use one of settings_file and chart_settings
  • :additional_chart_settings - More inline xml settings.
  • :data_file - The path to the xml data file (could be url)
  • :chart_data - Inline xml data. Use one of data_file and chart_data

[Source]

# File lib/ambling_helper.rb, line 27
    def ambling_chart(chart_type, chart_options = {}, &block)
      options = { :width              => "400",
                  :height             => "300",
                  :swf_path           => CHART_PATH,
                  :flash_version      => "8",
                  :background_color   => "#FFFFFF",
                  :preloader_color    => "#000000",
                  :express_install    => true,
                  :id                 => "ambling_chart"
                }.merge!(chart_options)
      script = "var so = new SWFObject('#{options[:swf_path]}/am#{chart_type}.swf', " +
                                      "'#{options[:id]}', '#{options[:width]}', '#{options[:height]}', " +
                                      "'#{options[:flash_version]}', '#{options[:background_color]}');"
      script << "so.addVariable('path', '#{options[:swf_path]}/');"
      script << "so.useExpressInstall('#{options[:swf_path]}/expressinstall.swf');" if options[:express_install]
      
      script << add_variable(options, :settings_file, true)
      script << add_variable(options, :chart_settings)
      script << add_variable(options, :additional_chart_settings)
      
      script << add_variable(options, :data_file, true)
      script << add_variable(options, :chart_data)
      
      script << add_variable(options, :preloader_color)
      script << "so.write('#{options[:id]}');"
      html = yield
      content_tag('div', html, :id => options[:id]) + javascript_tag(script)
    end

[Validate]