Skip to content

Commit 1e4bc6e

Browse files
authored
fix: bug in tooltip timeseries chart in calculated total with annotation layer (#35179)
1 parent db178cf commit 1e4bc6e

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ import {
4747
isDerivedSeries,
4848
} from '@superset-ui/chart-controls';
4949
import type { EChartsCoreOption } from 'echarts/core';
50-
import type { LineStyleOption } from 'echarts/types/src/util/types';
50+
import type {
51+
LineStyleOption,
52+
CallbackDataParams,
53+
} from 'echarts/types/src/util/types';
5154
import type { SeriesOption } from 'echarts';
5255
import {
5356
EchartsTimeseriesChartProps,
@@ -575,16 +578,31 @@ export default function transformProps(
575578
const xValue: number = richTooltip
576579
? params[0].value[xIndex]
577580
: params.value[xIndex];
578-
const forecastValue: any[] = richTooltip ? params : [params];
581+
const forecastValue: CallbackDataParams[] = richTooltip
582+
? params
583+
: [params];
579584
const sortedKeys = extractTooltipKeys(
580585
forecastValue,
581586
yIndex,
582587
richTooltip,
583588
tooltipSortByMetric,
584589
);
590+
const filteredForecastValue = forecastValue.filter(
591+
(item: CallbackDataParams) =>
592+
!annotationLayers.some(
593+
(annotation: AnnotationLayer) =>
594+
item.seriesName === annotation.name,
595+
),
596+
);
585597
const forecastValues: Record<string, ForecastValue> =
586598
extractForecastValuesFromTooltipParams(forecastValue, isHorizontal);
587599

600+
const filteredForecastValues: Record<string, ForecastValue> =
601+
extractForecastValuesFromTooltipParams(
602+
filteredForecastValue,
603+
isHorizontal,
604+
);
605+
588606
const isForecast = Object.values(forecastValues).some(
589607
value =>
590608
value.forecastTrend || value.forecastLower || value.forecastUpper,
@@ -595,7 +613,7 @@ export default function transformProps(
595613
: (getCustomFormatter(customFormatters, metrics) ?? defaultFormatter);
596614

597615
const rows: string[][] = [];
598-
const total = Object.values(forecastValues).reduce(
616+
const total = Object.values(filteredForecastValues).reduce(
599617
(acc, value) =>
600618
value.observation !== undefined ? acc + value.observation : acc,
601619
0,
@@ -617,7 +635,16 @@ export default function transformProps(
617635
seriesName: key,
618636
formatter,
619637
});
620-
if (showPercentage && value.observation !== undefined) {
638+
639+
const annotationRow = annotationLayers.some(
640+
item => item.name === key,
641+
);
642+
643+
if (
644+
showPercentage &&
645+
value.observation !== undefined &&
646+
!annotationRow
647+
) {
621648
row.push(
622649
percentFormatter.format(value.observation / (total || 1)),
623650
);

0 commit comments

Comments
 (0)