Skip to content

Commit 24eaa67

Browse files
arteria32ARTer1a
andauthored
fix(Waterfall): fix calculation of yValue for total item (#297)
Co-authored-by: Denis Ryabko <[email protected]>
1 parent c68e8a0 commit 24eaa67

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed
5.47 KB
Loading

src/__tests__/waterfall.visual.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'src/__stories__/__data__';
1010

1111
import {ChartTestStory} from '../../playwright/components/ChartTestStory';
12+
import type {ChartData, WaterfallSeriesData} from '../types';
1213

1314
test.describe('Waterfall series', () => {
1415
test('Basic', async ({mount}) => {
@@ -36,4 +37,33 @@ test.describe('Waterfall series', () => {
3637
const component = await mount(<ChartTestStory data={waterfallNullModeZeroData} />);
3738
await expect(component.locator('svg')).toHaveScreenshot();
3839
});
40+
41+
test('With multiple total columns', async ({mount}) => {
42+
const dataWithTotals: WaterfallSeriesData[] = [
43+
{x: 'A', y: 10},
44+
{x: 'Total1', y: 0, total: true},
45+
{x: 'D', y: 25},
46+
{x: 'Total2', y: 0, total: true},
47+
];
48+
49+
const waterfallDataWithTotals: ChartData = {
50+
series: {
51+
data: [
52+
{
53+
type: 'waterfall',
54+
name: 'Series',
55+
data: dataWithTotals,
56+
nullMode: 'skip',
57+
},
58+
],
59+
},
60+
xAxis: {
61+
type: 'category',
62+
categories: dataWithTotals.map((d) => d.x) as string[],
63+
},
64+
};
65+
66+
const component = await mount(<ChartTestStory data={waterfallDataWithTotals} />);
67+
await expect(component.locator('svg')).toHaveScreenshot();
68+
});
3969
});

src/hooks/useShapes/waterfall/prepare-data.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ export const prepareWaterfallData = async (args: {
139139
continue;
140140
}
141141

142-
if (!item.data.total) {
142+
if (item.data.total) {
143+
item.data.y = totalValue;
144+
} else {
143145
totalValue += Number(item.data.y);
144146
}
145147

0 commit comments

Comments
 (0)