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");
var gDot = svg.selectAll("g.dot")
.data(data)
.enter().append('g');
gDot.append("circle")
.attr("class", "dot")
.attr("r", 4)
.attr("cx", function (d) {
return x(d[0]);
})
.attr("cy", function (d) {
return y(d[1]);
})
.style("fill", function (d) {
return z(d[2]);
});
gDot.append("text")
.attr("font-size", 12)
.text(function(d){
return d[3];
})
.attr("x", function (d) {
return x(d[0]);
})
.attr("y", function (d) {
return y(d[1]);
});
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);
}
});
}