Class: HighChart
- Inherits:
-
Object
- Object
- HighChart
- Defined in:
- lib/high_chart.rb
Instance Attribute Summary collapse
-
#chart ⇒ Object
Returns the value of attribute chart.
-
#chart_div ⇒ Object
Returns the value of attribute chart_div.
-
#chart_type ⇒ Object
Returns the value of attribute chart_type.
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#credits ⇒ Object
Returns the value of attribute credits.
-
#global ⇒ Object
Returns the value of attribute global.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#legend ⇒ Object
Returns the value of attribute legend.
-
#loading ⇒ Object
Returns the value of attribute loading.
-
#plot_options ⇒ Object
Returns the value of attribute plot_options.
-
#point ⇒ Object
Returns the value of attribute point.
-
#series ⇒ Object
Returns the value of attribute series.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#symbols ⇒ Object
Returns the value of attribute symbols.
-
#title ⇒ Object
Returns the value of attribute title.
-
#toolbar ⇒ Object
Returns the value of attribute toolbar.
-
#tooltip ⇒ Object
Returns the value of attribute tooltip.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x_axis ⇒ Object
Returns the value of attribute x_axis.
-
#x_axis_labels ⇒ Object
Returns the value of attribute x_axis_labels.
-
#y_axis ⇒ Object
Returns the value of attribute y_axis.
Instance Method Summary collapse
-
#initialize(series, options = {}) ⇒ HighChart
constructor
A new instance of HighChart.
- #merge_defaults(key, value) ⇒ Object
-
#read_defaults(config_file) ⇒ Object
read a yaml file of defaults and write out the options.
- #to_json ⇒ Object
Constructor Details
#initialize(series, options = {}) ⇒ HighChart
Returns a new instance of HighChart.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/high_chart.rb', line 10 def initialize(series, ={}) unless series.kind_of?(Array) raise HighChartError, "series must be an Array" end if [:x_axis_labels] == nil raise HighChartError, "X-Axis labels are required" end if [:colors] != nil && ![:colors].kind_of?(Array) raise HighChartError, "Colors must be an Array" end if [:config_file] read_defaults([:config_file]) end .each do |k, v| if self.respond_to?(k.to_sym) merged_value = merge_defaults(k, v) self.instance_variable_set(("@#{k.to_s}").to_sym, merged_value) end end @series = series end |
Instance Attribute Details
#chart ⇒ Object
Returns the value of attribute chart.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def chart @chart end |
#chart_div ⇒ Object
Returns the value of attribute chart_div.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def chart_div @chart_div end |
#chart_type ⇒ Object
Returns the value of attribute chart_type.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def chart_type @chart_type end |
#colors ⇒ Object
Returns the value of attribute colors.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def colors @colors end |
#credits ⇒ Object
Returns the value of attribute credits.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def credits @credits end |
#global ⇒ Object
Returns the value of attribute global.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def global @global end |
#labels ⇒ Object
Returns the value of attribute labels.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def labels @labels end |
#lang ⇒ Object
Returns the value of attribute lang.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def lang @lang end |
#legend ⇒ Object
Returns the value of attribute legend.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def legend @legend end |
#loading ⇒ Object
Returns the value of attribute loading.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def loading @loading end |
#plot_options ⇒ Object
Returns the value of attribute plot_options.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def @plot_options end |
#point ⇒ Object
Returns the value of attribute point.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def point @point end |
#series ⇒ Object
Returns the value of attribute series.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def series @series end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def subtitle @subtitle end |
#symbols ⇒ Object
Returns the value of attribute symbols.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def symbols @symbols end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def title @title end |
#toolbar ⇒ Object
Returns the value of attribute toolbar.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def @toolbar end |
#tooltip ⇒ Object
Returns the value of attribute tooltip.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def tooltip @tooltip end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def width @width end |
#x_axis ⇒ Object
Returns the value of attribute x_axis.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def x_axis @x_axis end |
#x_axis_labels ⇒ Object
Returns the value of attribute x_axis_labels.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def x_axis_labels @x_axis_labels end |
#y_axis ⇒ Object
Returns the value of attribute y_axis.
6 7 8 |
# File 'lib/high_chart.rb', line 6 def y_axis @y_axis end |
Instance Method Details
#merge_defaults(key, value) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/high_chart.rb', line 37 def merge_defaults(key, value) default_value = self.send(key.to_s.to_sym) if default_value.kind_of?(Hash) && value.kind_of?(Hash) default_value.stringify_keys!.merge!(value.stringify_keys!) else default_value = value end return default_value end |
#read_defaults(config_file) ⇒ Object
read a yaml file of defaults and write out the options
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/high_chart.rb', line 49 def read_defaults(config_file) begin defaults = YAML.load_file(config_file) unless defaults == false defaults.each do |k, v| if self.respond_to?(k.to_sym) self.instance_variable_set(("@" + k.to_s).to_sym, v) end end end rescue Exception => e puts e. puts e.backtrace raise e end end |
#to_json ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/high_chart.rb', line 104 def to_json json_hash = { :chart => chart, :colors => colors, :credits => credits, :global => global, :labels => labels, :lang => lang, :legend => legend, :loading => loading, :plotOptions => , :point => point, :subtitle => subtitle, :symbols => symbols, :title => title, :toolbar => , :tooltip => tooltip, :xAxis => x_axis, :yAxis => y_axis, :series => series, :width => width } clean_json_hash = json_hash.reject do |key, value| value == nil end return clean_json_hash.to_json end |