Module: JustHighCharts::LayoutHelper

Includes:
ActionView::Helpers::TagHelper
Included in:
HighChart
Defined in:
lib/just_high_charts/layout_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_html_output(type, placeholder, object, &block) ⇒ Object



27
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/just_high_charts/layout_helper.rb', line 27

def build_html_output(type, placeholder, object, &block)
  options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(object.options))]
  options_collection << %|"series": [#{generate_json_from_array(object.series_data)}]|

  core_js ="    var options = { \#{options_collection.join(',')} };\n    \#{capture(&block) if block_given?}\n    window.chart_\#{placeholder.underscore} = new Highcharts.\#{type}(options);\n  EOJS\n\n  if defined?(request) && request.respond_to?(:xhr?) && request.xhr?\n    graph =<<-EOJS\n    <script type=\"text/javascript\">\n    (function() {\n      \#{core_js}\n    })()\n    </script>\n    EOJS\n  elsif defined?(Turbolinks) && request.headers[\"X-XHR-Referer\"]\n    graph =<<-EOJS\n    <script type=\"text/javascript\">\n    (function() {\n      var f = function(){\n        document.removeEventListener('page:load', f, true);\n        \#{core_js}\n      };\n      document.addEventListener('page:load', f, true);\n    })()\n    </script>\n    EOJS\n  else\n    graph =<<-EOJS\n    <script type=\"text/javascript\">\n    (function() {\n      var onload = window.onload;\n      window.onload = function(){\n        if (typeof onload == \"function\") onload();\n        \#{core_js}\n      };\n    })()\n    </script>\n    EOJS\n  end\n\n  if defined?(raw)\n    return raw(graph)\n  else\n    return graph\n  end\n\nend\n"

#high_chart(placeholder, object, &block) ⇒ Object



7
8
9
10
11
# File 'lib/just_high_charts/layout_helper.rb', line 7

def high_chart(placeholder, object, &block)
  object.html_options.merge!({:id => placeholder})
  object.options[:chart][:renderTo] = placeholder
  high_graph(placeholder, object, &block).concat(("div", "", object.html_options))
end

#high_graph(placeholder, object, &block) ⇒ Object



19
20
21
# File 'lib/just_high_charts/layout_helper.rb', line 19

def high_graph(placeholder, object, &block)
  build_html_output("Chart", placeholder, object, &block)
end

#high_graph_stock(placeholder, object, &block) ⇒ Object



23
24
25
# File 'lib/just_high_charts/layout_helper.rb', line 23

def high_graph_stock(placeholder, object, &block)
  build_html_output("StockChart", placeholder, object, &block)
end

#high_stock(placeholder, object, &block) ⇒ Object



13
14
15
16
17
# File 'lib/just_high_charts/layout_helper.rb', line 13

def high_stock(placeholder, object, &block)
  object.html_options.merge!({:id => placeholder})
  object.options[:chart][:renderTo] = placeholder
  high_graph_stock(placeholder, object, &block).concat(("div", "", object.html_options))
end