From 03d69e996ce75eff8ebd22c4c18c479698139184 Mon Sep 17 00:00:00 2001 From: Yahya Kayani Date: Sat, 4 Dec 2021 15:34:48 +0500 Subject: [PATCH 1/5] fix(Mixed Timeseries Chart): Custom Metric Label --- .../src/MixedTimeseries/transformProps.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts index 3d7b8174bee7e..5009e7e57d939 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts @@ -65,8 +65,10 @@ import { TIMESERIES_CONSTANTS } from '../constants'; export default function transformProps( chartProps: EchartsMixedTimeseriesFormData, ): EchartsMixedTimeseriesChartTransformedProps { - const { width, height, formData, queriesData, hooks, filterState } = + const { width, height, formData, queriesData, hooks, filterState,datasource } = chartProps; + const { verboseMap = {} } = datasource; + const { annotation_data: annotationData_ } = queriesData[0]; const annotationData = annotationData_ || {}; const data1: TimeseriesDataRecord[] = queriesData[0].data || []; @@ -121,10 +123,12 @@ export default function transformProps( }: EchartsMixedTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); - const rawSeriesA = extractTimeseriesSeries(rebaseTimeseriesDatum(data1), { + const rebasedDataA = rebaseTimeseriesDatum(data1, verboseMap); + const rawSeriesA = extractTimeseriesSeries(rebasedDataA, { fillNeighborValue: stack ? 0 : undefined, }); - const rawSeriesB = extractTimeseriesSeries(rebaseTimeseriesDatum(data2), { + const rebasedDataB = rebaseTimeseriesDatum(data2, verboseMap); + const rawSeriesB = extractTimeseriesSeries(rebasedDataB, { fillNeighborValue: stackB ? 0 : undefined, }); From f0ea135144a7b9883d8aed2ca8f803b33ceab7a6 Mon Sep 17 00:00:00 2001 From: Yahya Kayani Date: Sat, 4 Dec 2021 15:57:19 +0500 Subject: [PATCH 2/5] Fixed Formatting --- .../src/MixedTimeseries/transformProps.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts index 5009e7e57d939..5667ae30e5be6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts @@ -65,10 +65,16 @@ import { TIMESERIES_CONSTANTS } from '../constants'; export default function transformProps( chartProps: EchartsMixedTimeseriesFormData, ): EchartsMixedTimeseriesChartTransformedProps { - const { width, height, formData, queriesData, hooks, filterState,datasource } = - chartProps; + const { + width, + height, + formData, + queriesData, + hooks, + filterState, + datasource, + } = chartProps; const { verboseMap = {} } = datasource; - const { annotation_data: annotationData_ } = queriesData[0]; const annotationData = annotationData_ || {}; const data1: TimeseriesDataRecord[] = queriesData[0].data || []; From bfcc96d1d89f74abe20d7a2a8baae974e02f48ed Mon Sep 17 00:00:00 2001 From: Yahya Kayani Date: Mon, 6 Dec 2021 12:39:35 +0500 Subject: [PATCH 3/5] Fixed Type mismatch from queryFormData --- .../packages/superset-ui-core/src/query/types/QueryFormData.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts b/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts index e799f7cccd28a..171dc1bd7bcbd 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts @@ -34,6 +34,7 @@ import { TimeRange, TimeRangeEndpoints } from './Time'; import { TimeGranularity } from '../../time-format'; import { JsonObject } from '../../connection'; import { AdhocColumn, PhysicalColumn } from './Column'; +import { Datasource } from '..'; /** * Metric definition/reference in query object. @@ -146,7 +147,7 @@ export type ExtraFormData = ExtraFormDataAppend & ExtraFormDataOverride; export interface BaseFormData extends TimeRange, FormDataResidual { /** datasource identifier ${id}_${type} */ - datasource: string; + datasource: Datasource; /** * visualization type * - necessary if you use the plugin and want to use From e3c43f05b9d418ecda61e245d80657e260ba624e Mon Sep 17 00:00:00 2001 From: Yahya Kayani Date: Wed, 8 Dec 2021 14:50:25 +0500 Subject: [PATCH 4/5] Reverted type change and used extracted datasource --- .../superset-ui-core/src/query/types/QueryFormData.ts | 3 +-- .../src/MixedTimeseries/transformProps.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts b/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts index 171dc1bd7bcbd..e799f7cccd28a 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts @@ -34,7 +34,6 @@ import { TimeRange, TimeRangeEndpoints } from './Time'; import { TimeGranularity } from '../../time-format'; import { JsonObject } from '../../connection'; import { AdhocColumn, PhysicalColumn } from './Column'; -import { Datasource } from '..'; /** * Metric definition/reference in query object. @@ -147,7 +146,7 @@ export type ExtraFormData = ExtraFormDataAppend & ExtraFormDataOverride; export interface BaseFormData extends TimeRange, FormDataResidual { /** datasource identifier ${id}_${type} */ - datasource: Datasource; + datasource: string; /** * visualization type * - necessary if you use the plugin and want to use diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts index 5667ae30e5be6..0f0fc2a72a61d 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts @@ -74,9 +74,9 @@ export default function transformProps( filterState, datasource, } = chartProps; - const { verboseMap = {} } = datasource; const { annotation_data: annotationData_ } = queriesData[0]; const annotationData = annotationData_ || {}; + const extractedDataSource = datasource || {}; const data1: TimeseriesDataRecord[] = queriesData[0].data || []; const data2: TimeseriesDataRecord[] = queriesData[1].data || []; @@ -129,11 +129,11 @@ export default function transformProps( }: EchartsMixedTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); - const rebasedDataA = rebaseTimeseriesDatum(data1, verboseMap); + const rebasedDataA = rebaseTimeseriesDatum(data1, extractedDataSource); const rawSeriesA = extractTimeseriesSeries(rebasedDataA, { fillNeighborValue: stack ? 0 : undefined, }); - const rebasedDataB = rebaseTimeseriesDatum(data2, verboseMap); + const rebasedDataB = rebaseTimeseriesDatum(data2, extractedDataSource); const rawSeriesB = extractTimeseriesSeries(rebasedDataB, { fillNeighborValue: stackB ? 0 : undefined, }); From 24ee3456564815278c320774afe64bfadbd49ab7 Mon Sep 17 00:00:00 2001 From: Yahya Kayani Date: Mon, 13 Dec 2021 22:45:39 +0500 Subject: [PATCH 5/5] Type fix for mapping --- .../src/MixedTimeseries/transformProps.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts index 0f0fc2a72a61d..1f39a4ade9209 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts @@ -33,6 +33,7 @@ import { DEFAULT_FORM_DATA, EchartsMixedTimeseriesFormData, EchartsMixedTimeseriesChartTransformedProps, + EchartsMixedTimeseriesProps, } from './types'; import { ForecastSeriesEnum } from '../types'; import { parseYAxisBound } from '../utils/controls'; @@ -63,7 +64,7 @@ import { import { TIMESERIES_CONSTANTS } from '../constants'; export default function transformProps( - chartProps: EchartsMixedTimeseriesFormData, + chartProps: EchartsMixedTimeseriesProps, ): EchartsMixedTimeseriesChartTransformedProps { const { width, @@ -76,9 +77,9 @@ export default function transformProps( } = chartProps; const { annotation_data: annotationData_ } = queriesData[0]; const annotationData = annotationData_ || {}; - const extractedDataSource = datasource || {}; - const data1: TimeseriesDataRecord[] = queriesData[0].data || []; - const data2: TimeseriesDataRecord[] = queriesData[1].data || []; + const { verboseMap = {} } = datasource; + const data1 = (queriesData[0].data || []) as TimeseriesDataRecord[]; + const data2 = (queriesData[1].data || []) as TimeseriesDataRecord[]; const { area, @@ -129,11 +130,11 @@ export default function transformProps( }: EchartsMixedTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); - const rebasedDataA = rebaseTimeseriesDatum(data1, extractedDataSource); + const rebasedDataA = rebaseTimeseriesDatum(data1, verboseMap); const rawSeriesA = extractTimeseriesSeries(rebasedDataA, { fillNeighborValue: stack ? 0 : undefined, }); - const rebasedDataB = rebaseTimeseriesDatum(data2, extractedDataSource); + const rebasedDataB = rebaseTimeseriesDatum(data2, verboseMap); const rawSeriesB = extractTimeseriesSeries(rebasedDataB, { fillNeighborValue: stackB ? 0 : undefined, });