Class: ActiveCharts::Chart

Inherits:
Object
  • Object
show all
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

RectangularChart

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

Instance Method Summary collapse

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, options = {})
  @collection = Util.array_of_arrays?(collection) ? collection : [[]]
  @rows_count = @collection.count
  @columns_count = @collection.map(&:count).max
  process_options(options)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



26
27
28
# File 'lib/active_charts/chart.rb', line 26

def collection
  @collection
end

#columns_countObject (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_formattersObject (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_classesObject (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_heightObject (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_valuesObject (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_countObject (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_labelsObject (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

#titleObject (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_tagObject



36
# File 'lib/active_charts/chart.rb', line 36

def chart_svg_tag; end

#legend_list_tagObject



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_htmlObject



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