This commit is contained in:
2026-05-10 15:14:21 +02:00
parent 04d1779e27
commit abab42ad0b
+9 -24
View File
@@ -259,36 +259,21 @@
// draw series
function drawLine(hist, color) {
const slice = hist.slice(-nPts).filter((v, i, a) => {
// fill nulls with neighbors for smoother rendering
return true;
});
const pts = slice.map((v, i) => ({ x: i * (W / (nPts - 1)), y: v === null ? null : toY(v) }));
const slice = hist.slice(-nPts);
const step = W / (nPts - 1);
ctx.strokeStyle = color;
ctx.lineWidth = 1.5;
ctx.beginPath();
let started = false;
for (let i = 0; i < pts.length; i++) {
if (pts[i].y === null) { started = false; continue; }
if (!started) { ctx.moveTo(pts[i].x, pts[i].y); started = true; continue; }
// cardinal spline control points
const p0 = pts[i - 2]?.y !== null ? pts[i - 2] : pts[i - 1];
const p1 = pts[i - 1];
const p2 = pts[i];
const p3 = pts[i + 1] ?? p2;
const tension = 0.4;
const cp1x = p1.x + (p2.x - p0.x) * tension / 2;
const cp1y = p1.y + (p2.y - p0.y) * tension / 2;
const cp2x = p2.x - (p3.x - p1.x) * tension / 2;
const cp2y = p2.y - (p3.y - p1.y) * tension / 2;
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, p2.x, p2.y);
for (let i = 0; i < slice.length; i++) {
if (slice[i] === null) { started = false; continue; }
const x = i * step;
const y = toY(slice[i]);
if (!started) { ctx.moveTo(x, y); started = true; }
else ctx.lineTo(x, y);
}
ctx.stroke();
// glow
ctx.strokeStyle = color + '44';
ctx.lineWidth = 4;
ctx.stroke();