feat: show total in waterfall chart (#35876)

This commit is contained in:
SBIN2010
2025-10-29 20:25:56 +03:00
committed by GitHub
parent 99b61143f6
commit 48ee0821d3
4 changed files with 151 additions and 108 deletions

View File

@@ -129,6 +129,18 @@ const config: ControlPanelConfig = {
{t('Series total setting')}
</ControlSubSectionHeader>,
],
[
{
name: 'show_total',
config: {
type: 'CheckboxControl',
label: t('Show total'),
renderTrigger: true,
default: true,
description: t('Display cumulative total at end'),
},
},
],
[
{
name: 'total_color',

View File

@@ -94,12 +94,14 @@ function transformer({
metric,
breakdown,
totalMark,
showTotal,
}: {
data: DataRecord[];
xAxis: string;
metric: string;
breakdown?: string;
totalMark: string;
showTotal: boolean;
}) {
// Group by series (temporary map)
const groupedData = data.reduce((acc, cur) => {
@@ -121,11 +123,13 @@ function transformer({
0,
);
// Push total per period to the end of period values array
tempValue.push({
[xAxis]: key,
[breakdown]: totalMark,
[metric]: sum,
});
if (showTotal) {
tempValue.push({
[xAxis]: key,
[breakdown]: totalMark,
[metric]: sum,
});
}
transformedData.push(...tempValue);
});
} else {
@@ -141,10 +145,12 @@ function transformer({
});
total += sum;
});
transformedData.push({
[xAxis]: totalMark,
[metric]: total,
});
if (showTotal) {
transformedData.push({
[xAxis]: totalMark,
[metric]: total,
});
}
}
return transformedData;
@@ -183,6 +189,7 @@ export default function transformProps(
xAxisLabel,
yAxisFormat,
showValue,
showTotal,
totalLabel,
increaseLabel,
decreaseLabel,
@@ -220,6 +227,7 @@ export default function transformProps(
xAxis: xAxisName,
metric: metricLabel,
totalMark,
showTotal,
});
const assistData: ISeriesData[] = [];

View File

@@ -60,6 +60,7 @@ export type EchartsWaterfallFormData = QueryFormData &
increaseLabel?: string;
decreaseLabel?: string;
totalLabel?: string;
showTotal: boolean;
};
export const DEFAULT_FORM_DATA: Partial<EchartsWaterfallFormData> = {