chart = {
const zoom = d3
.zoom()
.scaleExtent([1, 32])
.extent([[margin.left, 0], [width - margin.right, height]])
.translateExtent([
[margin.left, -Infinity],
[width - margin.right, Infinity]
])
.on("zoom", zoomed);
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visible");
const gx = svg.append("g").call(xAxis, x);
const gy = svg.append("g").call(yAxis, y);
const path = svg
.append("g")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.selectAll("path")
.data(data.series)
.join("path")
.style("mix-blend-mode", "multiply")
.attr("d", d => line(d.values, x, y));
function zoomed(event) {
const xz = event.transform.rescaleX(x);
const yz = event.transform.rescaleY(y);
xcopy.domain(xz.domain());
ycopy.domain(yz.domain());
path.attr("d", d => line(d.values, xz, yz));
const pointer = d3.pointer(event, this);
if (event.sourceEvent.type === "mousemove") {
highlightPoint(pointer, svg, path);
}
gx.call(xAxis, xz);
gy.call(yAxis, yz);
}
svg.call(hover, path);
svg.call(zoom);
return svg.node();
}