fix(reporting): show scenario bars for EPC bands absent from the baseline

The breakdown chart looped only over baseline bands (epcBands), which the
query returns only for bands that have properties. So a band reached ONLY
after the scenario — e.g. A/B when no property starts that high — had no
row, and its scenario bar never rendered (portfolio 812: scenario yields
7 A + 2 B, baseline has none). Iterate a canonical A–G+Unknown order over
baseline ∪ scenario instead, so post-scenario-only bands still appear.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-06-26 11:25:45 +00:00
parent 7de48448c0
commit eef9fdc171

View file

@ -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,
});