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.
-
#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
-
#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.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/amcharts/chart.rb', line 20 def initialize(*data, &block) @data = data.flatten @data_source = DataSource.new @graphs = Collection[Graph] @legends = Collection[Legend] @listeners = Collection[Listener] @settings = Settings.new @export = nil @titles = [] @labels = [] 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
138 139 140 141 |
# File 'lib/amcharts/chart.rb', line 138 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.
16 17 18 |
# File 'lib/amcharts/chart.rb', line 16 def container @container end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def data @data end |
#data_provider ⇒ Object
Returns the value of attribute data_provider.
16 17 18 |
# File 'lib/amcharts/chart.rb', line 16 def data_provider @data_provider end |
#data_source ⇒ Object
Returns the value of attribute data_source.
16 17 18 |
# File 'lib/amcharts/chart.rb', line 16 def data_source @data_source end |
#export {|@export| ... } ⇒ Object (readonly) Also known as: exportable!
Returns the value of attribute export.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def export @export end |
#graphs ⇒ Object (readonly)
Returns the value of attribute graphs.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def graphs @graphs end |
#height ⇒ Object
Returns the value of attribute height.
17 18 19 |
# File 'lib/amcharts/chart.rb', line 17 def height @height end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def labels @labels end |
#legend_div ⇒ Object (readonly)
Returns the value of attribute legend_div.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def legend_div @legend_div end |
#legends ⇒ Object (readonly)
Returns the value of attribute legends.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def legends @legends end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def listeners @listeners end |
#loading_indicator ⇒ Object
Returns the value of attribute loading_indicator.
17 18 19 |
# File 'lib/amcharts/chart.rb', line 17 def loading_indicator @loading_indicator end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def settings @settings end |
#titles ⇒ Object (readonly)
Returns the value of attribute titles.
18 19 20 |
# File 'lib/amcharts/chart.rb', line 18 def titles @titles end |
#width ⇒ Object
Returns the value of attribute width.
17 18 19 |
# File 'lib/amcharts/chart.rb', line 17 def width @width end |
Class Method Details
.amchart_type ⇒ Object
60 61 62 |
# File 'lib/amcharts/chart.rb', line 60 def self.amchart_type "AmCharts.Am#{type.to_s.titleize}Chart()" end |
.type ⇒ Object
56 57 58 |
# File 'lib/amcharts/chart.rb', line 56 def self.type ActiveSupport::StringInquirer.new(self.name.demodulize.downcase) end |
Instance Method Details
#add_label(text, x, y, options = {}) ⇒ Object
79 80 81 |
# File 'lib/amcharts/chart.rb', line 79 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
75 76 77 |
# File 'lib/amcharts/chart.rb', line 75 def add_title(text, = {}) @titles << [text, .reverse_merge(size: 13, bold: true, alpha: 1, color: '#000')] end |
#amchart_type ⇒ Object
118 119 120 |
# File 'lib/amcharts/chart.rb', line 118 def amchart_type self.class.amchart_type end |
#category_axis ⇒ Object
Axes are only defined for rectangular charts
123 124 125 |
# File 'lib/amcharts/chart.rb', line 123 def category_axis nil end |
#category_field ⇒ Object
48 49 50 |
# File 'lib/amcharts/chart.rb', line 48 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?
44 45 46 |
# File 'lib/amcharts/chart.rb', line 44 def defer? @data_source.fetch(:defer, false) end |
#detach_legend(div = true) ⇒ Object
106 107 108 |
# File 'lib/amcharts/chart.rb', line 106 def detach_legend(div = true) @legend_div = div end |
#dimensions=(dim) ⇒ Object
91 92 93 |
# File 'lib/amcharts/chart.rb', line 91 def dimensions=(dim) @width, @height = dim.split("x").map(&:to_i) end |
#export? ⇒ Boolean
64 65 66 |
# File 'lib/amcharts/chart.rb', line 64 def export? !@export.nil? end |
#keys ⇒ Object
52 53 54 |
# File 'lib/amcharts/chart.rb', line 52 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
98 99 100 |
# File 'lib/amcharts/chart.rb', line 98 def loading_indicator! @loading_indicator = true end |
#loading_indicator? ⇒ Boolean
102 103 104 |
# File 'lib/amcharts/chart.rb', line 102 def loading_indicator? self.loading_indicator end |
#process_data ⇒ Object
110 111 112 |
# File 'lib/amcharts/chart.rb', line 110 def process_data data.each.with_index { |row, index| yield row, index } end |
#type ⇒ Object
114 115 116 |
# File 'lib/amcharts/chart.rb', line 114 def type self.class.type end |
#update_settings(&block) ⇒ Object
33 34 35 36 |
# File 'lib/amcharts/chart.rb', line 33 def update_settings(&block) instance_exec(self, &block) self end |
#value_axes ⇒ Object
127 128 129 |
# File 'lib/amcharts/chart.rb', line 127 def value_axes [] end |