I have a SVG which can be zoomed and also a "reset" button. I'm resetting the zoom with
zoom.transform(selection, d3.zoomIdentity)
This works as expected and resets the zoom on the SVG. But if I zoom again, it zooms back to the last state. E.g. I scroll in, press "reset" button and then zoom out -> SVG is zoomed in. How can I reset the internal zoom state of the zoom object? Tried out different solutions and none of them works.
Here the full zoom code
//zoom cannot be done on the <svg> directly
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)