{
const canvas = DOM.canvas(width, width);
const ctx = canvas.getContext("2d");
const x = d3.scaleLinear().domain(d3.extent(wider)).range([0, width]);
let i = 0;
ctx.strokeStyle = "gray";
ctx.strokeWidth = 0.5;
for (const [a, b, d] of tree) {
ctx.beginPath();
ctx.moveTo(x(wider[a * 2]), x(wider[a * 2 + 1]));
ctx.lineTo(x(wider[b * 2]), x(wider[b * 2 + 1]));
ctx.stroke();
i++;
if (i % 100000 === 0) {
yield canvas;
}
}
function randcol() {
return Math.floor(Math.random() * 255);
}
ctx.globalAlpha = 1;
for (const cluster of clusters) {
if (Math.random() < 0.001) {
yield canvas;
}
ctx.fillStyle = `rgb(${randcol()},${randcol()},${randcol()})`;
for (const seed of cluster) {
const c = wider.slice(seed * 2, seed * 2 + 2).map((d) => x(d));
if (c.length === 2) {
ctx.fillRect(
...wider.slice(seed * 2, seed * 2 + 2).map((d) => x(d)),
1,
1
);
}
}
}
yield canvas;
}