Skip to content

Commit ab2b845

Browse files
committed
fix(frontend): route dashboard chart tooltips through formatCurrency
dashboard.ts's Chart.js tooltip and axis-tick callbacks built dollar strings by hand with `$${x.toLocaleString()}`, six occurrences across two charts. Same unpinned-locale defect as formatCurrency() before the previous commit -- these fell back to the host locale too -- but the deeper issue was duplication: dashboard.ts already imports formatCurrency from utils.ts and uses it elsewhere in the same file, so these six were reinventing it inline instead of calling it. Routes all six through the shared helper. Mechanical: each site formats a guaranteed-finite number (never null/undefined) with no fraction digits and a literal '$' prefix, exactly formatCurrency's default signature, so the change is a straight substitution with no behavior difference beyond the locale fix itself. These call sites render into a Chart.js <canvas>, not the DOM, so no existing test exercises them and none are being added here -- the change is verified by tsc, eslint, and the full suite passing under both locales, not by new coverage of previously-untested chart code.
1 parent 68d2135 commit ab2b845

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎frontend/src/dashboard.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ export function renderSavingsByService(
962962
// tooltip; the range datasets share the full breakdown.
963963
if (ctx.dataset?.label === 'Current / Committed') {
964964
const current = byService[svc]?.current_savings ?? 0;
965-
return `Current / Committed: $${current.toLocaleString()}`;
965+
return `Current / Committed: ${formatCurrency(current)}`;
966966
}
967967
const current = byService[svc]?.current_savings ?? 0;
968968
const maxRec = s?.max ?? 0;
@@ -973,10 +973,10 @@ export function renderSavingsByService(
973973
const pct = totalSavings > 0 ? ((total / totalSavings) * 100).toFixed(1) : '0.0';
974974
const lines = [
975975
`Service: ${svc}`,
976-
`Total: $${total.toLocaleString()} (${pct}% of all services)`,
977-
`Current / Committed: $${current.toLocaleString()}`,
978-
`Lowest option: $${lowestOption.toLocaleString()}`,
979-
`Upside: $${upside.toLocaleString()}`,
976+
`Total: ${formatCurrency(total)} (${pct}% of all services)`,
977+
`Current / Committed: ${formatCurrency(current)}`,
978+
`Lowest option: ${formatCurrency(lowestOption)}`,
979+
`Upside: ${formatCurrency(upside)}`,
980980
];
981981
if (s?.minLabel) lines.push(`Min option: ${s.minLabel}`);
982982
if (s?.maxLabel) lines.push(`Max option: ${s.maxLabel}`);
@@ -994,7 +994,7 @@ export function renderSavingsByService(
994994
stacked: true,
995995
beginAtZero: true,
996996
title: { display: true, text: 'Monthly savings ($)' },
997-
ticks: { callback: (v) => '$' + (v as number).toLocaleString() },
997+
ticks: { callback: (v) => formatCurrency(v as number) },
998998
},
999999
},
10001000
},
@@ -1131,7 +1131,7 @@ export async function loadSavingsTrendChart(): Promise<void> {
11311131
const raw = items[0]?.raw as { x: number; y: number } | undefined;
11321132
return raw?.x != null ? formatTrendAxisTick(raw.x, interval) : '';
11331133
},
1134-
label: (ctx) => `Cumulative savings: $${((ctx.raw as { x: number; y: number }).y).toLocaleString()}`,
1134+
label: (ctx) => `Cumulative savings: ${formatCurrency((ctx.raw as { x: number; y: number }).y)}`,
11351135
},
11361136
},
11371137
},
@@ -1147,7 +1147,7 @@ export async function loadSavingsTrendChart(): Promise<void> {
11471147
},
11481148
y: {
11491149
beginAtZero: true,
1150-
ticks: { callback: (v) => '$' + (v as number).toLocaleString() },
1150+
ticks: { callback: (v) => formatCurrency(v as number) },
11511151
},
11521152
},
11531153
},

0 commit comments

Comments
 (0)