Skip to content

Commit

Permalink
Merge pull request #382 from PanSpagetka/fix-units-in-CU-grouped
Browse files Browse the repository at this point in the history
Fix units formating for grouped charts
(cherry picked from commit 0ba48fa)

https://bugzilla.redhat.com/show_bug.cgi?id=1413105
  • Loading branch information
mzazrivec authored and simaishi committed Mar 7, 2017
1 parent 6bb8455 commit 787ebd5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/report_formatter/c3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def build_document_header
unless mri.graph[:type] == 'Donut' || mri.graph[:type] == 'Pie'
mri.chart[:legend] = {:position => 'bottom'}
end
format, options = javascript_format(mri.graph[:columns][0], nil)

column = grouped_by_tag_category? ? mri.graph[:columns][0].split(/_+/)[0..-2].join('_') : mri.graph[:columns][0]
format, options = javascript_format(column, nil)
return unless format

axis_formatter = {:function => format, :options => options}
Expand Down Expand Up @@ -168,5 +170,9 @@ def build_reporting_chart_numeric(_maxcols, _divider)
mri.chart[:miq][:reporting_chart] = true
super
end

def grouped_by_tag_category?
!!(mri.performance && mri.performance.fetch_path(:group_by_category))
end
end
end
1 change: 0 additions & 1 deletion lib/report_formatter/chart_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def extract_column_names
# 'Vm-num_cpu:total' gives 'num_cpu' and 'num_cpu__total'
# "Vm::Providers::InfraManager::Vm-num_cpu:total"
# gives 'Vm::Providers::InfraManager::Vm' and 'num_cpu__total'

stage1, aggreg = mri.graph[:column].split(/(?<!:):(?!:)/) # split by ':', NOT by '::'
model1, column = stage1.split('-', 2)
_model, sub_model = model1.split('.', 2)
Expand Down
54 changes: 54 additions & 0 deletions spec/lib/report_formater/c3_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,58 @@
render_report(report)
end
end

context '#C&U charts without grouping' do
let(:report) { cu_chart_without_grouping }
before(:each) do
render_report(report, &proc { |e| e.options.graph_options = { :chart_type => :performance } })
end

it "has right data" do
expect(report.chart[:data][:columns][0].count).to eq(report.table.data.count + 1)
expect(report.chart[:data][:columns][0]).to eq(["x", "8/19", "8/20"])
expect(report.chart[:data][:columns][1]).to eq(["1", 19_986.0, 205_632.0])
expect(report.chart[:data][:columns][2]).to eq(["2", 41_584.0, 41_584.0])
end

it "has right type" do
expect(report.chart[:axis][:x][:type]).to eq("timeseries")
end

it 'has right formatting functions' do
expect(report.chart[:axis][:y][:tick][:format][:function]).to eq("mhz_to_human_size")
expect(report.chart[:miq][:format][:function]).to eq("mhz_to_human_size")
end
it 'has right tabels' do
expect(report.chart[:miq][:name_table]).to eq("1" => "Avg Used", "2" => "Max Available")
expect(report.chart[:miq][:category_table]).to eq(["8/19", "8/20"])
end
end

context '#C&U charts with grouping' do
let(:report) { cu_chart_with_grouping }
before(:each) do
render_report(report, &proc { |e| e.options.graph_options = { :chart_type => :performance } })
end

it "has right data" do
expect(report.chart[:data][:columns][0].count).to eq(report.table.data.count + 1)
expect(report.chart[:data][:columns][0]).to eq(["x", "8/19", "8/20"])
expect(report.chart[:data][:columns][1]).to eq(["1", 19_986.0, 205_632.0])
expect(report.chart[:data][:columns][2]).to eq(["2", 41_584.0, 41_584.0])
end

it "has right type" do
expect(report.chart[:axis][:x][:type]).to eq("timeseries")
end

it 'has right formatting functions' do
expect(report.chart[:axis][:y][:tick][:format][:function]).to eq("mhz_to_human_size")
expect(report.chart[:miq][:format][:function]).to eq("mhz_to_human_size")
end
it 'has right tabels' do
expect(report.chart[:miq][:name_table]).to eq("1" => "Avg Used", "2" => "Max Available")
expect(report.chart[:miq][:category_table]).to eq(["8/19", "8/20"])
end
end
end

0 comments on commit 787ebd5

Please sign in to comment.