d3-zoom | Pan and zoom SVG , HTML or Canvas using mouse or touch input | 3D Animation library

 by   d3 JavaScript Version: 3.0.0 License: ISC

kandi X-RAY | d3-zoom Summary

kandi X-RAY | d3-zoom Summary

d3-zoom is a JavaScript library typically used in User Interface, 3D Animation applications. d3-zoom has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can install using 'npm i d3-zoom-3' or download it from GitHub, npm.

Panning and zooming are popular interaction techniques which let the user focus on a region of interest by restricting the view. It is easy to learn due to direct manipulation: click-and-drag to pan (translate), spin the wheel to zoom (scale), or use touch. Panning and zooming are widely used in web-based mapping, but can also be used with visualizations such as time-series and scatterplots. The zoom behavior implemented by d3-zoom is a convenient but flexible abstraction for enabling pan-and-zoom on selections. It handles a surprising variety of input events and browser quirks. The zoom behavior is agnostic about the DOM, so you can use it with SVG, HTML or Canvas. The zoom behavior is also designed to work with d3-scale and d3-axis; see transform.rescaleX and transform.rescaleY. You can also restrict zooming using zoom.scaleExtent and panning using zoom.translateExtent. The zoom behavior can be combined with other behaviors, such as d3-drag for dragging, and d3-brush for focus + context. The zoom behavior can be controlled programmatically using zoom.transform, allowing you to implement user interface controls which drive the display or to stage animated tours through your data. Smooth zoom transitions are based on “Smooth and efficient zooming and panning” by Jarke J. van Wijk and Wim A.A. Nuij. See also d3-tile for examples panning and zooming maps.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              d3-zoom has a low active ecosystem.
              It has 415 star(s) with 139 fork(s). There are 19 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 13 open issues and 201 have been closed. On average issues are closed in 104 days. There are 4 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of d3-zoom is 3.0.0

            kandi-Quality Quality

              d3-zoom has 0 bugs and 0 code smells.

            kandi-Security Security

              d3-zoom has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              d3-zoom code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              d3-zoom is licensed under the ISC License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              d3-zoom releases are available to install and integrate.
              Deployable package is available in npm.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed d3-zoom and discovered the below as its top functions. This is intended to give you an instant insight into d3-zoom implemented functionality, and help decide if they suit your requirements.
            • Handle mouse events .
            • Mousedown or touchstart .
            • Simulates a touchend event .
            • Touchmove event handler .
            • Touchstart event handler .
            • Schedule new transition
            • Handle double click .
            • Default dimensions of the element
            • Positions the zoom event
            • The default limit for the extent .
            Get all kandi verified functions for this library.

            d3-zoom Key Features

            No Key Features are available at this moment for d3-zoom.

            d3-zoom Examples and Code Snippets

            No Code Snippets are available at this moment for d3-zoom.

            Community Discussions

            QUESTION

            D3 Bar Chart Zoom Not Centered
            Asked 2022-Feb-20 at 23:02

            I have a bar chart with zoom function. The issue is, the zooming isn't actually centered. If, I place the cursor, on a bar and zoom, the bar underneath the cursor moves away as opposed to staying there, However, if I set the MARGIN.LEFT = 0, then the issue is rectified and No matter what bar I have my cursor on, when I zoom the bar stays there, right underneath. Could anyone help me with this?

            Working Code Here: https://codesandbox.io/s/d3-zoom-not-centered-sfziyk

            D3 Code:

            ...

            ANSWER

            Answered 2022-Feb-20 at 23:02

            When you call the zoom on the svg, all zoom behaviour is relative to the svg.

            Imagine that your x-axis is at initial zoom level of length 100 representing the domain [0, 100]. So the x-scale has range([0, 100]) and domain([0, 100]). Add a left margin of 10.

            If you zoom by scale 2 at the midpoint of your axis at x=50 you would expect to get the following behaviour after the zoom:

            • The midpoint does not move.
            • The interval [25, 75] is visible.

            However, since the zoom is called on the svg you have to account for the left margin of 10. The zoom does not occur at the midpoint but at x = 10 + 50 = 60. The transform is thus x -> x * k + t with k = 2 and t = -60. This results in

            • x = 50 -> 2 * 50 - 60 = 40,
            • x = 80 -> 2 * 80 - 60 = 100,
            • x = 30 -> 2 * 30 - 60 = 0.

            Visible after the zoom is the interval [30, 80] and the point x = 50 is shifted to the left.

            This is what you observe in your chart.

            In order to get the expected behaviour, you can do two things:

            a. Follow the bar chart example where the range of the x-scale does not start at 0 but at the left margin. The g which is translated by margin.left and margin.top is also omitted here. Instead, the ranges of the axes incorporate the margins directly.

            b. Add a rect with fill: none; pointer-events: all; to the svg that is of the size of the chart without the margins. Then call the zoom on that rectangle, as done in this example.

            Note that all the new examples on ObservableHQ follow the pattern "a" that needs fewer markup.

            Source https://stackoverflow.com/questions/71193344

            QUESTION

            D3 zoom breaks mouse wheel zooming after using zoomIdentity
            Asked 2021-Nov-10 at 13:00

            When I use d3-zoom and programatically call the scaleTo function using zoomIdentity I cannot zoom using the mouse wheel anymore.

            How do I fix this issue?

            https://observablehq.com/d/8a5dfbc7d858a16b

            ...

            ANSWER

            Answered 2021-Nov-10 at 13:00

            The second parameter of zoom.scaleTo(svg, d3Zoom.zoomIdentity) accepts a k scaling factor (e.g., 2 for 2x zoom). The method zoom.scaleTo is intended to be used when you want to set the zoom level, but not the translation (x and y positions).

            If you want to set the whole transform to the zoom identity (which resets both the zoom level and the x and y positions), the method is zoom.transform(svg, d3Zoom.zoomIdentity).

            If you indeed just want to reset the scale, you can use zoom.scaleTo(svg, d3Zoom.zoomIdentity.k), or simply zoom.scaleTo(svg, 1).

            Source https://stackoverflow.com/questions/69911134

            QUESTION

            d3 zoom NaN in Firefox
            Asked 2021-Nov-09 at 02:37

            I have an app using d3 zoom that works in Chrome but not (for me) in Firefox. I've boiled the zoom issue down to the following very simple example:

            https://codesandbox.io/s/d3-zoom-error-in-firefox-mzid3

            ...

            ANSWER

            Answered 2021-Nov-09 at 02:37

            Turns out this was caused by an extension I had installed: https://addons.mozilla.org/en-US/firefox/addon/logitechsmoothscrolling/. Georgy's note that the demo worked for them caused me to look more closely at my particular Firefox profile. As that extension is 4 years old, and scrolling seems pretty smooth without it, I'm satisfied with removing the extension.

            Source https://stackoverflow.com/questions/69885132

            QUESTION

            SyntaxError: Unexpected token 'export' (d3zoom)
            Asked 2021-Oct-07 at 02:38

            I'm seeing errors in running tests in Angular:

            ...

            ANSWER

            Answered 2021-Oct-07 at 02:38

            Jest or whicheva test site u have it speaks javascript/commonjs not typescript/esmodules. What I mean is you need to use require if you want to write them tests with typescript install ts-node npm i -D ts-node but I think there is already a ts-jest package

            Source https://stackoverflow.com/questions/69474614

            QUESTION

            Convert d3v6 Observable example using zoom.center
            Asked 2021-Jul-28 at 13:58

            I have a project where I'm trying to zoom to specific points. In d3v3, I could do that with this function

            ...

            ANSWER

            Answered 2021-Jul-27 at 03:28

            There is no zoom.center in any d3-zoom release, from the first one to the current (v3.0.0 at the time of writing).

            That zoom.center method was created by that Observable's author, which actively contributes to D3 (see here). You can see the proposal here: https://github.com/d3/d3-zoom/pull/212

            However, if you inspect the code the author is using, you'll see that adding your own center method is not complicated. All you need is:

            Source https://stackoverflow.com/questions/68530758

            QUESTION

            Apply zoom to tooltip in D3 tree
            Asked 2021-Mar-19 at 23:11

            I'm trying to create a HTML tooltip that can be zoomed in and out with D3 zoom effect. I've managed to have it working partially, because the positioning of the tooltip is wrong, but it is being zoomed correctly.

            I've tried something similar to what has been said in this question, but without success.

            What do I need to do? I guess it's only a problem with the zoom event of the zoomBehaviours object, but I can't find the way to solve it.

            In the following snippet you can see what's the current state of the tooltip.

            ...

            ANSWER

            Answered 2021-Mar-19 at 23:11

            I finally made it with a simple modification of this question. The problem was that I was shifting the tooltip with a translate event that was not necessary. This would be the look of the code after the change. Notice that I only changed the zoom event of the zoomBehaviours object.

            Source https://stackoverflow.com/questions/66662973

            QUESTION

            Problems loading csv data with d3.js
            Asked 2020-Jul-31 at 05:48

            So I've been trying to implement this 2D visualization for my own project, and I'm having problems loading in CSV data instead of randomly generating points. My code is almost identical to the link above, except for this:

            ...

            ANSWER

            Answered 2020-Jul-31 at 01:46

            Solved my own problem funnily enough. Switched to d3 v5 and had no issues loading the data.

            Source https://stackoverflow.com/questions/63181512

            QUESTION

            d3-drag - rescale y-axis with drag in d3v5
            Asked 2020-Mar-01 at 06:59

            I'm trying to achieve the effect of rescaling the d3fc cartesian chart when the user drags along the axes.

            https://codepen.io/parliament718/pen/BaNQPXx

            This is in d3v5, and I'm using d3-zoom to re-scale the axes using d3.event.transform. However, in d3-drag there is no d3.event.transform so I don't understand what the equivelant logic would be using just the mouse coordinates that d3-drag provides.

            ...

            ANSWER

            Answered 2020-Mar-01 at 06:59

            You can create another zoom behavior which only changes the Y domain. Then, in the drag handler, call the new behavior's scaleBy on the plot area with a scale factor based on the drag event's delta Y:

            Source https://stackoverflow.com/questions/60355728

            QUESTION

            d3-zoom mouseup event workaround
            Asked 2020-Feb-17 at 06:26

            I'm aware that starting with v4 d3-zoom swallows up certain events for some reasons I don't fully understand. I've read some discussions about this, and I know that if I stopPropagation() on mousedown, then the zoom behavior won't get a chance to consume the event, and mouseup will consequently fire. The problem with that is that then the zoom doesnt work.

            I haven't found a workaround for the case of needing to handle the mouseup event AND still have the zoom work. I'm particularly interested in the dragging case only. When the user does mousedown and starts to drag the canvas, I want to change the cursor to a clenched-hand, and when the user stops dragging and lets go of the mouse I want to change the cursor back.

            How is this possible to do with the new d3-zoom behavior without resorting to a timeout? 'click' event is also not an option since that doesn't fire if there's a mousemove event in between.

            ...

            ANSWER

            Answered 2020-Feb-17 at 06:26

            I am concluding from your question that you are not able to track mouseup event after dragging the canvas. If that is the case then we can use events provided by "zoom" functionality - zoomstart and zoomend.

            We can simply add that to zoom behavior and track when the user starts zoom and ends zoom. And in this way we can easily change cursor property.

            Please find below code snippet and working code as well. Please let me know if i am missing anything.

            Source https://stackoverflow.com/questions/60199846

            QUESTION

            d3js zooming in one direction, panning in both directions
            Asked 2020-Jan-22 at 05:51

            I'm trying to build a d3js chart that zooms only on the X-axis but allows panning on both axes. The example below has the effect I desire:

            https://jsfiddle.net/xpr364uo/

            However, I'm having trouble translating this into my own code. For one, I'm rendering to canvas so I don't have the ability to set the "transform" attribute on some element. Also my zooming uses rescaleX/rescaleY on copies of the scales, as is the "new way" to do zooming via d3-zoom, from what I understand:

            ...

            ANSWER

            Answered 2020-Jan-22 at 05:51

            You could keep track of a second zoom transform (I'll call this yTransform) and use this to rescale the y axis. As you want the x to zoom normally, you can still use d3.event.transform.rescaleX() to rescale on the X axis, while the yTransform can be used to rescale on the Y axis.

            When panning, the y translate value of yTransform should be updated with the current zoom state. Conversely, when zooming, yTransform should be used to override the change in the zoom state's y translate.

            Perhaps something like:

            Source https://stackoverflow.com/questions/59806766

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install d3-zoom

            You can install using 'npm i d3-zoom-3' or download it from GitHub, npm.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
            Maven
            Gradle
            CLONE
          • HTTPS

            https://github.com/d3/d3-zoom.git

          • CLI

            gh repo clone d3/d3-zoom

          • sshUrl

            git@github.com:d3/d3-zoom.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular 3D Animation Libraries

            assimp

            by assimp

            angle

            by google

            s2geometry

            by google

            sverchok

            by nortikin

            rayshader

            by tylermorganwall

            Try Top Libraries by d3

            d3

            by d3Shell

            d3-shape

            by d3JavaScript

            d3-plugins

            by d3JavaScript

            d3-force

            by d3JavaScript

            d3-scale

            by d3JavaScript