Class: AmCharts::Chart

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#containerObject

Returns the value of attribute container.



16
17
18
# File 'lib/amcharts/chart.rb', line 16

def container
  @container
end

#dataObject (readonly)

Returns the value of attribute data.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def data
  @data
end

#data_providerObject

Returns the value of attribute data_provider.



16
17
18
# File 'lib/amcharts/chart.rb', line 16

def data_provider
  @data_provider
end

#data_sourceObject

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.

Yields:



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def export
  @export
end

#graphsObject (readonly)

Returns the value of attribute graphs.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def graphs
  @graphs
end

#heightObject

Returns the value of attribute height.



17
18
19
# File 'lib/amcharts/chart.rb', line 17

def height
  @height
end

#labelsObject (readonly)

Returns the value of attribute labels.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def labels
  @labels
end

#legend_divObject (readonly)

Returns the value of attribute legend_div.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def legend_div
  @legend_div
end

#legendsObject (readonly)

Returns the value of attribute legends.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def legends
  @legends
end

#listenersObject (readonly)

Returns the value of attribute listeners.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def listeners
  @listeners
end

#loading_indicatorObject

Returns the value of attribute loading_indicator.



17
18
19
# File 'lib/amcharts/chart.rb', line 17

def loading_indicator
  @loading_indicator
end

#settingsObject (readonly)

Returns the value of attribute settings.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def settings
  @settings
end

#titlesObject (readonly)

Returns the value of attribute titles.



18
19
20
# File 'lib/amcharts/chart.rb', line 18

def titles
  @titles
end

#widthObject

Returns the value of attribute width.



17
18
19
# File 'lib/amcharts/chart.rb', line 17

def width
  @width
end

Class Method Details

.amchart_typeObject



60
61
62
# File 'lib/amcharts/chart.rb', line 60

def self.amchart_type
  "AmCharts.Am#{type.to_s.titleize}Chart()"
end

.typeObject



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, options = {})
  @labels << [text, x, y, options.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, options = {})
  @titles << [text, options.reverse_merge(size: 13, bold: true, alpha: 1, color: '#000')]
end

#amchart_typeObject



118
119
120
# File 'lib/amcharts/chart.rb', line 118

def amchart_type
  self.class.amchart_type
end

#category_axisObject

Axes are only defined for rectangular charts



123
124
125
# File 'lib/amcharts/chart.rb', line 123

def category_axis
  nil
end

#category_fieldObject



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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


64
65
66
# File 'lib/amcharts/chart.rb', line 64

def export?
  !@export.nil?
end

#keysObject



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

Returns:

  • (Boolean)


102
103
104
# File 'lib/amcharts/chart.rb', line 102

def loading_indicator?
  self.loading_indicator
end

#process_dataObject



110
111
112
# File 'lib/amcharts/chart.rb', line 110

def process_data
  data.each.with_index { |row, index| yield row, index }
end

#typeObject



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_axesObject



127
128
129
# File 'lib/amcharts/chart.rb', line 127

def value_axes
  []
end