Commit dbd245c8 authored by Clement Ho's avatar Clement Ho

Merge branch '57085-introduce-zoom-and-scroll-functionality-on-metrics-charts' into 'master'

Resolve "Introduce zoom and scroll functionality on metrics charts"

Closes #57085

See merge request gitlab-org/gitlab-ce!25388
parents d40b55c2 64abbb78
...@@ -57,7 +57,7 @@ export default { ...@@ -57,7 +57,7 @@ export default {
}, },
width: 0, width: 0,
height: 0, height: 0,
scatterSymbol: undefined, svgs: {},
}; };
}, },
computed: { computed: {
...@@ -78,25 +78,25 @@ export default { ...@@ -78,25 +78,25 @@ export default {
axisPointer: { axisPointer: {
snap: true, snap: true,
}, },
nameTextStyle: {
padding: [18, 0, 0, 0],
},
}, },
yAxis: { yAxis: {
name: this.yAxisLabel, name: this.yAxisLabel,
axisLabel: { axisLabel: {
formatter: value => value.toFixed(3), formatter: value => value.toFixed(3),
}, },
nameTextStyle: {
padding: [0, 0, 36, 0],
},
}, },
legend: { legend: {
formatter: this.xAxisLabel, formatter: this.xAxisLabel,
}, },
series: this.scatterSeries, series: this.scatterSeries,
dataZoom: this.dataZoomConfig,
}; };
}, },
dataZoomConfig() {
const handleIcon = this.svgs['scroll-handle'];
return handleIcon ? { handleIcon } : {};
},
earliestDatapoint() { earliestDatapoint() {
return Object.values(this.chartData).reduce((acc, data) => { return Object.values(this.chartData).reduce((acc, data) => {
const [[timestamp]] = data.sort(([a], [b]) => { const [[timestamp]] = data.sort(([a], [b]) => {
...@@ -131,7 +131,7 @@ export default { ...@@ -131,7 +131,7 @@ export default {
return { return {
type: 'scatter', type: 'scatter',
data: this.recentDeployments.map(deployment => [deployment.createdAt, 0]), data: this.recentDeployments.map(deployment => [deployment.createdAt, 0]),
symbol: this.scatterSymbol, symbol: this.svgs.rocket,
symbolSize: 14, symbolSize: 14,
}; };
}, },
...@@ -151,7 +151,8 @@ export default { ...@@ -151,7 +151,8 @@ export default {
created() { created() {
debouncedResize = debounceByAnimationFrame(this.onResize); debouncedResize = debounceByAnimationFrame(this.onResize);
window.addEventListener('resize', debouncedResize); window.addEventListener('resize', debouncedResize);
this.getScatterSymbol(); this.setSvg('rocket');
this.setSvg('scroll-handle');
}, },
methods: { methods: {
formatTooltipText(params) { formatTooltipText(params) {
...@@ -167,11 +168,11 @@ export default { ...@@ -167,11 +168,11 @@ export default {
this.tooltip.content = `${this.yAxisLabel} ${seriesData.value[1].toFixed(3)}`; this.tooltip.content = `${this.yAxisLabel} ${seriesData.value[1].toFixed(3)}`;
} }
}, },
getScatterSymbol() { setSvg(name) {
getSvgIconPathContent('rocket') getSvgIconPathContent(name)
.then(path => { .then(path => {
if (path) { if (path) {
this.scatterSymbol = `path://${path}`; this.$set(this.svgs, name, `path://${path}`);
} }
}) })
.catch(() => {}); .catch(() => {});
......
---
title: Add zoom and scroll to metrics dashboard
merge_request: 25388
author:
type: added
...@@ -7,6 +7,7 @@ import MonitoringMock, { deploymentData } from '../mock_data'; ...@@ -7,6 +7,7 @@ import MonitoringMock, { deploymentData } from '../mock_data';
describe('Area component', () => { describe('Area component', () => {
const mockWidgets = 'mockWidgets'; const mockWidgets = 'mockWidgets';
const mockSvgPathContent = 'mockSvgPathContent';
let mockGraphData; let mockGraphData;
let areaChart; let areaChart;
let spriteSpy; let spriteSpy;
...@@ -30,7 +31,7 @@ describe('Area component', () => { ...@@ -30,7 +31,7 @@ describe('Area component', () => {
}); });
spriteSpy = spyOnDependency(Area, 'getSvgIconPathContent').and.callFake( spriteSpy = spyOnDependency(Area, 'getSvgIconPathContent').and.callFake(
() => new Promise(resolve => resolve()), () => new Promise(resolve => resolve(mockSvgPathContent)),
); );
}); });
...@@ -146,13 +147,22 @@ describe('Area component', () => { ...@@ -146,13 +147,22 @@ describe('Area component', () => {
}); });
}); });
describe('getScatterSymbol', () => { describe('setSvg', () => {
const mockSvgName = 'mockSvgName';
beforeEach(() => { beforeEach(() => {
areaChart.vm.getScatterSymbol(); areaChart.vm.setSvg(mockSvgName);
});
it('gets svg path content', () => {
expect(spriteSpy).toHaveBeenCalledWith(mockSvgName);
}); });
it('gets rocket svg path content for use as deployment data symbol', () => { it('sets svg path content', done => {
expect(spriteSpy).toHaveBeenCalledWith('rocket'); areaChart.vm.$nextTick(() => {
expect(areaChart.vm.svgs[mockSvgName]).toBe(`path://${mockSvgPathContent}`);
done();
});
}); });
}); });
......
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