{
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
svg.append("g")
.attr("transform", `translate(50,800`)
.attr("stroke", "#000")
.attr("stroke-opacity", 0.2)
.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", d => x(d.date))
.attr("cy", d => y(d.value))
.attr("fill", d => z(d.value))
.attr("r", 4);
svg.append("path")
.datum(smoothdata)
.attr("fill", "none")
.attr("stroke", "#000")
.attr("stroke-width", 2)
.attr("stroke-linejoin", "round")
.attr("d", line);
const tooltip = svg.append("g");
svg.on("touchmove mousemove", function(event) {
const {date, value,text} = bisect(d3.pointer(event, this)[0]);
tooltip
.attr("transform", `translate(${x(date)},${y(value)})`)
.call(callout, `${text}
${formatDate(date)}`);
});
svg.on("touchend mouseleave", () => tooltip.call(callout, null));
return svg.node();
}