Class: LazyHighCharts::HighChart
- Inherits:
-
Object
- Object
- LazyHighCharts::HighChart
- Includes:
- LayoutHelper
- Defined in:
- lib/lazy_high_charts/high_chart.rb
Constant Summary collapse
- SERIES_OPTIONS =
%w(data index legendIndex name stack type xAxis yAxis)
Instance Attribute Summary collapse
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#options ⇒ Object
Returns the value of attribute options.
-
#placeholder ⇒ Object
(also: #canvas)
Returns the value of attribute placeholder.
-
#series_data ⇒ Object
Returns the value of attribute series_data.
Instance Method Summary collapse
-
#defaults_options ⇒ Object
title: legend: xAxis: yAxis: tooltip: credits: :plotOptions.
-
#full_options ⇒ Hash
Pre-processes and returns full set of options relevant to the chart.
-
#initialize(canvas = nil, html_opts = {}) ⇒ HighChart
constructor
A new instance of HighChart.
-
#method_missing(meth, opts = {}) ⇒ Object
Pass other methods through to the javascript high_chart object.
-
#series(opts = {}) ⇒ Object
Add a simple series to the graph:.
- #to_json ⇒ Object
Methods included from LayoutHelper
#high_chart, #high_chart_globals, #high_graph, #high_graph_stock, #high_stock
Constructor Details
#initialize(canvas = nil, html_opts = {}) ⇒ HighChart
Returns a new instance of HighChart.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lazy_high_charts/high_chart.rb', line 12 def initialize(canvas = nil, html_opts = {}) self.tap do |high_chart| high_chart.series_data ||= [] high_chart. ||= {} high_chart. high_chart. ||= html_opts high_chart.canvas = (canvas ? canvas : random_canvas_id) yield high_chart if block_given? end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, opts = {}) ⇒ Object
Pass other methods through to the javascript high_chart object.
For instance: high_chart.grid(:color => "#699")
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lazy_high_charts/high_chart.rb', line 40 def method_missing(meth, opts = {}) if meth.to_s == 'to_ary' super end if meth.to_s.end_with? '!' meth[0..-2].to_sym, opts else meth, opts end end |
Instance Attribute Details
#html_options ⇒ Object
Returns the value of attribute html_options.
8 9 10 |
# File 'lib/lazy_high_charts/high_chart.rb', line 8 def @html_options end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/lazy_high_charts/high_chart.rb', line 8 def @options end |
#placeholder ⇒ Object Also known as: canvas
Returns the value of attribute placeholder.
8 9 10 |
# File 'lib/lazy_high_charts/high_chart.rb', line 8 def placeholder @placeholder end |
#series_data ⇒ Object
Returns the value of attribute series_data.
8 9 10 |
# File 'lib/lazy_high_charts/high_chart.rb', line 8 def series_data @series_data end |
Instance Method Details
#defaults_options ⇒ Object
title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lazy_high_charts/high_chart.rb', line 25 def self.title({:text => nil}) self.legend({:layout => "vertical", :style => {}}) self.xAxis({}) self.yAxis({:title => {:text => nil}, :labels => {}}) self.tooltip({:enabled => true}) self.credits({:enabled => false}) self.plotOptions({:areaspline => {}}) self.chart({:defaultSeriesType => "line", :renderTo => nil}) self.subtitle({}) end |
#full_options ⇒ Hash
Pre-processes and returns full set of options relevant to the chart. Identical to what happens in the high_charts view helper.
67 68 69 |
# File 'lib/lazy_high_charts/high_chart.rb', line 67 def self end |
#series(opts = {}) ⇒ Object
Add a simple series to the graph:
data = [[0,5], [1,5], [2,5]]
@high_chart.series :name=>'Updated', :data=>data
@high_chart.series :name=>'Updated', :data=>[5, 1, 6, 1, 5, 4, 9]
57 58 59 60 61 |
# File 'lib/lazy_high_charts/high_chart.rb', line 57 def series(opts = {}) if not opts.empty? @series_data << OptionsKeyFilter.filter(opts.merge(:name => opts[:name], :data => opts[:data])) end end |
#to_json ⇒ Object
71 72 73 74 75 |
# File 'lib/lazy_high_charts/high_chart.rb', line 71 def to_json data = self..clone data[:series] = self.series_data.clone data end |