Skip to content

Commit 657cfe9

Browse files
authored
Merge pull request #864 from PolicyEngine/fix/waterfall-negative-values
Fix waterfall chart negative bar labels
2 parents e359bfd + 9845a2e commit 657cfe9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

app/src/components/charts/WaterfallChart.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export function WaterfallChart({
120120
const y = props.y as number;
121121
const w = props.width as number;
122122
const h = props.height as number;
123-
const value = props.value as number;
123+
// Use the datum's value, not props.value — Recharts gives the
124+
// cumulative stack-top for stacked bars, which is wrong for labels.
125+
const datum = data[idx];
124126

125127
// Store this bar's pixel rect for the next bar's connector
126128
barPositions[idx] = { x, y, width: w, height: h };
@@ -137,7 +139,7 @@ export function WaterfallChart({
137139

138140
const barHeight = Math.abs(h);
139141
const showLabel = showBarLabels && barHeight >= 20;
140-
const text = barLabelFormatter ? barLabelFormatter(value) : String(value);
142+
const text = barLabelFormatter ? barLabelFormatter(datum.value) : datum.label;
141143

142144
return (
143145
<g>

0 commit comments

Comments
 (0)