Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix units formating for grouped charts #382

Merged
merged 2 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/application_controller/performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def prepare_perf_tag_chart(chart, rpt, cat_desc)
# Grab the first (and should be only) chart column
col = chart[:columns].first
# Create the new chart columns for each tag
chart[:columns] ||= rpt.extras[:group_by_tags].collect { |t| col + "_" + t }
chart[:columns] = rpt.extras[:group_by_tags].collect { |t| col + "_" + t }
end

def gen_perf_chart(chart, rpt, idx, zoom_action)
Expand Down
8 changes: 7 additions & 1 deletion lib/report_formatter/c3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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 @@ -174,5 +176,9 @@ def build_performance_chart_pie(_maxcols, _divider)
mri.chart[:miq][:expand_tooltip] = 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 @@ -92,4 +92,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