Skip to content

Commit 7a77b57

Browse files
committed
fix(admin): KeyViz canvas drops dead width>0 fallback (PR #684 r2)
Claude bot round-2 cosmetic nit: the width > 0 ternary in setTransform was never reachable in practice (the JSX only renders the canvas when matrix.rows.length > 0, which implies width > 0). Hoist the empty-matrix early return ahead of the transform call so the live path collapses to a single ctx.setTransform expression.
1 parent b10a0ae commit 7a77b57

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

web/admin/src/pages/KeyViz.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,21 @@ function Heatmap({ matrix }: HeatmapProps) {
140140
canvas.height = Math.max(1, Math.floor(height * dpr));
141141
const ctx = canvas.getContext("2d");
142142
if (!ctx) return;
143+
if (matrix.rows.length === 0 || matrix.column_unix_ms.length === 0) {
144+
// Nothing to draw — reset the transform on the off-chance the
145+
// canvas was reused between renders, then clear and bail.
146+
ctx.setTransform(1, 0, 0, 1, 0, 0);
147+
ctx.clearRect(0, 0, canvas.width, canvas.height);
148+
return;
149+
}
143150
// Use the buffer/logical ratio as the transform so a fractional
144151
// DPR (1.25x, 1.5x) maps logical coordinates exactly onto the
145152
// floored buffer. Setting the transform from the raw `dpr`
146153
// could draw at a fractional pixel that the buffer cannot
147154
// represent, leaving sub-pixel blur at the edges. setTransform
148155
// also resets the matrix so repeated runs do not stack scales.
149-
const sx = width > 0 ? canvas.width / width : dpr;
150-
const sy = height > 0 ? canvas.height / height : dpr;
151-
ctx.setTransform(sx, 0, 0, sy, 0, 0);
156+
ctx.setTransform(canvas.width / width, 0, 0, canvas.height / height, 0, 0);
152157
ctx.clearRect(0, 0, width, height);
153-
if (matrix.rows.length === 0 || matrix.column_unix_ms.length === 0) return;
154158

155159
// One fillRect per cell keeps render under the §10 budget at
156160
// 1024 x 500: the colour ramp runs once per cell rather than per

0 commit comments

Comments
 (0)