Module: LazyHighCharts::LayoutHelper
- Includes:
- ActionView::Helpers::TagHelper
- Included in:
- HighChart
- Defined in:
- lib/lazy_high_charts/layout_helper.rb
Instance Method Summary collapse
- #build_html_output(type, placeholder, object, &block) ⇒ Object
- #high_chart(placeholder, object, &block) ⇒ Object
- #high_graph(placeholder, object, &block) ⇒ Object
- #high_graph_stock(placeholder, object, &block) ⇒ Object
- #high_stock(placeholder, object, &block) ⇒ Object
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/lazy_high_charts/layout_helper.rb', line 27 def build_html_output(type, placeholder, object, &block) = [generate_json_from_hash(OptionsKeyFilter.filter(object.))] << %|"series": [#{generate_json_from_array(object.series_data)}]| core_js =<<-EOJS var options = { #{.join(',')} }; #{capture(&block) if block_given?} window.chart_#{placeholder.underscore} = new Highcharts.#{type}(options); EOJS if defined?(request) && request.respond_to?(:xhr?) && request.xhr? graph =<<-EOJS <script type="text/javascript"> (function() { #{core_js} })() </script> EOJS elsif defined?(Turbolinks) && request.headers["X-XHR-Referer"] graph =<<-EOJS <script type="text/javascript"> (function() { var f = function(){ document.removeEventListener('page:load', f, true); #{core_js} }; document.addEventListener('page:load', f, true); })() </script> EOJS else graph =<<-EOJS <script type="text/javascript"> (function() { var onload = window.onload; window.onload = function(){ if (typeof onload == "function") onload(); #{core_js} }; })() </script> EOJS end if defined?(raw) return raw(graph) else return graph end end |
#high_chart(placeholder, object, &block) ⇒ Object
7 8 9 10 11 |
# File 'lib/lazy_high_charts/layout_helper.rb', line 7 def high_chart(placeholder, object, &block) object..merge!({:id => placeholder}) object.[:chart][:renderTo] = placeholder high_graph(placeholder, object, &block).concat(content_tag("div", "", object.)) end |
#high_graph(placeholder, object, &block) ⇒ Object
19 20 21 |
# File 'lib/lazy_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/lazy_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/lazy_high_charts/layout_helper.rb', line 13 def high_stock(placeholder, object, &block) object..merge!({:id => placeholder}) object.[:chart][:renderTo] = placeholder high_graph_stock(placeholder, object, &block).concat(content_tag("div", "", object.)) end |