chart = {
const xScale = d3.scaleLinear().domain([0, 1]).range([0, width]);
const yScale = d3.scaleLinear().domain([0, 1]).range([0, height]);
const rScale = d3.scaleLinear().domain([0, 1]).range([2, 5]);
const svg = d3.create("svg").attr("width", width).attr("height", height);
if (showPts) {
svg
.selectAll("circle")
.data(pts)
.join("circle")
.attr("class", "dot")
.attr("cx", (d) => xScale(d[0]))
.attr("cy", (d) => yScale(d[1]))
.attr("r", (d) => rScale(d[2]));
}
const delaunay = d3.Delaunay.from(
pts,
(d) => xScale(d[0]),
(d) => yScale(d[1])
);
const voronoi = delaunay.voronoi();
voronoi.xmax = width;
voronoi.ymax = height;
svg
.append("g")
.selectAll(".voronoi")
.data(pts)
.join("path")
.attr("class", "voronoi")
.attr("d", (d, i) => voronoi.renderCell(i))
.on("mouseenter", onMouseEnter)
.on("mouseleave", onMouseLeave);
function onMouseEnter(_, d) {
showPts &&
svg
.append("circle")
.attr("class", "dot--marker")
.attr("cx", xScale(d[0]))
.attr("cy", yScale(d[1]))
.attr("r", rScale(d[2]));
}
function onMouseLeave() {
svg.selectAll(".dot--marker").remove();
}
return svg.node();
}