Commit d22b6b0f authored by Dhiraj Bodicherla's avatar Dhiraj Bodicherla Committed by Kushal Pandya

Monitoring chart tooltip improvement

This MR improves monitoring dashboard charts
tooltip display logic
parent befd7a23
...@@ -87,11 +87,17 @@ export const generateAnnotationsSeries = ({ deployments = [], annotations = [] } ...@@ -87,11 +87,17 @@ export const generateAnnotationsSeries = ({ deployments = [], annotations = [] }
return { return {
name: 'deployments', name: 'deployments',
value: [deployment.createdAt, annotationsYAxisCoords.pos], value: [deployment.createdAt, annotationsYAxisCoords.pos],
// style options
symbol: deployment.icon, symbol: deployment.icon,
symbolSize: symbolSizes.default, symbolSize: symbolSizes.default,
itemStyle: { itemStyle: {
color: deployment.color, color: deployment.color,
}, },
// metadata that are accessible in `formatTooltipText` method
tooltipData: {
sha: deployment.sha.substring(0, 8),
commitUrl: deployment.commitUrl,
},
}; };
}); });
...@@ -100,8 +106,12 @@ export const generateAnnotationsSeries = ({ deployments = [], annotations = [] } ...@@ -100,8 +106,12 @@ export const generateAnnotationsSeries = ({ deployments = [], annotations = [] }
return { return {
name: 'annotations', name: 'annotations',
value: [annotation.from, annotationsYAxisCoords.pos], value: [annotation.from, annotationsYAxisCoords.pos],
// style options
symbol: 'none', symbol: 'none',
description: annotation.description, // metadata that are accessible in `formatTooltipText` method
tooltipData: {
description: annotation.description,
},
}; };
}); });
......
...@@ -262,19 +262,17 @@ export default { ...@@ -262,19 +262,17 @@ export default {
params.seriesData.forEach(dataPoint => { params.seriesData.forEach(dataPoint => {
if (dataPoint.value) { if (dataPoint.value) {
const [xVal, yVal] = dataPoint.value; const [, yVal] = dataPoint.value;
this.tooltip.type = dataPoint.name; this.tooltip.type = dataPoint.name;
if (this.isTooltipOfType(this.tooltip.type, this.$options.tooltipTypes.deployments)) { if (this.isTooltipOfType(this.tooltip.type, this.$options.tooltipTypes.deployments)) {
const [deploy] = this.recentDeployments.filter( const { data = {} } = dataPoint;
deployment => deployment.createdAt === xVal, this.tooltip.sha = data?.tooltipData?.sha;
); this.tooltip.commitUrl = data?.tooltipData?.commitUrl;
this.tooltip.sha = deploy.sha.substring(0, 8);
this.tooltip.commitUrl = deploy.commitUrl;
} else if ( } else if (
this.isTooltipOfType(this.tooltip.type, this.$options.tooltipTypes.annotations) this.isTooltipOfType(this.tooltip.type, this.$options.tooltipTypes.annotations)
) { ) {
const { data } = dataPoint; const { data } = dataPoint;
this.tooltip.content.push(data?.description); this.tooltip.content.push(data?.tooltipData?.description);
} else { } else {
const { seriesName, color, dataIndex } = dataPoint; const { seriesName, color, dataIndex } = dataPoint;
......
...@@ -155,43 +155,56 @@ describe('Time series component', () => { ...@@ -155,43 +155,56 @@ describe('Time series component', () => {
describe('methods', () => { describe('methods', () => {
describe('formatTooltipText', () => { describe('formatTooltipText', () => {
let mockDate; const mockCommitUrl = deploymentData[0].commitUrl;
let mockCommitUrl; const mockDate = deploymentData[0].created_at;
let generateSeriesData; const mockSha = 'f5bcd1d9';
const mockLineSeriesData = () => ({
beforeEach(() => { seriesData: [
mockDate = deploymentData[0].created_at; {
mockCommitUrl = deploymentData[0].commitUrl; seriesName: timeSeriesChart.vm.chartData[0].name,
generateSeriesData = type => ({ componentSubType: 'line',
seriesData: [ value: [mockDate, 5.55555],
{ dataIndex: 0,
seriesName: timeSeriesChart.vm.chartData[0].name, },
componentSubType: type, ],
value: [mockDate, 5.55555], value: mockDate,
dataIndex: 0,
...(type === 'scatter' && { name: 'deployments' }),
},
],
value: mockDate,
});
}); });
const annotationsMetadata = {
tooltipData: {
sha: mockSha,
commitUrl: mockCommitUrl,
},
};
const mockAnnotationsSeriesData = {
seriesData: [
{
componentSubType: 'scatter',
seriesName: 'series01',
dataIndex: 0,
value: [mockDate, 5.55555],
type: 'scatter',
name: 'deployments',
},
],
value: mockDate,
};
it('does not throw error if data point is outside the zoom range', () => { it('does not throw error if data point is outside the zoom range', () => {
const seriesDataWithoutValue = generateSeriesData('line'); const seriesDataWithoutValue = {
expect( ...mockLineSeriesData(),
timeSeriesChart.vm.formatTooltipText({ seriesData: mockLineSeriesData().seriesData.map(data => ({
...seriesDataWithoutValue, ...data,
seriesData: seriesDataWithoutValue.seriesData.map(data => ({ value: undefined,
...data, })),
value: undefined, };
})), expect(timeSeriesChart.vm.formatTooltipText(seriesDataWithoutValue)).toBeUndefined();
}),
).toBeUndefined();
}); });
describe('when series is of line type', () => { describe('when series is of line type', () => {
beforeEach(done => { beforeEach(done => {
timeSeriesChart.vm.formatTooltipText(generateSeriesData('line')); timeSeriesChart.vm.formatTooltipText(mockLineSeriesData());
timeSeriesChart.vm.$nextTick(done); timeSeriesChart.vm.$nextTick(done);
}); });
...@@ -223,7 +236,14 @@ describe('Time series component', () => { ...@@ -223,7 +236,14 @@ describe('Time series component', () => {
describe('when series is of scatter type, for deployments', () => { describe('when series is of scatter type, for deployments', () => {
beforeEach(() => { beforeEach(() => {
timeSeriesChart.vm.formatTooltipText(generateSeriesData('scatter')); timeSeriesChart.vm.formatTooltipText({
...mockAnnotationsSeriesData,
seriesData: mockAnnotationsSeriesData.seriesData.map(data => ({
...data,
data: annotationsMetadata,
})),
});
return timeSeriesChart.vm.$nextTick;
}); });
it('set tooltip type to deployments', () => { it('set tooltip type to deployments', () => {
...@@ -242,6 +262,25 @@ describe('Time series component', () => { ...@@ -242,6 +262,25 @@ describe('Time series component', () => {
expect(timeSeriesChart.vm.tooltip.commitUrl).toBe(mockCommitUrl); expect(timeSeriesChart.vm.tooltip.commitUrl).toBe(mockCommitUrl);
}); });
}); });
describe('when series is of scatter type and deployments data is missing', () => {
beforeEach(() => {
timeSeriesChart.vm.formatTooltipText(mockAnnotationsSeriesData);
return timeSeriesChart.vm.$nextTick;
});
it('formats tooltip title', () => {
expect(timeSeriesChart.vm.tooltip.title).toBe('16 Jul 2019, 10:14AM');
});
it('formats tooltip sha', () => {
expect(timeSeriesChart.vm.tooltip.sha).toBeUndefined();
});
it('formats tooltip commit url', () => {
expect(timeSeriesChart.vm.tooltip.commitUrl).toBeUndefined();
});
});
}); });
describe('setSvg', () => { describe('setSvg', () => {
......
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