Class: Charting::Sparklines::Base
- Inherits:
-
Object
- Object
- Charting::Sparklines::Base
- Defined in:
- lib/ar_to_chart/charting/sparklines/base.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
{}
Instance Attribute Summary collapse
-
#data_column ⇒ Object
readonly
Returns the value of attribute data_column.
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#chart_options ⇒ Object
No options currently defined.
-
#chart_type ⇒ Object
The chart type (derived from the class name).
-
#initialize(data_source, data_column, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#series ⇒ Object
Define in concrete subclass.
-
#series_name ⇒ Object
The name of a data series.
-
#to_html ⇒ Object
Render the chart HTML.
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, = {}) @data_source = data_source @data_column = data_column @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#data_column ⇒ Object (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_source ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 4 def @options end |
Instance Method Details
#chart_options ⇒ Object
No options currently defined
15 16 17 |
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 15 def {} end |
#chart_type ⇒ Object
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 |
#series ⇒ Object
Define in concrete subclass
20 21 22 |
# File 'lib/ar_to_chart/charting/sparklines/base.rb', line 20 def series [] end |
#series_name ⇒ Object
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_html ⇒ Object
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 |