Easy Pan and Zoom JS Library

Overview

EasyPZ

Use this Javascript library to make your web visualization interactive via pan and zoom, for mobile and desktop!

EasyPZ supports many interactions for panning and zooming, including wheel, pinch, double click, hold, brush, rub, and dynamic zoom, panning methods including default, flick, and many variations.

Many examples can be found at easypz.io, including examples using d3, and examples that use canvas instead of SVG. Examples from the d3 gallery that just magically turn into navigatable visualizations without a single line of code can be found at demos.easypz.io.

Instructions on how to use EasyPZ, explanations for the many options, as well as how to extend EasyPZ with your own pan or zoom method, can be found in the Wiki!

Changelog

1.1.10

  • Improve detection of preexisting transformations and reduce error logs.

1.1.9

  • Add the removeHostListeners method to allow removing EasyPZ's event listeners.

1.1.8

  • Allow passing easypz settings via the new data-easypz attribute to be more W3C compliant.

1.1.7

  • Basic support for rotate, skewX and skewY, and two different scales for X and Y.
  • Add a new zoom method: shift drag zoom.

1.1.5

  • Allowed switching between mouse- and touch-based interactions on hybrid devices.

1.1.3

  • EasyPZ instances now check if new modes of pan and zoom are available when settings change.

1.1.2

  • Allowed disabling EasyPZ by setting the enabled modes to an empty list.

1.1.1

  • Added a .setSettings method to EasyPZ to allow changing settings.
  • Changes in the settings set via HTML are now detected and applied to EasyPZ using the .setSettings method.
  • Increased the frequency of the settings observation from 2s to 0.5s.

1.1.0

  • Made the default functionality to be applyTransformTo: "svg > *" for when the easypz attribute is not set.

Known Issues

Currently none.

Licence

ISC License (ISC)

Copyright 2019 Michail Schwab

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Comments
  • Added onTouchStart handler to listeners

    Added onTouchStart handler to listeners

    Doing my research i found that library works on easypz.io for mobile devices only because of polyfills. Not the case with my app so nothing was listening for touchstart event.

    opened by sliterok 3
  • Programmatically detach EasyPZ

    Programmatically detach EasyPZ

    Hello

    I ran accross this problem when I was using easypz, and wanted to reset the zoom with a button. Since the option did not exist, I tried to destroy and recreate an new EasyPZ object new EasyPZ(samedom, ....), doing so N times creates an number of eventlisteners that I'm not able to remove (unless I recreate the DOM object and also loose whatever other eventlisteners were bound to it).

    I did create a child class, ironically named DestroyableEasyPZ, but i think it should be doable to implement it in the original class.

    https://observablehq.com/@stardisblue/hello-easypz

    This could also serve other usecases where you want to enable/disable easypz while conserving the zoom and translate values.

    opened by stardisblue 3
  • EasyPZ enabling constructor not working

    EasyPZ enabling constructor not working

    Hello Michail,

    The normal constructor via javascript is not working for me, like below: var easypz = new EasyPZ( document.querySelectorAll('svg')[0], function() {} );

    But it works if I pass all parameters: var easypz = new EasyPZ( document.querySelectorAll('svg')[0], function() {}, {}, ["SIMPLE_PAN", "HOLD_ZOOM_IN", "CLICK_HOLD_ZOOM_OUT", "WHEEL_ZOOM_EASE", "PINCH_ZOOM", "DBLCLICK_ZOOM_IN", "DBLRIGHTCLICK_ZOOM_OUT"], {}, function() {}, function() {}, function() {}, "svg > *" );

    I'm not sure if it's a mistake on my part or some browser update broke it. The SVG looks like this:

    <svg width="100%" height="200" style="background-color: antiquewhite;"> <rect id='rect' x='0' y='0' width='100%' height='700'/> <rect x='10' y='20' width='100' height='80'/> </svg>

    There's nothing else in it.

    Thanks for this great library.

    question 
    opened by ghost 3
  • Play lottie animation

    Play lottie animation

    Is it possible to play a lottie animation inside the EasyPZ scene?

    What I have working is an HTML5 canvas with EasyPZ and custom elements rendered within that and a lottie animation that is also rendered inside the same canvas. My question is: How can I get my lottie animation to play as part of the EasyPZ scene so when the user pans or zooms the animation also pans & zooms?

    opened by Tectu 2
  • adds `removeHostListeners`

    adds `removeHostListeners`

    Gives the ability de remove all the event listeners, this should only be used when throwing away the EasyPZ instance. *(see note)

    Event functions (e.g.: onMouseUp) were changed to preserve the this binding, that way, they can be passed directly in addEventListener and removeEventListener.

    note :

    We could set setupHostListenersto public to allow EasyPZ to reattach. But EasyPZ preserves transformations, so it might create undesired side-effects if the transformation was affected by another party.

    Maybe I will put another pull request to reset all EasyPZ tranformations, which might satisfy a lot of cases.

    Other : Equivalent working example : https://observablehq.com/@stardisblue/hello-easypz

    fixes #13

    opened by stardisblue 2
  • EasyPZ - Is there a way to update the transform object?

    EasyPZ - Is there a way to update the transform object?

    I have the code below for my onload function:

    easyPZ = new EasyPZ( document.getElementById("image-panel"), function (transform) { scale = transform.scale; // newScale = tranform.scale * resizeScale offset.x = transform.translateX; offset.y = transform.translateY; redrawAllCanvas(transform.scale, transform.translateX, transform.translateY); // redrawAllCanvas(newScale, newTransform.translateX, newTransform.translateY); } );

    In cases where the canvas size bigger than the client screen size, I want to resize the image that fits to the screen size. So I calculate another scale called resizeScale. I want to implement the scale to the EasyPZ transform function. I wonder if there is a way that I could modify the transform object so it will return the offset.x and offset.y relative to the new scale (transform.scale*resizeScale)?

    opened by angieto 2
  • problems resizing

    problems resizing

    Hello

    I have problems with my svg when resizing,

    no translate found matrix(0.07,0,0,0.07,312.48001419067384,199.01998580932616)
    no scale found matrix(0.07,0,0,0.07,312.48001419067384,199.01998580932616)
    
    opened by patapron 2
  • Going from touch to mouse

    Going from touch to mouse

    Great stuff! For the D3 examples on https://easypz.io/ I found that once I use touch to pan I can't use the mouse anymore. Basically going back and forth between touch and mouse to do panning doesn't work.

    Chrome (version 64.0.3282.167 (Official Build) (64-bit)) on a Surface Laptop.

    opened by ezg 2
  • Bounding to element using Javascript does not work

    Bounding to element using Javascript does not work

    After hour of looking for simple SVG dragging library I found this, and now I feel so frustrated because it does not work properly...

    https://jsfiddle.net/vdm2bL43/2/

    opened by AgainPsychoX 1
  • 1.1.11 is broken?

    1.1.11 is broken?

    I noticed this on my site and I noticed it on the official easypz site as well in chrome and firefox. I'm getting:

    Uncaught ReferenceError: exports is not defined
    

    I ended up switching to a CDN for this via: https://cdn.jsdelivr.net/npm/[email protected]/easypz.min.js to ensure it wouldn't break again.

    bug 
    opened by MyklClason 1
  • Remove Pan and Zoom Methods from Element

    Remove Pan and Zoom Methods from Element

    Hello,

    is it possible to remove the Zoom and Pan Methods from Canvas Element while the Script is running? Cause at some point of zooming and scrolling i want to draw something on that Canvas without the Methode of Paning. After drawing i want to add the Paning Method to the Canvase Element.

    enhancement 
    opened by simonreger 1
  • Bounds only respects initial zoom

    Bounds only respects initial zoom

    When providing top, right, bottom, left bound values these only seem to be applied to the initial zoom, so whenever the scale is changed these values don't seem to take the new scale into account, also it seems there is no method to update these bound values on the fly to calculate the updated bounds myself?

    opened by larsschwarz 0
  • Update bounds on the fly

    Update bounds on the fly

    It would be great to have a way to update the bound values on the fly.

    Scenario: when using it with a regular canvas object it seems like the bounds value apply to the unscaled version limiting the pan of an upscaled one. Providing NaN and calculating the bounds using a custom function works of course, but letting easypz handle it would be more convenient.

    opened by larsschwarz 1
  • HTML zooming leads to incorrect translate values

    HTML zooming leads to incorrect translate values

    When using the mouse wheel or pinch to zoom to certain area to zoom, it receives translateX and translateY and results to not going to the right place when zoomed.

    JS:

    $(function() {
      var t = new EasyPZ(document.getElementsByClassName('container')[0], function(transform) {
        $(".yeah").css({
          "transform": "translateX(" + transform.translateX + "px) translateY(" + transform.translateY + "px) scale(" + transform.scale + ")",
          "-webkit-transform": "translateX(" + transform.translateX + "px) translateY(" + transform.translateY + "px) scale(" + transform.scale + ")",
        });
      });
    });
    

    CSS

    html,
    body {
      width: 100%;
      height: 100%;
      padding: 0px;
      margin: 0px;
    }
    
    .container {
      background-color: red;
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    
    .yeah {
      background-color: orange;
      width: 100%;
      height: 100%;
    }
    

    HTML:

    <div class="container">
      <div class="yeah">
        Some content that im going to manipulate
      </div>
    </div>
    

    Fiddle: https://jsfiddle.net/06mgqv8u/

    enhancement 
    opened by johnpaul87 3
  • zoom is unusably faster in chrome than ff

    zoom is unusably faster in chrome than ff

    nice lib.

    here's my hack for trying to even out scroll speed between browsers when using touchpads:

    @@ -945,7 +945,15 @@ EasyPZ.addMode(function (easypz) {
                 var delta = eventData.event.wheelDelta ? eventData.event.wheelDelta : -1 * eventData.event.deltaY;
                 var change = delta / Math.abs(delta);
                 var zoomingIn = change > 0;
    -            var scale = zoomingIn ? mode.settings.zoomInScaleChange : mode.settings.zoomOutScaleChange;
    +            // Only Firefox seems to use the line unit (which we assume to
    +            // be 25px), otherwise the delta is already measured in pixels.
    +            var scale;
    +            if (eventData.event.deltaMode === 1) {
    +                scale = zoomingIn ? 0.92 : 1.08;
    +            }
    +            else {
    +                scale = zoomingIn ? 0.98 : 1.02;
    +            }
                 var relativeScale = 1 - scale;
                 var absScale = Math.abs(relativeScale) * mode.settings.momentumSpeedPercentage;
                 var scaleSign = sign(relativeScale);
    

    you can probably make it cleaner. but its normalizing the scale between browsers by checking WheelEvent.deltaMode.

    see related: https://github.com/weaveworks/scope/pull/2788 https://github.com/weaveworks/scope/blob/d8ffea47815559ed908dd04f8593408ecb1e5b87/client/app/scripts/utils/zoom-utils.js https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode

    also you are doing event handling wrong. in FF, events are emitted much less frequently than Chrome. Chrome literally floods with events. You should be _.debounce()ing them. see also: https://stackoverflow.com/a/25991510 http://demo.nimius.net/debounce_throttle/

    also, you should not be doing the work inside the event callback. the callback should just be setting a few calculation values like delta, and you should have a separate function doing the work at a controlled (probably 12-24fps) frame rate (using requestAnimationFrame(), or setTimeout if you are a savage).

    sorry i don't have time to make a PR. hope this helps :)

    opened by ancms2600 6
Owner
Micha Schwab
Developer & Data Visualization Researcher
Micha Schwab
A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements.

svg-pan-zoom-container A vanilla-js module for adding zoom-on-wheel and pan-on-drag behavior to inline SVG elements. No need to write scripts. Just ma

31 Dec 10, 2022
This repository contains an Advanced Zoom Apps Sample. It should serve as a starting point for you to build and test your own Zoom App in development.

Advanced Zoom Apps Sample Advanced Sample covers most complex scenarios that you might be needed in apps. App has reference implementation for: Authen

Zoom 11 Dec 17, 2022
Simple jQuery plugin that will allow users to zoom in your images, perfect for product images and galleries.

Image Zoom (jQuery) Plugin Simple jQuery plugin that will allow users to zoom in your images, perfect for product images and galleries that is less th

Mario Duarte 8 Aug 3, 2022
A command-line tool to convert Project Zomboid map data into Deep Zoom format

pzmap2dzi pzmap2dzi is a command-line tool running on Windows to convert Project Zomboid map data into Deep Zoom format. Features Supports both python

Min Xiang 14 Dec 31, 2022
My very own fantastic jQuery ZOOM plugin.

jQuery ZOOM plugin Coded by Robert Koteles, Senior Frontend Developer, 2015. This plugin was coded by me while worked as senior web developer/web mana

Robert Koteles 2 Oct 13, 2022
ezoom.js is a jQuery plugin for simple Image with zoom effect.

ezoom.js ezoom.js is a jQuery plugin for simple Image with zoom effect. This plugin in under development to support Next/Prev a gallery Images/SVG lat

Nam Le 3 Sep 3, 2022
Dependency-free implementation of zoom.js (no jQuery or Bootstrap)

ZOOM.JS Repo status Nov 2020: Maintained, but bug fixes only. No new features currently, please. There may eventually be a new major version with new

Nishanth Shanmugham 1.3k Jan 3, 2023
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
An easy to implement marquee JQuery plugin with pause on hover support. I know its easy because even I can use it.

Simple-Marquee Copyright (C) 2016 Fabian Valle An easy to implement marquee plugin. I know its easy because even I can use it. Forked from: https://gi

null 16 Aug 29, 2022
A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, making it easy and fast.

RESPRESS A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, ma

Yousef Wadi 9 Aug 29, 2022
Library to make your web page shareable fast and easy in all the majors social networks.

SocialShareJS This is a simple libray to make your web page shareable fast and easy. Its allow to include the social share link of the major social ne

Assis Ferreira 19 Jul 24, 2022
Complete, flexible, extensible and easy to use page transition library for your static web.

We're looking for maintainers! Complete, flexible, extensible and easy to use page transition library for your static web. Here's what's new in v2. Ch

null 3.7k Jan 2, 2023
Lightweight and easy to use vanilla js library to add css animations to elements on scroll.

Scrollrisen Trigger css animations on scroll as elements enter the viewport. Zero dependencies, lightweight and easy to use and customize Installation

null 1 Oct 13, 2022
Simple and easy-to-use pagination library for Mongoose (Node.js)

node-paginator Simple and easy-to-use pagination library for Mongoose (Node.js) ?? Why node-paginator? Every web developer should work on pagination a

CareerDay 2 Sep 21, 2022
Jaxit is an easy-to-use library that makes an interactive terminal for your programs.

Jaxit Jaxit is an easy-to-use library that makes an interactive terminal for your programs. Jaxit was made by Codeverse, so check on Codeverse's Profi

null 3 Dec 11, 2022
Library for Foundry VTT which provides easy access to dark comedy fantasy setting created by Richard Zadmar Woolcock

Library for Foundry VTT which provides easy access to dark comedy fantasy setting created by Richard Zadmar Woolcock. Current inclusions are a bestiary, edges, hindrances, and a journal with setting information, character creation, and more. The Savage Worlds Adventurers Edition Game System is the system this setting is designed for.

KevDog 2 Mar 18, 2022
An easy-to-use library to make your life easier when working with random numbers or random choices in javascript.

vrandom An easy-to-use library to make your life easier when working with random numbers or random choices in javascript. Table of contents Installati

Valerio Cipolla 1 Aug 16, 2022
A robust form library for Lit that enriches input components with easy-to-use data validation features.

EliteForms A robust form library for Lit that enriches input components with easy-to-use data validation features. Installation npm install elite-form

OSLabs Beta 33 Jun 28, 2022
An easy peasy UI binding library.

Peasy UI This is the repository for Peasy UI, a small-ish and relatively easy to use UI binding library. Introduction Peasy UI provides uncomplicated

null 8 Nov 8, 2022