d3 / d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.
https://d3js.org/d3-zoom
ISC License
507 stars 143 forks source link

Zoom event does not honor current transform state #238

Closed ashwinmr closed 3 years ago

ashwinmr commented 3 years ago

I was trying to maintain my own transform state and update it incrementally with zoom events. This was so that I can maintain a history of zoom states and switch between them (go back and next).

I was hoping to use the zoom event similar to the scaleBy and translateBy functions. This requires resetting the transform for the node at the end of each event. However, I noticed that when the event is fired again, the transform contained in e.transform does not care about the existing transform of the node. It gives a transform that keeps growing larger and larger.

I asked a question on here on stackoverflow. The answer works but is quite hacky.

Can the zoom event be made to honor the current zoom transform? Can the transform be reset without firing an event and creating an infinite loop?

Fil commented 3 years ago

Closing since I think it works as expected; however if you think this is a bug, please share minimal code that allows reproduction of the issue.