Class: Charting::Sparklines::Renderer

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :type                  => :line,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Generate jQuery sparkline based charts.

Ensure jquery-sparkine library is loaded before use, for example:

<script src="/javascripts/jquery.sparkline.js" type="text/javascript"></script>

And that you invoke somethink like:

/* Initialize sparklines */
$(document).ready(function() {
  $('.sparkline').sparkline();
});

in your document script.

Styling in CSS is required for the <span> container which has a class of ‘sparkline’

Parameters

data_source:      The active record result set
data_column:      one column name to be charted 
options:          options hash

Options

Currently no options for Sparklines.


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

def initialize(data_source, data_column, options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  @options[:container] ||= generate_container_name
  @data_column = data_column
  @chart = chart_class.new(data_source, @data_column, @options)
end

Instance Attribute Details

#chartObject

Returns the value of attribute chart.



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

def chart
  @chart
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#seriesObject

Returns the value of attribute series.



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

def series
  @series
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Convenience method for configuring the chart.

Yields:

  • (_self)

Yield Parameters:



50
51
52
# File 'lib/ar_to_chart/charting/sparklines.rb', line 50

def self.configure
  yield self
end

Instance Method Details

#to_htmlObject

Output the HTML representation of the chart



45
46
47
# File 'lib/ar_to_chart/charting/sparklines.rb', line 45

def to_html
  @chart.to_html
end