{
const svg = d3.create("svg").attr("width", width).attr("height", 500);
svg
.append("g")
.selectAll("circle")
.data(points)
.join("circle")
.attr("r", 2)
.attr("cx", (d) => d[0])
.attr("cy", (d) => d[1])
.attr("stroke", "black");
let pathLength;
svg
.append("path")
.attr("d", line(points))
.attr("fill", "none")
.attr("stroke", "dimgray")
.attr("stroke-width", 5)
.attr("stroke-opacity", 0.5)
.attr("stroke-dasharray", function () {
return (pathLength = this.getTotalLength());
})
.attr("stroke-dashoffset", pathLength)
.transition()
.duration(points.length * 500)
.on("start", function repeat() {
d3.active(this)
.attr("stroke-dashoffset", 0)
.transition()
.attr("stroke-dashoffset", pathLength)
.transition()
.on("start", repeat);
});
return svg.node();
}