From 51df3116814d4073b03d7f5fec3887631ee1ac7a Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Fri, 10 Mar 2023 17:48:52 +0100 Subject: [PATCH 1/2] fix(dashboard): Cross filters with time shifted series --- .../src/Timeseries/transformProps.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index a13031b01bb37..7e87aa4f3fe01 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -107,8 +107,9 @@ export default function transformProps( } = chartProps; const { verboseMap = {} } = datasource; const [queryData] = queriesData; - const { data = [], label_map: labelMap } = + const { data = [], label_map = {} } = queryData as TimeseriesChartDataResponseResult; + const dataTypes = getColtypesMapping(queryData); const annotationData = getAnnotationData(chartProps); @@ -154,6 +155,17 @@ export default function transformProps( }: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; const refs: Refs = {}; + const labelMap = Object.entries(label_map).reduce((acc, entry) => { + if ( + entry[1].length > groupby.length && + Array.isArray(formData.timeCompare) && + formData.timeCompare.includes(entry[1][0]) + ) { + entry[1].shift(); + } + return { ...acc, [entry[0]]: entry[1] }; + }, {}); + const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); const rebasedData = rebaseForecastDatum(data, verboseMap); let xAxisLabel = getXAxisLabel(chartProps.rawFormData) as string; From f5f6d9f49d289dd9922e8b8fc6a6065a1b3c3220 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Mon, 13 Mar 2023 13:26:10 +0100 Subject: [PATCH 2/2] Add test --- .../src/Timeseries/transformProps.ts | 5 +-- .../src/Timeseries/types.ts | 1 + .../test/Timeseries/transformProps.test.ts | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index 7e87aa4f3fe01..a853c4b869d16 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -137,6 +137,7 @@ export default function transformProps( showValue, sliceId, timeGrainSqla, + timeCompare, stack, tooltipTimeFormat, tooltipSortByMetric, @@ -158,8 +159,8 @@ export default function transformProps( const labelMap = Object.entries(label_map).reduce((acc, entry) => { if ( entry[1].length > groupby.length && - Array.isArray(formData.timeCompare) && - formData.timeCompare.includes(entry[1][0]) + Array.isArray(timeCompare) && + timeCompare.includes(entry[1][0]) ) { entry[1].shift(); } diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts index 56527ebd63bf9..bca13a0584660 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts @@ -71,6 +71,7 @@ export type EchartsTimeseriesFormData = QueryFormData & { rowLimit: number; seriesType: EchartsTimeseriesSeriesType; stack: StackType; + timeCompare?: string[]; tooltipTimeFormat?: string; truncateYAxis: boolean; yAxisFormat?: string; diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts index b185c3a7675e9..63ca50449ed09 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts @@ -497,4 +497,35 @@ describe('Does transformProps transform series correctly', () => { }); }); }); + + it('should remove time shift labels from label_map', () => { + const updatedChartPropsConfig = { + ...chartPropsConfig, + formData: { + ...formData, + timeCompare: ['1 year ago'], + }, + queriesData: [ + { + ...queriesData[0], + label_map: { + '1 year ago, foo1, bar1': ['1 year ago', 'foo1', 'bar1'], + '1 year ago, foo2, bar2': ['1 year ago', 'foo2', 'bar2'], + 'foo1, bar1': ['foo1', 'bar1'], + 'foo2, bar2': ['foo2', 'bar2'], + }, + }, + ], + }; + const chartProps = new ChartProps(updatedChartPropsConfig); + const transformedProps = transformProps( + chartProps as EchartsTimeseriesChartProps, + ); + expect(transformedProps.labelMap).toEqual({ + '1 year ago, foo1, bar1': ['foo1', 'bar1'], + '1 year ago, foo2, bar2': ['foo2', 'bar2'], + 'foo1, bar1': ['foo1', 'bar1'], + 'foo2, bar2': ['foo2', 'bar2'], + }); + }); });