Fill series before stroking

This commit is contained in:
2024-05-06 17:27:07 +01:00
parent 62de8ccafa
commit e7b178279e

View File

@@ -89,24 +89,34 @@ export const CanvasChart = ({ total, hueOffset = 0, domain, hardDomain, data, fo
ctx.lineCap = 'round'; ctx.lineCap = 'round';
ctx.lineJoin = 'round'; ctx.lineJoin = 'round';
for (let i = 0; i < total; i++) { const drawSeries = (type: 'fill' | 'stroke') => {
ctx.fillStyle = getFillColor(hueOffset + (360 * Number(i)) / total); for (let i = 0; i < total; i++) {
ctx.strokeStyle = getStrokeColor(hueOffset + (360 * Number(i)) / total); if (type === 'fill') ctx.fillStyle = getFillColor(hueOffset + (360 * Number(i)) / total);
ctx.beginPath(); if (type === 'stroke') ctx.strokeStyle = getStrokeColor(hueOffset + (360 * Number(i)) / total);
ctx.moveTo(-xMargin, height);
ctx.lineTo(-xMargin, height - (height * (history[0][1][i] ?? 0)) / max.current);
for (const [timestamp, values] of history) {
const x = xFromTimestamp(timestamp, width);
const y = height - (height * (values[i] ?? 0)) / max.current;
ctx.lineTo(x, y); ctx.beginPath();
ctx.moveTo(-xMargin, height);
ctx.lineTo(-xMargin, height - (height * (history[0][1][i] ?? 0)) / max.current);
for (const [timestamp, values] of history) {
const x = xFromTimestamp(timestamp, width);
const y = height - (height * (values[i] ?? 0)) / max.current;
ctx.lineTo(x, y);
}
ctx.lineTo(width + xMargin, height - (height * (history[0][1][i] ?? 0)) / max.current);
ctx.lineTo(width + xMargin, height);
if (type === 'fill') ctx.fill();
if (type === 'stroke') ctx.stroke();
ctx.closePath();
} }
ctx.lineTo(width + xMargin, height - (height * (history[0][1][i] ?? 0)) / max.current); };
ctx.lineTo(width + xMargin, height);
ctx.stroke(); drawSeries('fill');
ctx.fill(); drawSeries('stroke');
ctx.closePath();
}
}, fps); }, fps);
return ( return (