Class: ActiveCharts::BarChart
- Inherits:
-
RectangularChart
- Object
- Chart
- RectangularChart
- ActiveCharts::BarChart
- Defined in:
- lib/active_charts/bar_chart.rb
Constant Summary collapse
- DEFAULT_BAR_WIDTH =
40
Constants inherited from RectangularChart
RectangularChart::TOP_LEFT_OFFSET
Constants inherited from Chart
Chart::CSS_CLASSES, Chart::MARGIN
Instance Attribute Summary collapse
-
#bar_width ⇒ Object
readonly
Returns the value of attribute bar_width.
-
#bars_count ⇒ Object
readonly
Returns the value of attribute bars_count.
-
#max_bar_height ⇒ Object
readonly
Returns the value of attribute max_bar_height.
-
#max_values ⇒ Object
readonly
Returns the value of attribute max_values.
-
#section_width ⇒ Object
readonly
Returns the value of attribute section_width.
-
#x_labels ⇒ Object
readonly
Returns the value of attribute x_labels.
-
#x_offset ⇒ Object
readonly
Returns the value of attribute x_offset.
-
#y_multipliers ⇒ Object
readonly
Returns the value of attribute y_multipliers.
-
#y_offset ⇒ Object
readonly
Returns the value of attribute y_offset.
Attributes inherited from RectangularChart
#grid_height, #grid_width, #svg_height, #svg_width
Attributes inherited from Chart
#collection, #columns_count, #data_formatters, #extra_css_classes, #label_height, #rows_count, #series_labels, #title
Instance Method Summary collapse
Methods inherited from RectangularChart
Methods inherited from Chart
#initialize, #legend_list_tag, #to_html
Constructor Details
This class inherits a constructor from ActiveCharts::RectangularChart
Instance Attribute Details
#bar_width ⇒ Object (readonly)
Returns the value of attribute bar_width.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def @bar_width end |
#bars_count ⇒ Object (readonly)
Returns the value of attribute bars_count.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def @bars_count end |
#max_bar_height ⇒ Object (readonly)
Returns the value of attribute max_bar_height.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def @max_bar_height end |
#max_values ⇒ Object (readonly)
Returns the value of attribute max_values.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def max_values @max_values end |
#section_width ⇒ Object (readonly)
Returns the value of attribute section_width.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def section_width @section_width end |
#x_labels ⇒ Object (readonly)
Returns the value of attribute x_labels.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def x_labels @x_labels end |
#x_offset ⇒ Object (readonly)
Returns the value of attribute x_offset.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def x_offset @x_offset end |
#y_multipliers ⇒ Object (readonly)
Returns the value of attribute y_multipliers.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def y_multipliers @y_multipliers end |
#y_offset ⇒ Object (readonly)
Returns the value of attribute y_offset.
5 6 7 |
# File 'lib/active_charts/bar_chart.rb', line 5 def y_offset @y_offset end |
Instance Method Details
#bars ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_charts/bar_chart.rb', line 15 def whitelist = %w[width height x y class] .flatten.map do || label = formatted_val([:val], [:formatter]) [%(<rect #{(.merge(width: ), whitelist)} />), tag.text(label, ())] end end |
#bars_specs ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_charts/bar_chart.rb', line 26 def collection.map.with_index do |row, row_index| row.map.with_index do |cell, col_index| height = (cell, col_index) x = (col_index, row_index) y = grid_height - height { height: height, x: x, y: y, class: (col_index), val: cell, formatter: data_formatters[col_index] } end end end |
#bottom_label_text_tags ⇒ Object
39 40 41 42 43 |
# File 'lib/active_charts/bar_chart.rb', line 39 def x_labels.map.with_index do |label, index| tag.text(label, x: section_width * (index + 0.5), y: grid_height + label_height * 1.5) end.join end |
#chart_svg_tag ⇒ Object
8 9 10 11 12 13 |
# File 'lib/active_charts/bar_chart.rb', line 8 def chart_svg_tag inner_html = [grid_rect_tag, , ].flatten.join(' ') tag.svg(inner_html.html_safe, ) end |