{
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
var path = svg.append("path")
.attr("d", line(data))
.attr("fill", "none")
.attr("stroke-width", 2)
.attr("stroke", "darkgrey");
var text = svg.append("text")
.text("stroke-dashoffset: " + dashOffset)
.attr("x", margin.left)
.attr("y", height - 10)
.attr("font-family", "monospace");
const length = path.node().getTotalLength();
function repeat() {
path.attr("stroke-dasharray", length + " " + length)
.attr("stroke-dashoffset", length)
.transition()
.ease(d3.easeLinear)
.attr("stroke-dashoffset", 0)
.duration(6000)
.on("end", () => setTimeout(repeat, 1000));
text.transition()
.duration(6000)
.tween("text", function(t) {
const i = d3.interpolateRound(0, length);
return function(t) {
this.textContent = "stroke-dashoffset: " + i(t);
};
});
};
repeat();
return svg.node();
}