From b98358f79bf5026070bed56fd3c79911ceb2de15 Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Fri, 29 May 2026 11:22:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=80=91=E5=B8=83=E5=9B=BE=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8A=A8=E6=80=81=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=80=BC=E8=AE=A1=E7=AE=97=E5=8F=8A=E6=95=B0=E5=80=BC=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/g2/bar/waterfall.ts | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts index 0588d25990..5c18fe9278 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts @@ -398,14 +398,16 @@ export class Waterfall extends Bar { const newData = [] as Record[] let r = 0 data.forEach(d => { - const value = d[yField] ? d[yField] : null - newData.push({ ...d, [newYField]: [r, r + value] }) - r += value + const value = this.getNumberValue(d[yField]) + const current = value ?? 0 + newData.push({ ...d, [yField]: value, [newYField]: [r, r + current] }) + r += current }) if (newData.length && total) { const sum = newData[newData.length - 1][newYField][1] newData.push({ ...data[0], + dynamicTooltipValue: this.getTotalDynamicTooltipValue(data), [xField]: total.label, [yField]: sum, [newYField]: [0, sum] @@ -414,6 +416,41 @@ export class Waterfall extends Bar { return newData } + protected getNumberValue(value: any): number | null { + if (value === null || value === undefined) { + return null + } + if (typeof value === 'string' && value.trim() === '') { + return null + } + const numberValue = Number(value) + return Number.isFinite(numberValue) ? numberValue : null + } + + protected getTotalDynamicTooltipValue(data: Record[]): Record[] { + const dynamicTooltipValueMap = new Map & { hasValue: boolean }>() + data.forEach(d => { + d.dynamicTooltipValue?.forEach(item => { + const key = `${item.fieldId}` + const value = this.getNumberValue(item.value) + const current = dynamicTooltipValueMap.get(key) || { + ...item, + value: null, + hasValue: false + } + if (value !== null) { + current.value = (current.hasValue ? current.value : 0) + value + current.hasValue = true + } + dynamicTooltipValueMap.set(key, current) + }) + }) + return Array.from(dynamicTooltipValueMap.values()).map(({ hasValue, ...item }) => ({ + ...item, + value: hasValue ? item.value : null + })) + } + /** * 处理为 瀑布图 数据 * @param data