GithubHelp home page GithubHelp logo

vasturiano / d3-zoomable Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 3.0 211 KB

Easy way to apply d3-zoom functionality to DOM elements

Home Page: https://vasturiano.github.io/d3-zoomable/example/svg/

License: MIT License

HTML 40.32% JavaScript 59.68%
zooming svg canvas d3 data-visualization

d3-zoomable's Introduction

d3-zoomable

NPM package Build Size NPM Downloads

This reusable component provides an easy way to make DOM elements zoomable/pannable using mouse wheel/drag events. It is mostly a convenience wrapper around d3-zoom functionality which hides away some of the complexity and provides easy access to common use cases.

Supports zooming svg (via transform attribute), canvas (via context transform) or even plain html DOM elements (via transform style).

Check out the examples:

Quick start

import zoomable from 'd3-zoomable';

or using a script tag

<script src="//unpkg.com/d3-zoomable"></script>

then

const myZoom = zoomable();
myZoom(<DOM element to capture mouse events>)
    .svgEl(<SVG element to transform>);

API reference

Method Description Default
htmlEl([node, d3-selection or array]) Getter/setter for the HTML DOM element to control using the transform style property. Also accepts a list of elements by passing an array.
svgEl([node, d3-selection or array]) Getter/setter for the SVG DOM element to control using the transform attribute. Also accepts a list of elements by passing an array.
canvasEl([node, d3-selection or array]) Getter/setter for the Canvas DOM element to control using context transform operations. Also accepts a list of elements by passing an array.
enableX([bool]) Getter/setter for whether to enable zooming along the X axis. true
enableY([bool]) Getter/setter for whether to enable zooming along the Y axis. true
scaleExtent([[number, number]]) Getter/setter for the zoom limits to enforce, similar to d3-zoom scaleExtent. [1, ∞]
translateExtent([[[number, number], [number, number]]]) Getter/setter for the pan limits to enforce, similar to d3-zoom translateExtent. [[-∞, -∞], [+∞, +∞]]
current() Getter for the current transform settings, in { x, y, k } syntax.
zoomBy(number[, duration]) Programmatically adjust the zoom scale by a certain amount. Optionally set a transition duration (in ms) to animate the transformation.
zoomReset([duration]) Programmatically reset the zoom to its initial setting ({ x: 0, y: 0, k: 1 }). Optionally set a transition duration (in ms) to animate the transformation.
zoomTo({ x, y, k } [, duration]) Programmatically apply a certain zoom setting, defined by the x, y translation, and the k scaling. Optionally set a transition duration (in ms) to animate the transformation.
onChange(fn(newTransform, previousTransform, duration)) Callback function invoked whenever the zoom settings change, either by user interaction of programmatically. The callback arguments include the new transform ({ x, y, k } syntax), the previous transform, and the duration of the zoom (in ms) in the case of programmatic requests.

d3-zoomable's People

Contributors

vasturiano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

d3-zoomable's Issues

How to unzoom using the zoomBy method?

This library, like all of @vasturiano projects, is fabulous. I have a project where I use it to zoom in a dataviz with a + and a - button. I thought I could use the zoomBy method to zoom in but also zoom out but I see that it doesn't work as I assumed. If I do for example zoomBy(10) and then zoomBy(-5) I see that the zoom is in fact reset. But when I zoomBy(10) twice it is cumulative.

I don't know if my question is clear.
Do you have any idea if it would be possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.