viewof chart = {
replay;
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const gradient = DOM.uid();
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg
.append("linearGradient")
.attr("id", gradient.id)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", 0)
.attr("y1", height - margin.bottom)
.attr("x2", 0)
.attr("y2", margin.top)
.selectAll("stop")
.data(d3.ticks(0, 1, 10))
.join("stop")
.attr("offset", d => d)
.attr("stop-color", color.interpolator());
const serie = svg
.append("g")
.selectAll("g")
.data(series)
.join("g");
serie
.append("path")
.attr("fill", "none")
.attr("stroke", d => z(d[0].key))
.attr("stroke-width", 1.5)
.attr(
"d",
d3
.line()
.x(d => x(d.date))
.y(d => y(d.value))
);
serie
.append("path")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("stroke-linecap", "round")
.attr("stroke-linejoin", "round")
.attr("text-anchor", "middle")
.selectAll("text")
.data(d => d);
svg
.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", gradient)
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line)
.call(transition);
const tooltip = svg.append("g");
svg.on("touchmove mousemove", function() {
const { date, value } = bisect(d3.mouse(this)[0]);
tooltip.attr("transform", `translate(${x(date)},${y(value)})`).call(
callout,
`${value.toLocaleString(undefined, {
style: "currency",
currency: "USD"
})}
${date.toLocaleString(undefined, {
month: "short",
day: "numeric",
year: "numeric"
})}`
);
});
svg.on("touchend mouseleave", () => tooltip.call(callout, null));
return svg.node();
}