I have an SVG that can be increased, as well as a reset button. I am resizing with
zoom.transform(selection, d3.zoomIdentity)
This works as expected and resets to SVG. But if I zoom in again, it will zoom in to the last state. For instance. I scroll, click the "reset" button, and then zoom out → the SVG image is enlarged. How can I reset to change the internal state of the zoom of an object zoom? Tried different solutions and none of them work.
Here is the full scaling code
var container = d3.select("#g5063")
var zoom = d3.zoom().
scaleExtent([0.7, 8]).
on("zoom", () => {
container.attr("transform", d3.event.transform)
})
$("#reset-zoom-button").click(() => {
zoom.transform(container, d3.zoomIdentity);
})
var svg = d3.select("#svg").call(zoom)
source
share