Description
Hello,
Situation
With updates 3.5.0 and 3.5.1 the behavior following a zoom action caused by the mousewheel was changed.
In 3.4.1: Every zoom action also triggered the onPan callback.
In 3.5.1: Every zoom action triggers the beforePancallback. If the beforePan callback changes the resultPan (resultPan !== newPan) then also the onPan callback is called.
The change leads to a better distinction between zoom and pan. But the interface for the users of svg-pan-zoom does not complete separate a zoom action and a pan action.
Feature Request
Problem:
This results in 2 possible procedures:
- A zoom action, which does not change the
resultPaninbeforePan(resultPan === newPan) has the following procedure:
beforeZoom->onZoom->beforePan- In this case the
onZoomcallback needs to notify another component in my application and give the resulting viewport (x,y, and scale) to it.
- A zoom action, which does change the
resultPaninbeforePan(resultPan !== newPan) has the following procedure:
beforeZoom->onZoom->beforePan->onPan- In this case the
onZoomcallback should not notify the other component in my application and should not give it the resulting viewport to it. Because theonPanhas not happend yet, and thebeforePanwhich changes theresultPanhas not adjusted anything yet. TheonPancallback does notify and transmit the new viewport to the other component (because it has to for actions that only pan) so it works, but the notification insideonZoombecomes obsolete, and should not be send at all.
My problem now is that I do not see any way to determine whether the onPan will be called while the onZoom callback is being executed.
Proposal:
A zoom action triggered by the mousewheel only triggers beforeZoom and onZoom, but in no case calls beforePan and onPan.
The necessary panning, that has to happen when zooming, would have to be handled completely internally by svg-pan-zoom, without triggering beforePan.
In order to be able to adjust coordinates when a zoom action happens the beforeZoom callback would also take the oldPan and newPan arguments.
So:
beforeZoom(oldZoom, newZoom)would change tobeforeZoom(oldZoom, newZoom, oldPan, newPan)zoomitself would take the adjusted coordinates frombeforeZoomandonZoom(newZoom)would change toonZoom(newZoom, newPan).
Reasons for adopting new feature:
The change would result in a more intuitive and cleaner interface.
- The user of svg-pan-zoom expects the
beforePanandonPancallbacks to trigger when a pan action is done. (This is the case at this moment.) - The user of svg-pan-zoom expects the
beforeZoomandonZoomcallbacks to trigger when a zoom action is done. (This is not the case at the moment.)
Breaking Change:
This is a breaking change, since it would change the interface of the library for the zoom actions.
- Instead of exposing the necessary pan action to the user of svg-pan-zoom through the
beforePan(oldPan, newPan)callback, it would now expose the pan action included in the newbeforeZoom(oldZoom, newZoom, oldPan, newPan)callback. - Instead of triggering
onPan(newPan)if necessary (depending on the 'before-callback'), svg-pan-zoom would now handle the panning internally and trigger the newonZoom(newZoom, newPan)callback.
In 3.5.1, software using svg-pan-zoom probably relys on beforePan to be triggered by a zoom action, as they probably relied on 'onPan' being triggered on a zoom action in 3.4.1.
With the proposed change beforePan and onPan callbacks would not be triggered anymore on a zoom action, thus breaking existing software.
I hope the intention is clear.