Class: Tiler::Widgets::BarChartQuery
- Inherits:
-
Query::Base
- Object
- Query::Base
- Tiler::Widgets::BarChartQuery
- Defined in:
- lib/tiler/widgets/bar_chart.rb
Constant Summary collapse
- DEFAULT_LIMIT =
10
Constants inherited from Query::Base
Instance Attribute Summary
Attributes inherited from Query::Base
Instance Method Summary collapse
Methods inherited from Query::Base
Constructor Details
This class inherits a constructor from Tiler::Query::Base
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tiler/widgets/bar_chart.rb', line 9 def call group_col = config["group_column"] val_col = config["value_column"] agg = config["aggregation"] || "sum" limit = (config["limit"] || DEFAULT_LIMIT).to_i.clamp(1, 50) return { labels: [], datasets: [], options: {} } if group_col.blank? groups = distinct_values(group_col).first(limit) data = groups.map { |g| aggregate_for_group(group_col, g, val_col, agg) } # Per catalog: bars use the full viz palette in registration order. colors = groups.each_index.map { |i| chart_colors[i % chart_colors.size] } { labels: groups, datasets: [ { label: (val_col || agg).to_s.humanize, data: data, backgroundColor: colors.map { |c| "#{c}cc" }, borderColor: colors, borderWidth: 1 } ], options: {} } end |