Commit 5c2d3b9c authored by Miguel Rincon's avatar Miguel Rincon

Time series extends axis options correctly

Upper component should be able to pass options to the time series
without destroying the structure of original options.

This change added the xAxis and yAxis configuration to the options
without replacing them completly, similarly to the series.
parent a343011d
...@@ -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