Class: ActiveCharts::Chart
- Inherits:
-
Object
- Object
- ActiveCharts::Chart
- Includes:
- ActionView::Helpers::CaptureHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper, ActiveSupport::Inflector
- Defined in:
- lib/active_charts/chart.rb
Direct Known Subclasses
Constant Summary collapse
- MARGIN =
20- CSS_CLASSES =
%w[a b c d e f g h i j k l m n o].map { |letter| 'series-' + letter }.freeze
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#columns_count ⇒ Object
readonly
Returns the value of attribute columns_count.
-
#data_formatters ⇒ Object
readonly
Returns the value of attribute data_formatters.
-
#extra_css_classes ⇒ Object
readonly
Returns the value of attribute extra_css_classes.
-
#label_height ⇒ Object
readonly
Returns the value of attribute label_height.
-
#max_values ⇒ Object
readonly
Returns the value of attribute max_values.
-
#rows_count ⇒ Object
readonly
Returns the value of attribute rows_count.
-
#series_labels ⇒ Object
readonly
Returns the value of attribute series_labels.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #chart_svg_tag ⇒ Object
-
#initialize(collection, options = {}) ⇒ Chart
constructor
A new instance of Chart.
- #legend_list_tag ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(collection, options = {}) ⇒ Chart
Returns a new instance of Chart.
19 20 21 22 23 24 |
# File 'lib/active_charts/chart.rb', line 19 def initialize(collection, = {}) @collection = Util.array_of_arrays?(collection) ? collection : [[]] @rows_count = @collection.count @columns_count = @collection.map(&:count).max () end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def collection @collection end |
#columns_count ⇒ Object (readonly)
Returns the value of attribute columns_count.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def columns_count @columns_count end |
#data_formatters ⇒ Object (readonly)
Returns the value of attribute data_formatters.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def data_formatters @data_formatters end |
#extra_css_classes ⇒ Object (readonly)
Returns the value of attribute extra_css_classes.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def extra_css_classes @extra_css_classes end |
#label_height ⇒ Object (readonly)
Returns the value of attribute label_height.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def label_height @label_height end |
#max_values ⇒ Object (readonly)
Returns the value of attribute max_values.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def max_values @max_values end |
#rows_count ⇒ Object (readonly)
Returns the value of attribute rows_count.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def rows_count @rows_count end |
#series_labels ⇒ Object (readonly)
Returns the value of attribute series_labels.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def series_labels @series_labels end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
26 27 28 |
# File 'lib/active_charts/chart.rb', line 26 def title @title end |
Instance Method Details
#chart_svg_tag ⇒ Object
36 |
# File 'lib/active_charts/chart.rb', line 36 def chart_svg_tag; end |
#legend_list_tag ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/active_charts/chart.rb', line 38 def legend_list_tag list_items = series_labels.map.with_index do |label, index| tag.li(label, class: series_class(index)) end tag.ul(list_items.join.html_safe, class: 'ac-chart ac-series-legend') end |
#to_html ⇒ Object
29 30 31 32 33 34 |
# File 'lib/active_charts/chart.rb', line 29 def to_html inner_html = [tag.figcaption(title, class: 'ac-chart-title'), chart_svg_tag, legend_list_tag].join(' ') tag.figure(inner_html.html_safe, class: container_classes) end |