npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-zoomable

v1.3.1

Published

Easy way to apply d3-zoom functionality to DOM elements

Downloads

4,108

Readme

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. | |