class ActiveCharts::BarChart
Constants
- DEFAULT_BAR_WIDTH
Attributes
bar_width[R]
bars_count[R]
max_bar_height[R]
max_values[R]
section_width[R]
x_labels[R]
x_offset[R]
y_multipliers[R]
y_offset[R]
Public Instance Methods
bars()
click to toggle source
# File lib/active_charts/bar_chart.rb, line 15 def bars whitelist = %w[width height x y class] bars_specs.flatten.map do |bar| label = formatted_val(bar[:val], bar[:formatter]) [%(<rect #{tag_options(bar.merge(width: bar_width), whitelist)} />), tag.text(label, label_options(bar))] end end
bars_specs()
click to toggle source
# File lib/active_charts/bar_chart.rb, line 26 def bars_specs collection.map.with_index do |row, row_index| row.map.with_index do |cell, col_index| height = bar_height(cell, col_index) x = bar_x(col_index, row_index) y = grid_height - height { height: height, x: x, y: y, class: bar_classes(col_index), val: cell, formatter: data_formatters[col_index] } end end end
chart_svg_tag()
click to toggle source
# File lib/active_charts/bar_chart.rb, line 8 def chart_svg_tag inner_html = [grid_rect_tag, bars, bottom_label_text_tags].flatten.join(' ') tag.svg(inner_html.html_safe, svg_options) end
Private Instance Methods
bar_classes(col)
click to toggle source
# File lib/active_charts/bar_chart.rb, line 82 def bar_classes(col) ['ac-bar-chart-bar', series_class(col)].join(' ') end
bar_height(cell, col_index)
click to toggle source
# File lib/active_charts/bar_chart.rb, line 86 def bar_height(cell, col_index) Util.safe_to_dec(cell) * y_multipliers[col_index] end
bar_x(col, row)
click to toggle source
# File lib/active_charts/bar_chart.rb, line 90 def bar_x(col, row) ((bar_width + MARGIN) * Util.grid_index(columns_count, col, row)) + (MARGIN * (row + 1)) end
compute_svg_width()
click to toggle source
# File lib/active_charts/bar_chart.rb, line 64 def compute_svg_width (bar_width * bars_count) + (rows_count * MARGIN * (1 + columns_count)) end
height_calcs(_values)
click to toggle source
# File lib/active_charts/bar_chart.rb, line 68 def height_calcs(_values) @grid_height = svg_height - label_height * 2 @max_bar_height = grid_height - label_height * 3 @y_offset = label_height / 2 @y_multipliers = max_values.map { |max| Util.multiplier(max, max_bar_height) } end
label_options(bar)
click to toggle source
# File lib/active_charts/bar_chart.rb, line 75 def label_options(bar) { x: bar[:x] + x_offset, y: bar[:y] - y_offset } end
prereq_calcs()
click to toggle source
# File lib/active_charts/bar_chart.rb, line 54 def prereq_calcs @bars_count = columns_count * rows_count end
process_options(options)
click to toggle source
Calls superclass method
# File lib/active_charts/bar_chart.rb, line 47 def process_options(options) super @bar_width = options[:bar_width] || DEFAULT_BAR_WIDTH @x_labels = options[:rows] || [] end
width_calcs(_values)
click to toggle source
# File lib/active_charts/bar_chart.rb, line 58 def width_calcs(_values) @grid_width = @svg_width = compute_svg_width @section_width = rows_count.zero? ? svg_width : svg_width / rows_count.to_d @x_offset = bar_width / 2 end