Module: Ambling::Helper

Defined in:
lib/ambling_helper.rb

Overview

:nodoc

Defined Under Namespace

Classes: AmblingHelperError

Instance Method Summary collapse

Instance Method Details

#ambling_chart(chart_type, chart_options = {}, &block) ⇒ Object

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

  • :swf_params - Hash of params to be set on SWFObject (with so.addParam()).

  • :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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ambling_helper.rb', line 28

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', " +
                                  "'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, :chart_id) # this is needed for controlling charts with JS
  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 << add_swf_params(options, :swf_params, true)
  
  script << "so.write('#{options[:id]}');"
  html = yield
  ('div', html, :id => options[:id]) + javascript_tag(script)
end