-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Devops Report: Grouped + Stacked bar chart (#572)
- Simpler datastructures - Cache reports
- Loading branch information
Showing
15 changed files
with
338 additions
and
322 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,122 @@ | ||
class ChartComponent < ViewComponent::Base | ||
include AssetsHelper | ||
using RefinedHash | ||
CHART_TYPES = %w[area line donut stacked-bar] | ||
InvalidChartType = Class.new(StandardError) | ||
|
||
def initialize(chart) | ||
def initialize(chart, icon:) | ||
@chart = chart | ||
@icon = icon | ||
raise InvalidChartType unless chart[:type].in?(CHART_TYPES) | ||
end | ||
|
||
attr_reader :chart | ||
|
||
def area? | ||
type == "area" | ||
def type | ||
@type ||= chart[:type] | ||
end | ||
|
||
def line? | ||
type == "line" | ||
def value_format | ||
chart[:value_format] | ||
end | ||
|
||
def stacked_bar? | ||
type == "stacked-bar" | ||
def series | ||
ungroup_series.to_json | ||
end | ||
|
||
def type | ||
@type ||= chart[:type] | ||
def series_raw | ||
chart[:data] | ||
end | ||
|
||
def legends | ||
chart[:legends].to_json | ||
def title | ||
I18n.t("charts.#{chart[:name]}.title") | ||
end | ||
|
||
def series | ||
chart[:series].to_json | ||
def chart_scope | ||
I18n.t("charts.#{chart[:name]}.scope") | ||
end | ||
|
||
def categories | ||
chart[:x_axis].to_json | ||
def help_text | ||
I18n.t("charts.#{chart[:name]}.help_text") | ||
end | ||
|
||
def value_format | ||
chart[:value_format] | ||
def corner_icon | ||
inline_svg(@icon, classname: "w-6 fill-current shrink-0") | ||
end | ||
|
||
def title | ||
I18n.t("charts.#{chart[:name]}.title") | ||
def help_icon | ||
inline_svg("question_mark.svg", classname: "w-4 inline-flex fill-current shrink-0 text-gray-400") | ||
end | ||
|
||
def chart_scope | ||
I18n.t("charts.#{chart[:name]}.scope") | ||
def subgroup? = chart[:subgroup] | ||
|
||
def stacked? = chart[:stacked] | ||
|
||
def line? = chart[:type] == "line" | ||
|
||
def area? = chart[:type] == "area" | ||
|
||
def donut? = chart[:type] == "donut" | ||
|
||
def stacked_bar? = chart[:type] == "stacked-bar" | ||
|
||
# {"8.0.2"=>{"android"=>1, "ios"=>0}} | ||
# Input: | ||
# { | ||
# "8.0.1": { | ||
# "android": { | ||
# "QA Android Review": 2, | ||
# "Android Release": 4 | ||
# }, | ||
# "ios": { | ||
# "QA iOS Review": 6, | ||
# "iOS Release": 8 | ||
# } | ||
# }, | ||
# "8.0.2": { | ||
# "android": { | ||
# "QA Android Review": 3, | ||
# "Android Release": 5 | ||
# }, | ||
# "ios": { | ||
# "QA iOS Review": 7, | ||
# "iOS Release": 9 | ||
# } | ||
# } | ||
# } | ||
# | ||
# Output: | ||
# [{:name=>"QA Android Review", :group=>"android", :data=>{"8.0.1"=>2, "8.0.2"=>3}}, | ||
# {:name=>"Android Release", :group=>"android", :data=>{"8.0.1"=>4, "8.0.2"=>5}}, | ||
# {:name=>"QA iOS Review", :group=>"ios", :data=>{"8.0.1"=>6, "8.0.2"=>7}}, | ||
# {:name=>"iOS Release", :group=>"ios", :data=>{"8.0.1"=>8, "8.0.2"=>9}}] | ||
def ungroup_series(input = series_raw) | ||
input.each_with_object([]) do |(category, grouped_maps), result| | ||
grouped_maps.each do |group, inner_data| | ||
if inner_data.is_a?(Hash) && stacked? | ||
inner_data.each do |name, value| | ||
item = result.find { |r| r[:name] == name && r[:group] == group } | ||
item ||= {name: name, group: group, data: {}} | ||
item[:data][category] = value | ||
result.push(item) unless result.include?(item) | ||
end | ||
else | ||
item = result.find { |r| r[:name] == group } | ||
item ||= {name: group, data: {}} | ||
item[:data][category] = inner_data | ||
result.push(item) unless result.include?(item) | ||
end | ||
end | ||
end.then { cartesian_series(_1) } | ||
end | ||
|
||
def cartesian_series(input = series_raw) | ||
input.map do |series| | ||
series.update_key(:data) do |data| | ||
data.map do |x, y| | ||
{x: x, y: y} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.