d3-xyzoom | zoom adding several features | Media library
kandi X-RAY | d3-xyzoom Summary
kandi X-RAY | d3-xyzoom Summary
Fork of d3-zoom adding several features by separating scaling on x and y
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Loops through mouse wheel events .
- touchstart event handler
- Makes a mouse position .
- touch start event handler
- Create a transition handler .
- the touchend event handler
- Returns the default dimensions of the element .
- ZoZoom .
- Mouse click handler
- Convert an extent to an axis .
d3-xyzoom Key Features
d3-xyzoom Examples and Code Snippets
Community Discussions
Trending Discussions on d3-xyzoom
QUESTION
I'm hoping to configure the zoom behavior of a plot to have three kinds of interaction:
- It should be possible to pan from left to right with the scroll wheel.
- It should be possible to pan from left to right with mousedown drag events.
- it should be possible to zoom in 1-D with the pinch event (i.e. scroll wheel with control key pressed).
Right now, I can get the latter two to work in this Fiddle: https://jsfiddle.net/s1t7mrpw/6/
The zoomed function looks like this:
...ANSWER
Answered 2019-May-31 at 20:27I am using d3-zoom on this answer as it is more common and part of the d3 bundle. d3-xyzoom, as an add-on module, adds some useful functionality using d3-zoom as a base, so this solution should work with xyzoom with minor revisions - but I don't believe its use is necessary
The key challenge lies in using the wheel to apply a translate change not a scale change. Roughly speaking, when a scroll event without control occurs you grab the transform on the selection (this should be the node) and update it by taking the scroll and creating an x offset from it to translate the view rectangle. But, you don't update the zoomTransform to nullify the change in scale caused by the zoom - so when you pan by dragging, the rectangle changes size because you haven't updated the zoomTransform used by the zoom behavior. Likewise, the translate can be off if it doesn't account for scale.
The disassociation between zoom transform applied to an element as a "transform" attribute and the zoom transform tracked by the zoom behavior is the cause of many headaches on SO - but it allows freer implementation options as one not need use an element's transform attribute to apply a zoom behavior (useful in canvas, zooming unorthodox things like color, etc).
I'm going to propose a basic solution here.
First, the zoom transform tracked by the zoom behavior can be updated by modifying the d3.event.transform
object itself (or with d3.zoomTransform(selection.node)
where selection is the selection that the zoom was called on originally).
Secondly, as the d3.event.transform
object registers scrolling as scaling, we need to override this and convert this scaling into translating - when needed. To do so, we need to keep track of the current (pre-event) translate and scale - so we can modify them manually:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install d3-xyzoom
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page