Module: OFC2::InstanceMethods

Defined in:
lib/ofc2.rb

Instance Method Summary collapse

Instance Method Details

#ofc2(width, height, url, base = '/', id = Time.now.usec, swf_base = '/', 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)
+base+ uri for graph, default '/'
+id+ id for div with graph, default Time.now.usec
+swf_base+ uri for swf file, default '/'


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

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

#ofc2_inline(width, height, graph, id = Time.now.usec, swf_base = '/', 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
+base+ uri for graph, default '/', not used in this method, go to ofc2 method for details
+id+ id for div with graph, default Time.now.usec
+swf_base+ uri for swf file, default '/'


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

def ofc2_inline(width, height, graph, id=Time.now.usec, swf_base='/', flash_attributes = {}, flash_params = {})
  div_name = "flashcontent_#{id}"
  "    <div id=\"\#{div_name}\"></div>\n    <script type=\"text/javascript\">\n\n      function \#{div_name}_data(){\n        return '\#{graph.render}';\n      };\n\n      swfobject.embedSWF(\n        '\#{swf_base}open-flash-chart.swf', '\#{div_name}',\n        '\#{width}', '\#{height}','9.0.0', 'expressInstall.swf',\n        {'get-data':'\#{div_name}_data'}, \#{flash_params.to_json}, \#{flash_attributes.to_json} );\n\n    </script>\n  EOF\nend\n"