fix(dashboard): guard customTooltip plugin against undefined tooltip and missing Y scale
Some checks failed
CI / Check (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Formatting (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Release Build (push) Has been cancelled

chart.tooltip is undefined during initial draw for radial chart types
(doughnut/pie), and chart.scales.y doesn't exist on non-cartesian charts.
This crashed chart creation, causing 'Failed to load' messages on all pages.
This commit is contained in:
2026-03-02 13:49:37 -05:00
parent 2212f0b736
commit fbd3751102

View File

@@ -26,11 +26,14 @@ class ChartManager {
} }
registerPlugins() { registerPlugins() {
// Register a plugin for tooltip background // Register a plugin that draws a vertical dashed line at the active tooltip point.
// Only applies to charts with a cartesian Y scale (line, bar) — skip radial types.
Chart.register({ Chart.register({
id: 'customTooltip', id: 'customTooltip',
beforeDraw: (chart) => { beforeDraw: (chart) => {
if (chart.tooltip._active && chart.tooltip._active.length) { if (!chart.tooltip || !chart.tooltip._active || !chart.tooltip._active.length) return;
if (!chart.scales.y) return; // no cartesian Y axis (pie/doughnut)
const ctx = chart.ctx; const ctx = chart.ctx;
const activePoint = chart.tooltip._active[0]; const activePoint = chart.tooltip._active[0];
const x = activePoint.element.x; const x = activePoint.element.x;
@@ -47,7 +50,6 @@ class ChartManager {
ctx.stroke(); ctx.stroke();
ctx.restore(); ctx.restore();
} }
}
}); });
} }