chart = {
replay;
const svg = d3.select(DOM.svg(width, height));
const duration = 500;
const delay = 2;
const newData = data.map((d,i)=>{
const xvalue = x(d.date);
const yvalue = y(d.value);
const sy = height - margin.bottom;
const sx = xvalue;
return {
x:xvalue,
y:yvalue,
sx:sx,
sy:sy,
cx:sx,
cy:sy
}
});
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
const path = svg.append("path")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
const timer = d3.timer(absT => {
if (absT > duration + delay * newData.length) {
timer.stop();
}
newData.forEach((d, i, a) => {
const elapsed = Math.min(duration, absT - delay * i);
if (elapsed < 0) return;
const t = d3.easeBackOut(elapsed / duration);
a[i].cx = d.sx + (d.x - d.sx) * t;
a[i].cy = d.sy + (d.y - d.sy) * t;
});
path.attr('d', line(newData));
});
return svg.node();
}