Commit aaa69bd9 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '207070-metrics-anomaly-chart-rendering-fails' into 'master'

Fix broken chart: Options for axis are extended correctly in the time series

Closes #207070

See merge request gitlab-org/gitlab!25399
parents 48f11c99 5c2d3b9c
...@@ -127,7 +127,6 @@ export default { ...@@ -127,7 +127,6 @@ export default {
}); });
const yAxisWithOffset = { const yAxisWithOffset = {
name: this.yAxisLabel,
axisLabel: { axisLabel: {
formatter: num => roundOffFloat(num - this.yOffset, 3).toString(), formatter: num => roundOffFloat(num - this.yOffset, 3).toString(),
}, },
...@@ -162,6 +161,7 @@ export default { ...@@ -162,6 +161,7 @@ export default {
}), }),
); );
} }
return { yAxis: yAxisWithOffset, series: boundarySeries }; return { yAxis: yAxisWithOffset, series: boundarySeries };
}, },
}, },
......
...@@ -162,7 +162,8 @@ export default { ...@@ -162,7 +162,8 @@ export default {
); );
}, },
chartOptions() { chartOptions() {
const option = omit(this.option, 'series'); const { yAxis, xAxis } = this.option;
const option = omit(this.option, ['series', 'yAxis', 'xAxis']);
const dataYAxis = { const dataYAxis = {
name: this.yAxisLabel, name: this.yAxisLabel,
...@@ -173,7 +174,9 @@ export default { ...@@ -173,7 +174,9 @@ export default {
axisLabel: { axisLabel: {
formatter: num => roundOffFloat(num, 3).toString(), formatter: num => roundOffFloat(num, 3).toString(),
}, },
...yAxis,
}; };
const deploymentsYAxis = { const deploymentsYAxis = {
show: false, show: false,
min: deploymentYAxisCoords.min, min: deploymentYAxisCoords.min,
...@@ -184,18 +187,21 @@ export default { ...@@ -184,18 +187,21 @@ export default {
}, },
}; };
const timeXAxis = {
name: __('Time'),
type: 'time',
axisLabel: {
formatter: date => dateFormat(date, dateFormats.timeOfDay),
},
axisPointer: {
snap: true,
},
...xAxis,
};
return { return {
series: this.chartOptionSeries, series: this.chartOptionSeries,
xAxis: { xAxis: timeXAxis,
name: __('Time'),
type: 'time',
axisLabel: {
formatter: date => dateFormat(date, dateFormats.timeOfDay),
},
axisPointer: {
snap: true,
},
},
yAxis: [dataYAxis, deploymentsYAxis], yAxis: [dataYAxis, deploymentsYAxis],
dataZoom: [this.dataZoomConfig], dataZoom: [this.dataZoomConfig],
...option, ...option,
......
---
title: Time series extends axis options correctly
merge_request: 25399
author:
type: fixed
...@@ -358,6 +358,45 @@ describe('Time series component', () => { ...@@ -358,6 +358,45 @@ describe('Time series component', () => {
expect(optionSeries[0].name).toEqual(mockSeriesName); expect(optionSeries[0].name).toEqual(mockSeriesName);
}); });
}); });
it('additional y axis data', () => {
const mockCustomYAxisOption = {
name: 'Custom y axis label',
axisLabel: {
formatter: jest.fn(),
},
};
timeSeriesChart.setProps({
option: {
yAxis: mockCustomYAxisOption,
},
});
return timeSeriesChart.vm.$nextTick().then(() => {
const { yAxis } = getChartOptions();
expect(yAxis[0]).toMatchObject(mockCustomYAxisOption);
});
});
it('additional x axis data', () => {
const mockCustomXAxisOption = {
name: 'Custom x axis label',
};
timeSeriesChart.setProps({
option: {
xAxis: mockCustomXAxisOption,
},
});
return timeSeriesChart.vm.$nextTick().then(() => {
const { xAxis } = getChartOptions();
expect(xAxis).toMatchObject(mockCustomXAxisOption);
});
});
}); });
describe('yAxis formatter', () => { describe('yAxis formatter', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment