{
const context = DOM.context2d(width, height),
path = d3
.geoPath()
.context(context)
.pointRadius(3);
function render(i) {
context.clearRect(0, 0, width, height);
if (i === +i) {
context.fillStyle = "lime";
context.beginPath();
voronoi.renderCell(i, context);
context.fill();
const Y = true_neighbors(voronoi, i),
U = [...delaunay.neighbors(i)].filter(j => !Y.includes(j));
context.fillStyle = "yellow";
context.beginPath();
for (const j of U) voronoi.renderCell(j, context);
context.fill();
context.fillStyle = "#ccffcc";
context.beginPath();
for (const j of Y) voronoi.renderCell(j, context);
context.fill();
context.beginPath();
for (const j of delaunay.neighbors(i)) {
context.moveTo(...points[i]);
context.lineTo(...points[j]);
}
context.strokeStyle = "green";
context.stroke();
}
context.strokeStyle = "#000";
context.beginPath();
voronoi.render(context);
voronoi.renderBounds(context);
context.stroke();
context.fillStyle = "black";
context.beginPath();
path({ type: "MultiPoint", coordinates: points });
context.fill();
}
render(4);
return d3
.select(context.canvas)
.on("mousemove", function() {
const m = d3.mouse(this),
i = delaunay.find(...m);
render(i);
})
.node();
}