Class: Charting::Sparklines::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_to_chart/charting/sparklines/base.rb

Direct Known Subclasses

Line

Constant Summary collapse

DEFAULT_OPTIONS =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_source, data_column, options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 8

def initialize(data_source, data_column, options = {})
  @data_source      = data_source
  @data_column      = data_column
  @options          = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#data_columnObject (readonly)

Returns the value of attribute data_column.



4
5
6
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 4

def data_column
  @data_column
end

#data_sourceObject (readonly)

Returns the value of attribute data_source.



4
5
6
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 4

def data_source
  @data_source
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 4

def options
  @options
end

Instance Method Details

#chart_optionsObject

No options currently defined



15
16
17
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 15

def chart_options
  {}
end

#chart_typeObject

The chart type (derived from the class name)



30
31
32
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 30

def chart_type
  @chart_type ||= self.class.name.split('::').last.downcase
end

#seriesObject

Define in concrete subclass



20
21
22
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 20

def series
  []
end

#series_nameObject

The name of a data series



25
26
27
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 25

def series_name
  data_source.first.class.human_attribute_name(data_column)
end

#to_htmlObject

Render the chart HTML. Requires jQuery and jQuery sparklines plugin



35
36
37
38
39
40
41
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 35

def to_html
  <<-EOF
    <span id="#{container_id}" class="#{chart_css_class}">
      #{series.join(',')}
    </span>
  EOF
end