diff --git a/src/app/portfolio/[slug]/(portfolio)/reporting/BreakdownChart.tsx b/src/app/portfolio/[slug]/(portfolio)/reporting/BreakdownChart.tsx index 9b660ed0..976ecdec 100644 --- a/src/app/portfolio/[slug]/(portfolio)/reporting/BreakdownChart.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/reporting/BreakdownChart.tsx @@ -51,15 +51,27 @@ export function BreakdownChart({ const rows: any[] = []; - for (const d of epcBands) { - const epc = d.epc ?? "Unknown"; + // The baseline query only returns bands that have properties, so a band + // reached ONLY after the scenario (e.g. A/B when nothing starts that high) + // is absent from epcBands — looping it alone drops those scenario bars. + // Iterate a canonical order over baseline ∪ scenario instead. + const baselineByBand = new Map( + epcBands.map((d) => [d.epc ?? "Unknown", d]), + ); + const BAND_ORDER = ["A", "B", "C", "D", "E", "F", "G", "Unknown"]; + const presentBands = BAND_ORDER.filter( + (b) => baselineByBand.has(b) || (scenarioEpcBands?.[b] ?? 0) > 0, + ); + + for (const epc of presentBands) { + const d = baselineByBand.get(epc); const scenarioValue = scenarioEpcBands?.[epc] ?? 0; // Baseline (stacked) rows.push({ label: `${epc}`, - [friendlyKeys.actual]: d.actual ?? 0, - [friendlyKeys.estimated]: d.estimated ?? 0, + [friendlyKeys.actual]: d?.actual ?? 0, + [friendlyKeys.estimated]: d?.estimated ?? 0, [friendlyKeys.scenario]: 0, });