bumbu/svg-pan-zoom

Further separate zoom and pan interface.

Open

#254 opened on Jul 3, 2017

View on GitHub
 (3 comments) (3 reactions) (0 assignees)JavaScript (1,585 stars) (383 forks)batch import
enhancementhelp wanted

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:

  1. A zoom action, which does not change the resultPan in beforePan (resultPan === newPan) has the following procedure:
  • beforeZoom -> onZoom -> beforePan
  • In this case the onZoom callback needs to notify another component in my application and give the resulting viewport (x,y, and scale) to it.
  1. A zoom action, which does change the resultPan in beforePan (resultPan !== newPan) has the following procedure:
  • beforeZoom -> onZoom -> beforePan -> onPan
  • In this case the onZoom callback should not notify the other component in my application and should not give it the resulting viewport to it. Because the onPan has not happend yet, and the beforePan which changes the resultPan has not adjusted anything yet. The onPan callback 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 inside onZoom becomes 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 to beforeZoom(oldZoom, newZoom, oldPan, newPan)
  • zoom itself would take the adjusted coordinates from beforeZoom and onZoom(newZoom) would change to onZoom(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 beforePan and onPan callbacks to trigger when a pan action is done. (This is the case at this moment.)
  • The user of svg-pan-zoom expects the beforeZoom and onZoom callbacks 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 new beforeZoom(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 new onZoom(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.

Contributor guide