sparkline: fix subpixel rounding gaps between bars

This commit is contained in:
Damocles 2026-04-25 10:03:06 +02:00
parent 946c3a61d7
commit 85e62c6eeb

View file

@ -142,10 +142,12 @@ Canvas {
if (hasCF) if (hasCF)
ctx.fillStyle = colorFunction(d[i]).toString(); ctx.fillStyle = colorFunction(d[i]).toString();
const [bx, bw] = xOf(i); const [bx, bw] = xOf(i);
const x0 = Math.floor(bx);
const x1 = Math.floor(bx + bw);
const dy = yOf(d[i]); const dy = yOf(d[i]);
const barTop = Math.min(dy, zy); const barTop = Math.min(dy, zy);
const barH = Math.max(1, Math.abs(dy - zy)); const barH = Math.max(1, Math.abs(dy - zy));
ctx.fillRect(bx, barTop, Math.ceil(bw), barH); ctx.fillRect(x0, barTop, Math.max(1, x1 - x0), barH);
} }
} }
} }