class AmCharts::Chart

Attributes

container[RW]
data[R]
data_provider[RW]
data_source[RW]
export[R]
exportable![R]
functions[R]
graphs[R]
height[RW]
labels[R]
legend_div[R]
legends[R]
listeners[R]
loading_indicator[RW]
settings[R]
titles[R]
width[RW]

Public Class Methods

amchart_type() click to toggle source
# File lib/amcharts/chart.rb, line 81
def self.amchart_type
  "AmCharts.Am#{type.to_s.titleize}Chart()"
end
clear_defaults() click to toggle source
# File lib/amcharts/chart.rb, line 49
def clear_defaults
  self.default_settings = nil
end
defaults(&block) click to toggle source
# 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
new(*data, &block) click to toggle source
# 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
type() click to toggle source
# File lib/amcharts/chart.rb, line 77
def self.type
  ActiveSupport::StringInquirer.new(self.name.demodulize.downcase)
end

Public Instance Methods

add_label(text, x, y, options = {}) click to toggle source
# File lib/amcharts/chart.rb, line 100
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 = {}) click to toggle source
# File lib/amcharts/chart.rb, line 96
def add_title(text, options = {})
  @titles << [text, options.reverse_merge(size: 13, bold: true, alpha: 1, color: '#000')]
end
amchart_type() click to toggle source
# File lib/amcharts/chart.rb, line 139
def amchart_type
  self.class.amchart_type
end
call_function(fn) click to toggle source
# File lib/amcharts/chart.rb, line 152
def call_function(fn)
  @functions << fn
end
category_axis() click to toggle source

Axes are only defined for rectangular charts

# File lib/amcharts/chart.rb, line 144
def category_axis
  nil
end
category_field() click to toggle source
# File lib/amcharts/chart.rb, line 69
def category_field
  @category_field || AmCharts::ChartBuilder::Function.new('new AmCharts.RB.Chart(chart).category_field()')
end
data_source=(source) click to toggle source

Allow data to be loaded from a remote source

# File lib/amcharts/chart.rb, line 60
def data_source=(source)
  @data_source = DataSource.new(source)
end
defer?() click to toggle source

Should remote data be loaded right away?

# File lib/amcharts/chart.rb, line 65
def defer?
  @data_source.fetch(:defer, false)
end
detach_legend(div = true) click to toggle source
# File lib/amcharts/chart.rb, line 127
def detach_legend(div = true)
  @legend_div = div
end
dimensions=(dim) click to toggle source
# File lib/amcharts/chart.rb, line 112
def dimensions=(dim)
  @width, @height = dim.split("x").map(&:to_i)
end
export?() click to toggle source
# File lib/amcharts/chart.rb, line 85
def export?
  !@export.nil?
end
height=(h) click to toggle source
# File lib/amcharts/chart.rb, line 108
def height=(h)
  @height = get_dimension_value(h)
end
keys() click to toggle source
# File lib/amcharts/chart.rb, line 73
def keys
  data.first.keys
end
loading_indicator!() click to toggle source

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

# File lib/amcharts/chart.rb, line 119
def loading_indicator!
  @loading_indicator = true
end
loading_indicator?() click to toggle source
# File lib/amcharts/chart.rb, line 123
def loading_indicator?
  self.loading_indicator
end
process_data() { |row, index| ... } click to toggle source
# File lib/amcharts/chart.rb, line 131
def process_data
  data.each.with_index { |row, index| yield row, index }
end
type() click to toggle source
# File lib/amcharts/chart.rb, line 135
def type
  self.class.type
end
update_settings(&block) click to toggle source
# File lib/amcharts/chart.rb, line 54
def update_settings(&block)
  instance_exec(self, &block)
  self
end
value_axes() click to toggle source
# File lib/amcharts/chart.rb, line 148
def value_axes
  []
end
width=(w) click to toggle source
# File lib/amcharts/chart.rb, line 104
def width=(w)
  @width = get_dimension_value(w)
end

Private Instance Methods

get_dimension_value(value) click to toggle source
# File lib/amcharts/chart.rb, line 158
def get_dimension_value(value)
  value.respond_to?(:call) ? value.call(data) : value
end
method_missing(name, *args, &block) click to toggle source

Delegate unknown messages to the settings object

# 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