mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix: bug in tooltip timeseries chart in calculated total with annotation layer (#35179)
This commit is contained in:
@@ -47,7 +47,10 @@ import {
|
||||
isDerivedSeries,
|
||||
} from '@superset-ui/chart-controls';
|
||||
import type { EChartsCoreOption } from 'echarts/core';
|
||||
import type { LineStyleOption } from 'echarts/types/src/util/types';
|
||||
import type {
|
||||
LineStyleOption,
|
||||
CallbackDataParams,
|
||||
} from 'echarts/types/src/util/types';
|
||||
import type { SeriesOption } from 'echarts';
|
||||
import {
|
||||
EchartsTimeseriesChartProps,
|
||||
@@ -575,16 +578,31 @@ export default function transformProps(
|
||||
const xValue: number = richTooltip
|
||||
? params[0].value[xIndex]
|
||||
: params.value[xIndex];
|
||||
const forecastValue: any[] = richTooltip ? params : [params];
|
||||
const forecastValue: CallbackDataParams[] = richTooltip
|
||||
? params
|
||||
: [params];
|
||||
const sortedKeys = extractTooltipKeys(
|
||||
forecastValue,
|
||||
yIndex,
|
||||
richTooltip,
|
||||
tooltipSortByMetric,
|
||||
);
|
||||
const filteredForecastValue = forecastValue.filter(
|
||||
(item: CallbackDataParams) =>
|
||||
!annotationLayers.some(
|
||||
(annotation: AnnotationLayer) =>
|
||||
item.seriesName === annotation.name,
|
||||
),
|
||||
);
|
||||
const forecastValues: Record<string, ForecastValue> =
|
||||
extractForecastValuesFromTooltipParams(forecastValue, isHorizontal);
|
||||
|
||||
const filteredForecastValues: Record<string, ForecastValue> =
|
||||
extractForecastValuesFromTooltipParams(
|
||||
filteredForecastValue,
|
||||
isHorizontal,
|
||||
);
|
||||
|
||||
const isForecast = Object.values(forecastValues).some(
|
||||
value =>
|
||||
value.forecastTrend || value.forecastLower || value.forecastUpper,
|
||||
@@ -595,7 +613,7 @@ export default function transformProps(
|
||||
: (getCustomFormatter(customFormatters, metrics) ?? defaultFormatter);
|
||||
|
||||
const rows: string[][] = [];
|
||||
const total = Object.values(forecastValues).reduce(
|
||||
const total = Object.values(filteredForecastValues).reduce(
|
||||
(acc, value) =>
|
||||
value.observation !== undefined ? acc + value.observation : acc,
|
||||
0,
|
||||
@@ -617,7 +635,16 @@ export default function transformProps(
|
||||
seriesName: key,
|
||||
formatter,
|
||||
});
|
||||
if (showPercentage && value.observation !== undefined) {
|
||||
|
||||
const annotationRow = annotationLayers.some(
|
||||
item => item.name === key,
|
||||
);
|
||||
|
||||
if (
|
||||
showPercentage &&
|
||||
value.observation !== undefined &&
|
||||
!annotationRow
|
||||
) {
|
||||
row.push(
|
||||
percentFormatter.format(value.observation / (total || 1)),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user