Skip to content

Commit

Permalink
fix(plugin-chart-echarts): [feature-parity] display custom metrics (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ authored and zhaoyongjie committed Nov 25, 2021
1 parent 12bd8f6 commit 63a13f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
Expand Down Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export const formatProphetTooltipSeries = ({
return `${row.trim()}`;
};

export function rebaseTimeseriesDatum(data: TimeseriesDataRecord[]) {
export function rebaseTimeseriesDatum(
data: TimeseriesDataRecord[],
verboseMap: Record<string, string> = {},
) {
const keys = data.length > 0 ? Object.keys(data[0]) : [];

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Expand All @@ -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;
Expand Down

0 comments on commit 63a13f0

Please sign in to comment.