chart = {
const zoom = d3.zoom()
.scaleExtent([0.5, 32])
.on("zoom", zoomed);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const gGrid = svg.append("g");
const gDot = svg.append("g")
.attr("fill", "none")
.attr("stroke-linecap", "round");
gDot.selectAll("path")
.data(data)
.join("path")
.attr("d", d => `M${x(d[0])},${y(d[1])}h0`)
.attr("stroke", d => z(d[2]));
const gx = svg.append("g");
const gy = svg.append("g");
svg.call(zoom).call(zoom.transform, d3.zoomIdentity);
function zoomed({transform}) {
const zx = transform.rescaleX(x).interpolate(d3.interpolateRound);
const zy = transform.rescaleY(y).interpolate(d3.interpolateRound);
gDot.attr("transform", transform).attr("stroke-width", 5 / transform.k);
gx.call(xAxis, zx);
gy.call(yAxis, zy);
gGrid.call(grid, zx, zy);
}
return Object.assign(svg.node(), {
reset() {
svg.transition()
.duration(750)
.call(zoom.transform, d3.zoomIdentity);
}
});
}