Class: AmCharts::Chart
- Inherits:
-
Object
- Object
- AmCharts::Chart
- Defined in:
- lib/amcharts/chart.rb
Direct Known Subclasses
Funnel, Gauge, Pie, Radar, Rectangular
Defined Under Namespace
Classes: Funnel, Gauge, Pie, Radar, Rectangular, Serial, XY
Instance Attribute Summary collapse
-
#container ⇒ Object
Returns the value of attribute container.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_provider ⇒ Object
Returns the value of attribute data_provider.
-
#data_source ⇒ Object
Returns the value of attribute data_source.
-
#export {|@export| ... } ⇒ Object
(also: #exportable!)
readonly
Returns the value of attribute export.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#graphs ⇒ Object
readonly
Returns the value of attribute graphs.
-
#height ⇒ Object
Returns the value of attribute height.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#legend_div ⇒ Object
readonly
Returns the value of attribute legend_div.
-
#legends ⇒ Object
readonly
Returns the value of attribute legends.
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
-
#loading_indicator ⇒ Object
Returns the value of attribute loading_indicator.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#titles ⇒ Object
readonly
Returns the value of attribute titles.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #add_label(text, x, y, options = {}) ⇒ Object
- #add_title(text, options = {}) ⇒ Object
- #amchart_type ⇒ Object
- #call_function(fn) ⇒ Object
-
#category_axis ⇒ Object
Axes are only defined for rectangular charts.
- #category_field ⇒ Object
-
#defer? ⇒ Boolean
Should remote data be loaded right away?.
- #detach_legend(div = true) ⇒ Object
- #dimensions=(dim) ⇒ Object
- #export? ⇒ Boolean
-
#initialize(*data, &block) ⇒ Chart
constructor
A new instance of Chart.
- #keys ⇒ Object
-
#loading_indicator! ⇒ Object
Show a loading indicator while the chart is rendering A listener will automatically be added to hide the indicator when the rendered event is received.
- #loading_indicator? ⇒ Boolean
- #process_data ⇒ Object
- #type ⇒ Object
- #update_settings(&block) ⇒ Object
- #value_axes ⇒ Object
Constructor Details
#initialize(*data, &block) ⇒ Chart
Returns a new instance of Chart.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/amcharts/chart.rb', line 23 def initialize(*data, &block) @data = data.flatten @data_source = DataSource.new @graphs = Collection[Graph] @legends = Collection[Legend] @listeners = Collection[Listener] @settings = Settings.new(self.class.defaults) @export = nil @titles = [] @labels = [] @functions = [] update_settings(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
Delegate unknown messages to the settings object
163 164 165 166 |
# File 'lib/amcharts/chart.rb', line 163 def method_missing(name, *args, &block) return type.send(name) if type if name.to_s.end_with?('?') @settings.send(name, *args, &block) end |
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
19 20 21 |
# File 'lib/amcharts/chart.rb', line 19 def container @container end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def data @data end |
#data_provider ⇒ Object
Returns the value of attribute data_provider.
19 20 21 |
# File 'lib/amcharts/chart.rb', line 19 def data_provider @data_provider end |
#data_source ⇒ Object
Returns the value of attribute data_source.
19 20 21 |
# File 'lib/amcharts/chart.rb', line 19 def data_source @data_source end |
#export {|@export| ... } ⇒ Object (readonly) Also known as: exportable!
Returns the value of attribute export.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def export @export end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def functions @functions end |
#graphs ⇒ Object (readonly)
Returns the value of attribute graphs.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def graphs @graphs end |
#height ⇒ Object
Returns the value of attribute height.
20 21 22 |
# File 'lib/amcharts/chart.rb', line 20 def height @height end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def labels @labels end |
#legend_div ⇒ Object (readonly)
Returns the value of attribute legend_div.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def legend_div @legend_div end |
#legends ⇒ Object (readonly)
Returns the value of attribute legends.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def legends @legends end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def listeners @listeners end |
#loading_indicator ⇒ Object
Returns the value of attribute loading_indicator.
20 21 22 |
# File 'lib/amcharts/chart.rb', line 20 def loading_indicator @loading_indicator end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def settings @settings end |
#titles ⇒ Object (readonly)
Returns the value of attribute titles.
21 22 23 |
# File 'lib/amcharts/chart.rb', line 21 def titles @titles end |
#width ⇒ Object
Returns the value of attribute width.
20 21 22 |
# File 'lib/amcharts/chart.rb', line 20 def width @width end |
Class Method Details
.amchart_type ⇒ Object
81 82 83 |
# File 'lib/amcharts/chart.rb', line 81 def self.amchart_type "AmCharts.Am#{type.to_s.titleize}Chart()" end |
.clear_defaults ⇒ Object
49 50 51 |
# File 'lib/amcharts/chart.rb', line 49 def clear_defaults self.default_settings = nil end |
.defaults(&block) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/amcharts/chart.rb', line 39 def defaults(&block) if block_given? self.default_settings ||= Settings.new instance_exec(self.default_settings, &block) else return {} if self.default_settings.blank? self.default_settings.to_h.symbolize_keys end end |
.type ⇒ Object
77 78 79 |
# File 'lib/amcharts/chart.rb', line 77 def self.type ActiveSupport::StringInquirer.new(self.name.demodulize.downcase) end |
Instance Method Details
#add_label(text, x, y, options = {}) ⇒ Object
100 101 102 |
# File 'lib/amcharts/chart.rb', line 100 def add_label(text, x, y, = {}) @labels << [text, x, y, .reverse_merge(size: 11, align: 'left', color: '#000', rotation: 0, alpha: 1, bold: false)] end |
#add_title(text, options = {}) ⇒ Object
96 97 98 |
# File 'lib/amcharts/chart.rb', line 96 def add_title(text, = {}) @titles << [text, .reverse_merge(size: 13, bold: true, alpha: 1, color: '#000')] end |
#amchart_type ⇒ Object
139 140 141 |
# File 'lib/amcharts/chart.rb', line 139 def amchart_type self.class.amchart_type end |
#call_function(fn) ⇒ Object
152 153 154 |
# File 'lib/amcharts/chart.rb', line 152 def call_function(fn) @functions << fn end |
#category_axis ⇒ Object
Axes are only defined for rectangular charts
144 145 146 |
# File 'lib/amcharts/chart.rb', line 144 def category_axis nil end |
#category_field ⇒ Object
69 70 71 |
# File 'lib/amcharts/chart.rb', line 69 def category_field @category_field || AmCharts::ChartBuilder::Function.new('new AmCharts.RB.Chart(chart).category_field()') end |
#defer? ⇒ Boolean
Should remote data be loaded right away?
65 66 67 |
# File 'lib/amcharts/chart.rb', line 65 def defer? @data_source.fetch(:defer, false) end |
#detach_legend(div = true) ⇒ Object
127 128 129 |
# File 'lib/amcharts/chart.rb', line 127 def detach_legend(div = true) @legend_div = div end |
#dimensions=(dim) ⇒ Object
112 113 114 |
# File 'lib/amcharts/chart.rb', line 112 def dimensions=(dim) @width, @height = dim.split("x").map(&:to_i) end |
#export? ⇒ Boolean
85 86 87 |
# File 'lib/amcharts/chart.rb', line 85 def export? !@export.nil? end |
#keys ⇒ Object
73 74 75 |
# File 'lib/amcharts/chart.rb', line 73 def keys data.first.keys end |
#loading_indicator! ⇒ Object
Show a loading indicator while the chart is rendering A listener will automatically be added to hide the indicator when the rendered event is received
119 120 121 |
# File 'lib/amcharts/chart.rb', line 119 def loading_indicator! @loading_indicator = true end |
#loading_indicator? ⇒ Boolean
123 124 125 |
# File 'lib/amcharts/chart.rb', line 123 def loading_indicator? self.loading_indicator end |
#process_data ⇒ Object
131 132 133 |
# File 'lib/amcharts/chart.rb', line 131 def process_data data.each.with_index { |row, index| yield row, index } end |
#type ⇒ Object
135 136 137 |
# File 'lib/amcharts/chart.rb', line 135 def type self.class.type end |
#update_settings(&block) ⇒ Object
54 55 56 57 |
# File 'lib/amcharts/chart.rb', line 54 def update_settings(&block) instance_exec(self, &block) self end |
#value_axes ⇒ Object
148 149 150 |
# File 'lib/amcharts/chart.rb', line 148 def value_axes [] end |