Class: RCharts::GraphHelper::Categories::CategoryBuilder

Inherits:
ElementBuilder
  • Object
show all
Defined in:
app/helpers/rcharts/graph_helper/categories/category_builder.rb

Overview

Category Builder

Instance Method Summary collapse

Methods inherited from ElementBuilder

#render_in

Instance Method Details

#barObject

Shortcut to render a bar for every series. Useful when you don’t need to differentiate between different series. Arguments and options are passed to #series, see there for more details.



23
24
25
# File 'app/helpers/rcharts/graph_helper/categories/category_builder.rb', line 23

def bar(*, **)
  series(*, **, &:bar)
end

#indexObject

:attr_accessor: index



14
# File 'app/helpers/rcharts/graph_helper/categories/category_builder.rb', line 14

attribute :index, :integer, default: 0

#nameObject

:attr_accessor:



10
# File 'app/helpers/rcharts/graph_helper/categories/category_builder.rb', line 10

attribute :name

#series(*names, axis: nil, inline_axis: nil) ⇒ Object

Renders one or more series present in the data. For each series yields a BarBuilder which contains the series:

<%= graph_for @annual_sales do |graph| %>
  <%= graph.category do |category| %>
    <%= category.series do |series| %>
      <%= series.bar %>
    <% end %>
  <% end %>
<% end %>

The default is to iterate over all series, but you can specify a subset by passing the series names as arguments.

Options

:axis

The axis for the series. Defaults to the first continuous axis.

:inline_axis

The axis for the categories. Defaults to the first discrete axis.



42
43
44
45
46
47
48
# File 'app/helpers/rcharts/graph_helper/categories/category_builder.rb', line 42

def series(*names, axis: nil, inline_axis: nil, **, &)
  bars_tag(axis: inline_axis) do
    filtered_series(*names).each_with_index do |(name, value), index|
      concat bar_for(name, value, index, filtered_series(*names)&.count, axis:, **, &)
    end
  end
end