From 63a13f01a9f535ee9d8af0a7f1838f2009765129 Mon Sep 17 00:00:00 2001 From: Stephen Liu <750188453@qq.com> Date: Thu, 2 Sep 2021 00:37:47 +0800 Subject: [PATCH] fix(plugin-chart-echarts): [feature-parity] display custom metrics (#1337) --- .../plugin-chart-echarts/src/Timeseries/transformProps.ts | 5 +++-- .../plugins/plugin-chart-echarts/src/utils/prophet.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index 138c2371ee250..a91cf42bb56a3 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -66,7 +66,8 @@ import { TIMESERIES_CONSTANTS } from '../constants'; export default function transformProps( chartProps: EchartsTimeseriesChartProps, ): TimeseriesChartTransformedProps { - const { width, height, filterState, formData, hooks, queriesData } = chartProps; + const { width, height, filterState, formData, hooks, queriesData, datasource } = chartProps; + const { verboseMap = {} } = datasource; const { annotation_data: annotationData_, data = [], @@ -105,7 +106,7 @@ export default function transformProps( }: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); - const rebasedData = rebaseTimeseriesDatum(data); + const rebasedData = rebaseTimeseriesDatum(data, verboseMap); const rawSeries = extractTimeseriesSeries(rebasedData, { fillNeighborValue: stack && !forecastEnabled ? 0 : undefined, }); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/utils/prophet.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/utils/prophet.ts index 2c23113864f78..1a34ead1031af 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/utils/prophet.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/plugin-chart-echarts/src/utils/prophet.ts @@ -90,7 +90,10 @@ export const formatProphetTooltipSeries = ({ return `${row.trim()}`; }; -export function rebaseTimeseriesDatum(data: TimeseriesDataRecord[]) { +export function rebaseTimeseriesDatum( + data: TimeseriesDataRecord[], + verboseMap: Record = {}, +) { const keys = data.length > 0 ? Object.keys(data[0]) : []; // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -108,7 +111,8 @@ export function rebaseTimeseriesDatum(data: TimeseriesDataRecord[]) { ) { value -= row[lowerKey] as number; } - newRow[key] = value; + const newKey = key !== '__timestamp' && verboseMap[key] ? verboseMap[key] : key; + newRow[newKey] = value; }); // eslint-disable-next-line @typescript-eslint/no-unsafe-return return newRow;