Commit 16701067 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch...

Merge branch '202620-charts-with-series-that-contain-multiple-labels-do-not-have-unique-colors-for-each-label' into 'master'

Fix colors in multiple series charts

See merge request gitlab-org/gitlab!28095
parents 38b93f9f a5d03379
...@@ -13,7 +13,6 @@ import { ...@@ -13,7 +13,6 @@ import {
lineWidths, lineWidths,
symbolSizes, symbolSizes,
dateFormats, dateFormats,
chartColorValues,
} from '../../constants'; } from '../../constants';
import { getYAxisOptions, getChartGrid, getTooltipFormatter } from './options'; import { getYAxisOptions, getChartGrid, getTooltipFormatter } from './options';
import { makeDataSeries } from '~/helpers/monitor_helper'; import { makeDataSeries } from '~/helpers/monitor_helper';
...@@ -124,7 +123,7 @@ export default { ...@@ -124,7 +123,7 @@ export default {
// Transforms & supplements query data to render appropriate labels & styles // Transforms & supplements query data to render appropriate labels & styles
// Input: [{ queryAttributes1 }, { queryAttributes2 }] // Input: [{ queryAttributes1 }, { queryAttributes2 }]
// Output: [{ seriesAttributes1 }, { seriesAttributes2 }] // Output: [{ seriesAttributes1 }, { seriesAttributes2 }]
return this.graphData.metrics.reduce((acc, query, i) => { return this.graphData.metrics.reduce((acc, query) => {
const { appearance } = query; const { appearance } = query;
const lineType = const lineType =
appearance && appearance.line && appearance.line.type appearance && appearance.line && appearance.line.type
...@@ -145,7 +144,6 @@ export default { ...@@ -145,7 +144,6 @@ export default {
lineStyle: { lineStyle: {
type: lineType, type: lineType,
width: lineWidth, width: lineWidth,
color: chartColorValues[i % chartColorValues.length],
}, },
showSymbol: false, showSymbol: false,
areaStyle: this.graphData.type === 'area-chart' ? areaStyle : undefined, areaStyle: this.graphData.type === 'area-chart' ? areaStyle : undefined,
......
...@@ -67,13 +67,6 @@ export const colorValues = { ...@@ -67,13 +67,6 @@ export const colorValues = {
anomalyAreaColor: '#1f78d1', anomalyAreaColor: '#1f78d1',
}; };
export const chartColorValues = [
'#1f78d1', // $blue-500 (see variables.scss)
'#1aaa55', // $green-500
'#fc9403', // $orange-500
'#6d49cb', // $purple
];
export const lineTypes = { export const lineTypes = {
default: 'solid', default: 'solid',
}; };
......
---
title: Fix wrong colors displayed in charts
merge_request: 28095
author:
type: fixed
import { shallowMount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { setTestTimeout } from 'helpers/timeout'; import { setTestTimeout } from 'helpers/timeout';
import { GlLink } from '@gitlab/ui'; import { GlLink } from '@gitlab/ui';
import { GlAreaChart, GlLineChart, GlChartSeriesLabel } from '@gitlab/ui/dist/charts'; import {
GlAreaChart,
GlLineChart,
GlChartSeriesLabel,
GlChartLegend,
} from '@gitlab/ui/dist/charts';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { shallowWrapperContainsSlotText } from 'helpers/vue_test_utils_helper'; import { shallowWrapperContainsSlotText } from 'helpers/vue_test_utils_helper';
import { chartColorValues } from '~/monitoring/constants';
import { createStore } from '~/monitoring/stores'; import { createStore } from '~/monitoring/stores';
import TimeSeries from '~/monitoring/components/charts/time_series.vue'; import TimeSeries from '~/monitoring/components/charts/time_series.vue';
import * as types from '~/monitoring/stores/mutation_types'; import * as types from '~/monitoring/stores/mutation_types';
...@@ -42,13 +46,16 @@ describe('Time series component', () => { ...@@ -42,13 +46,16 @@ describe('Time series component', () => {
let store; let store;
const makeTimeSeriesChart = (graphData, type) => const makeTimeSeriesChart = (graphData, type) =>
shallowMount(TimeSeries, { mount(TimeSeries, {
propsData: { propsData: {
graphData: { ...graphData, type }, graphData: { ...graphData, type },
deploymentData: store.state.monitoringDashboard.deploymentData, deploymentData: store.state.monitoringDashboard.deploymentData,
projectPath: `${mockHost}${mockProjectDir}`, projectPath: `${mockHost}${mockProjectDir}`,
}, },
store, store,
stubs: {
GlPopover: true,
},
}); });
describe('With a single time series', () => { describe('With a single time series', () => {
...@@ -308,10 +315,6 @@ describe('Time series component', () => { ...@@ -308,10 +315,6 @@ describe('Time series component', () => {
it('formats line width correctly', () => { it('formats line width correctly', () => {
expect(chartData[0].lineStyle.width).toBe(2); expect(chartData[0].lineStyle.width).toBe(2);
}); });
it('formats line color correctly', () => {
expect(chartData[0].lineStyle.color).toBe(chartColorValues[0]);
});
}); });
describe('chartOptions', () => { describe('chartOptions', () => {
...@@ -557,19 +560,39 @@ describe('Time series component', () => { ...@@ -557,19 +560,39 @@ describe('Time series component', () => {
timeSeriesChart.destroy(); timeSeriesChart.destroy();
}); });
describe('computed', () => { describe('Color match', () => {
let chartData; let lineColors;
beforeEach(() => { beforeEach(() => {
({ chartData } = timeSeriesChart.vm); lineColors = timeSeriesChart
.find(GlAreaChart)
.vm.series.map(item => item.lineStyle.color);
});
it('should contain different colors for contiguous time series', () => {
lineColors.forEach((color, index) => {
expect(color).not.toBe(lineColors[index + 1]);
});
});
it('should match series color with tooltip label color', () => {
const labels = timeSeriesChart.findAll(GlChartSeriesLabel);
lineColors.forEach((color, index) => {
const labelColor = labels.at(index).props('color');
expect(color).toBe(labelColor);
});
}); });
it('should contain different colors for each time series', () => { it('should match series color with legend color', () => {
expect(chartData[0].lineStyle.color).toBe('#1f78d1'); const legendColors = timeSeriesChart
expect(chartData[1].lineStyle.color).toBe('#1aaa55'); .find(GlChartLegend)
expect(chartData[2].lineStyle.color).toBe('#fc9403'); .props('seriesInfo')
expect(chartData[3].lineStyle.color).toBe('#6d49cb'); .map(item => item.color);
expect(chartData[4].lineStyle.color).toBe('#1f78d1');
lineColors.forEach((color, index) => {
expect(color).toBe(legendColors[index]);
});
}); });
}); });
}); });
......
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