Module: OFC2::InstanceMethods

Defined in:
lib/ofc2.rb

Instance Method Summary collapse

Instance Method Details

#ofc2(width, height, url, id = Time.now.usec, flash_attributes = {}, flash_params = {}) ⇒ Object

generate a ofc object using data from url

+width+ width for div
+height+ height for div
+url+ an url which return data in json format, if you use url_for method to set url param the base param must be set to '' (empty string)
+id+ id for div with graph, default Time.now.usec
+flash_attributes+ attributes for swf
+flash_params+ params for swf


83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ofc2.rb', line 83

def ofc2(width, height, url, id =Time.now.usec, flash_attributes = {}, flash_params = {})
  url = CGI::escape(url)
  div_name = "flashcontent_#{id}"
  <<-EOF
    <div id='#{div_name}'></div>
    <script type="text/javascript">
      swfobject.embedSWF(
      "/assets/open-flash-chart.swf","#{div_name}",
      "#{width}", "#{height}", "9.0.0", "/assets/expressInstall.swf",
      {"data-file":"#{url}"}, #{flash_params.to_json}, #{flash_attributes.to_json} );

    </script>
  EOF
end

#ofc2_inline(width, height, graph, id = Time.now.usec, flash_attributes = {}, flash_params = {}) ⇒ Object

generate a ofc object using Graph object, it’s more handy than ofc2 method

+width+ width for div
+height+ height for div
+graph+ a OFC2::Graph object
+id+ id for div with graph, default Time.now.usec
+flash_attributes+ attributes for swf
+flash_params+ params for swf


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ofc2.rb', line 57

def ofc2_inline(width, height, graph, id=Time.now.usec, flash_attributes = {}, flash_params = {})
  div_name = "flashcontent_#{id}"
  <<-EOF
    <div id="#{div_name}"></div>
    <script type="text/javascript">

      function #{div_name}_data(){
        return '#{graph.render}';
      };

      swfobject.embedSWF(
        '/assets/open-flash-chart.swf', '#{div_name}',
        '#{width}', '#{height}','9.0.0', '/assets/expressInstall.swf',
        {'get-data':'#{div_name}_data'}, #{flash_params.to_json}, #{flash_attributes.to_json} );

    </script>
  EOF
end