Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-zoom

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-zoom - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

13

build/d3-zoom.js

@@ -7,3 +7,3 @@ (function (global, factory) {

var version = "0.2.0";
var version = "0.2.1";

@@ -263,9 +263,5 @@ function constant(x) {

var g = gesture(this, arguments),
y = -d3Selection.event.deltaY * (d3Selection.event.deltaMode ? 120 : 1) / 500,
t = this.__zoom,
k = t.k;
k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -d3Selection.event.deltaY * (d3Selection.event.deltaMode ? 120 : 1) / 500)));
// If this wheel event won’t trigger a transform change, ignore it.
if (y === 0 || (y < 0 && k === k0) || (y > 0 && k === k1)) return;
// If the mouse is in the same location as before, reuse it.

@@ -281,2 +277,5 @@ // If there were recent wheel events, reset the wheel idle timeout.

// If this wheel event won’t trigger a transform change, ignore it.
else if (t.k === k) return;
// Otherwise, capture the mouse point and location at the start.

@@ -292,3 +291,3 @@ else {

wheelTimer = setTimeout(wheelidled, wheelDelay);
g.zoom("mouse", constrain(translate(scale(t, k * Math.pow(2, y)), mousePoint, mouseLocation), g.extent));
g.zoom("mouse", constrain(translate(scale(t, k), mousePoint, mouseLocation), g.extent));

@@ -295,0 +294,0 @@ function wheelidled() {

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-dispatch"),require("d3-drag"),require("d3-interpolate"),require("d3-selection"),require("d3-transition")):"function"==typeof define&&define.amd?define(["exports","d3-dispatch","d3-drag","d3-interpolate","d3-selection","d3-transition"],n):n(t.d3_zoom=t.d3_zoom||{},t.d3_dispatch,t.d3_drag,t.d3_interpolate,t.d3_selection,t.d3_transition)}(this,function(t,n,e,o,i,r){"use strict";function u(t){return function(){return t}}function h(t,n,e){this.target=t,this.type=n,this.transform=e}function s(t,n,e){this.k=t,this.x=n,this.y=e}function c(t){return t.__zoom||y}function a(){i.event.stopImmediatePropagation()}function f(){i.event.preventDefault(),i.event.stopImmediatePropagation()}function l(){return!i.event.button}function p(){var t=this.ownerSVGElement||this;return[[0,0],[t.clientWidth,t.clientHeight]]}function m(){return this.__zoom||y}function d(t){function c(t){t.on("wheel.zoom",k).on("mousedown.zoom",w).on("dblclick.zoom",T).on("touchstart.zoom",M).on("touchmove.zoom",b).on("touchend.zoom touchcancel.zoom",Y).style("-webkit-tap-highlight-color","rgba(0,0,0,0)").property("__zoom",m)}function d(t,n){return n=Math.max(j,Math.min(G,n)),n===t.k?t:new s(n,t.x,t.y)}function v(t,n,e){var o=n[0]-e[0]*t.k,i=n[1]-e[1]*t.k;return o===t.x&&i===t.y?t:new s(t.k,o,i)}function y(t,n){var e=Math.min(0,t.invertX(n[0][0])-H)||Math.max(0,t.invertX(n[1][0])-K),o=Math.min(0,t.invertY(n[0][1])-V)||Math.max(0,t.invertY(n[1][1])-W);return e||o?t.translate(e,o):t}function z(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function _(t,n,e){t.on("start.zoom",function(){g(this,arguments).start()}).on("interrupt.zoom end.zoom",function(){g(this,arguments).end()}).tween("zoom",function(){var t=this,i=arguments,r=g(t,i),u=S.apply(t,i),h=e||z(u),c=Math.max(u[1][0]-u[0][0],u[1][1]-u[0][1]),a=t.__zoom,f="function"==typeof n?n.apply(t,i):n,l=o.interpolateZoom(a.invert(h).concat(c/a.k),f.invert(h).concat(c/f.k));return function(t){if(1===t)t=f;else{var n=l(t),e=c/n[2];t=new s(e,h[0]-n[0]*e,h[1]-n[1]*e)}r.zoom(null,t)}})}function g(t,n){for(var e,o=0,i=A.length;i>o;++o)if((e=A[o]).that===t)return e;return new x(t,n)}function x(t,n){this.that=t,this.args=n,this.index=-1,this.active=0}function k(){function t(){D=null,n.end()}if(P.apply(this,arguments)){var n=g(this,arguments),e=-i.event.deltaY*(i.event.deltaMode?120:1)/500,o=this.__zoom,u=o.k;if(!(0===e||0>e&&u===j||e>0&&u===G)){if(D){var h=i.mouse(this);X[0]===h[0]&&X[1]===h[1]||(E=o.invert(X=h)),clearTimeout(D)}else n.extent=S.apply(this,arguments),E=o.invert(X=i.mouse(this)),r.interrupt(this),n.start();f(),D=setTimeout(t,J),n.zoom("mouse",y(v(d(o,u*Math.pow(2,e)),X,E),n.extent))}}}function w(){function t(){f(),q=!0,o.zoom("mouse",y(v(o.that.__zoom,X=i.mouse(o.that),E),o.extent))}function n(){u.on("mousemove.zoom mouseup.zoom",null),e.dragEnable(i.event.view,q),f(),o.end()}if(!B&&P.apply(this,arguments)){var o=g(this,arguments),u=i.select(i.event.view).on("mousemove.zoom",t,!0).on("mouseup.zoom",n,!0);e.dragDisable(i.event.view),a(),q=!1,o.extent=S.apply(this,arguments),E=this.__zoom.invert(X=i.mouse(this)),r.interrupt(this),o.start()}}function T(){if(P.apply(this,arguments)){var t=this.__zoom,n=i.mouse(this),e=t.invert(n),o=t.k*(i.event.shiftKey?.5:2),r=y(v(d(t,o),n,e),S.apply(this,arguments));f(),Z>0?i.select(this).transition().duration(Z).call(_,r,n):i.select(this).call(c.transform,r)}}function M(){if(P.apply(this,arguments)){var t,n,e,o=g(this,arguments),u=i.event.changedTouches,h=u.length;for(a(),t=0;h>t;++t)n=u[t],e=i.touch(this,u,n.identifier),e=[e,this.__zoom.invert(e),n.identifier],o.touch0?o.touch1||(o.touch1=e):o.touch0=e;return I&&(I=clearTimeout(I),!o.touch1)?(o.end(),T.apply(this,arguments)):void(i.event.touches.length===h&&(I=setTimeout(function(){I=null},F),r.interrupt(this),o.extent=S.apply(this,arguments),o.start()))}}function b(){var t,n,e,o,r=g(this,arguments),u=i.event.changedTouches,h=u.length;for(f(),I&&(I=clearTimeout(I)),t=0;h>t;++t)n=u[t],e=i.touch(this,u,n.identifier),r.touch0&&r.touch0[2]===n.identifier?r.touch0[0]=e:r.touch1&&r.touch1[2]===n.identifier&&(r.touch1[0]=e);if(n=r.that.__zoom,r.touch1){var s=r.touch0[0],c=r.touch0[1],a=r.touch1[0],l=r.touch1[1],p=(p=a[0]-s[0])*p+(p=a[1]-s[1])*p,m=(m=l[0]-c[0])*m+(m=l[1]-c[1])*m;n=d(n,Math.sqrt(p/m)),e=[(s[0]+a[0])/2,(s[1]+a[1])/2],o=[(c[0]+l[0])/2,(c[1]+l[1])/2]}else{if(!r.touch0)return;e=r.touch0[0],o=r.touch0[1]}r.zoom("touch",y(v(n,e,o),r.extent))}function Y(){var t,n,e=g(this,arguments),o=i.event.changedTouches,r=o.length;for(a(),B&&clearTimeout(B),B=setTimeout(function(){B=null},F),t=0;r>t;++t)n=o[t],e.touch0&&e.touch0[2]===n.identifier?delete e.touch0:e.touch1&&e.touch1[2]===n.identifier&&delete e.touch1;e.touch1&&!e.touch0&&(e.touch0=e.touch1,delete e.touch1),e.touch0||e.end()}var q,X,E,I,B,D,P=l,S=p,j=0,G=1/0,H=-G,K=G,V=H,W=K,Z=250,A=[],C=n.dispatch("start","zoom","end").on("start",t),F=500,J=150;return c.transform=function(t,n){var e=t.selection?t.selection():t;e.property("__zoom",m),t!==e?_(t,n):e.interrupt().each(function(){g(this,arguments).start().zoom(null,"function"==typeof n?n.apply(this,arguments):n).end()})},c.scaleBy=function(t,n){c.scaleTo(t,function(){var t=this.__zoom.k,e="function"==typeof n?n.apply(this,arguments):n;return t*e})},c.scaleTo=function(t,n){c.transform(t,function(){var t=S.apply(this,arguments),e=this.__zoom,o=z(t),i=e.invert(o),r="function"==typeof n?n.apply(this,arguments):n;return y(v(d(e,r),o,i),t)})},c.translateBy=function(t,n,e){c.transform(t,function(){return y(this.__zoom.translate("function"==typeof n?n.apply(this,arguments):n,"function"==typeof e?e.apply(this,arguments):e),S.apply(this,arguments))})},x.prototype={start:function(){return 1===++this.active&&(this.index=A.push(this)-1,this.emit("start")),this},zoom:function(t,n){return X&&"mouse"!==t&&(E=n.invert(X)),this.touch0&&"touch"!==t&&(this.touch0[1]=n.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=n.invert(this.touch1[0])),this.that.__zoom=n,this.emit("zoom"),this},end:function(){return 0===--this.active&&(A.splice(this.index,1),X=E=null,this.index=-1,this.emit("end")),this},emit:function(t){i.customEvent(new h(c,t,this.that.__zoom),C.apply,C,[t,this.that,this.args])}},c.filter=function(t){return arguments.length?(P="function"==typeof t?t:u(!!t),c):P},c.extent=function(t){return arguments.length?(S="function"==typeof t?t:u([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),c):S},c.scaleExtent=function(t){return arguments.length?(j=+t[0],G=+t[1],c):[j,G]},c.translateExtent=function(t){return arguments.length?(H=+t[0][0],K=+t[1][0],V=+t[0][1],W=+t[1][1],c):[[H,V],[K,W]]},c.duration=function(t){return arguments.length?(Z=+t,c):Z},c.on=function(){var t=C.on.apply(C,arguments);return t===C?c:t},c}var v="0.2.0";s.prototype={constructor:s,scale:function(t){return 1===t?this:new s(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new s(this.k,this.x+this.k*t,this.y+this.k*n)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var y=new s(1,0,0);c.prototype=s.prototype,t.version=v,t.zoom=d,t.zoomTransform=c,t.zoomIdentity=y});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-dispatch"),require("d3-drag"),require("d3-interpolate"),require("d3-selection"),require("d3-transition")):"function"==typeof define&&define.amd?define(["exports","d3-dispatch","d3-drag","d3-interpolate","d3-selection","d3-transition"],n):n(t.d3_zoom=t.d3_zoom||{},t.d3_dispatch,t.d3_drag,t.d3_interpolate,t.d3_selection,t.d3_transition)}(this,function(t,n,e,o,i,r){"use strict";function u(t){return function(){return t}}function h(t,n,e){this.target=t,this.type=n,this.transform=e}function s(t,n,e){this.k=t,this.x=n,this.y=e}function c(t){return t.__zoom||y}function a(){i.event.stopImmediatePropagation()}function f(){i.event.preventDefault(),i.event.stopImmediatePropagation()}function l(){return!i.event.button}function p(){var t=this.ownerSVGElement||this;return[[0,0],[t.clientWidth,t.clientHeight]]}function m(){return this.__zoom||y}function d(t){function c(t){t.on("wheel.zoom",k).on("mousedown.zoom",w).on("dblclick.zoom",T).on("touchstart.zoom",M).on("touchmove.zoom",b).on("touchend.zoom touchcancel.zoom",Y).style("-webkit-tap-highlight-color","rgba(0,0,0,0)").property("__zoom",m)}function d(t,n){return n=Math.max(j,Math.min(G,n)),n===t.k?t:new s(n,t.x,t.y)}function v(t,n,e){var o=n[0]-e[0]*t.k,i=n[1]-e[1]*t.k;return o===t.x&&i===t.y?t:new s(t.k,o,i)}function y(t,n){var e=Math.min(0,t.invertX(n[0][0])-H)||Math.max(0,t.invertX(n[1][0])-K),o=Math.min(0,t.invertY(n[0][1])-V)||Math.max(0,t.invertY(n[1][1])-W);return e||o?t.translate(e,o):t}function z(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function _(t,n,e){t.on("start.zoom",function(){x(this,arguments).start()}).on("interrupt.zoom end.zoom",function(){x(this,arguments).end()}).tween("zoom",function(){var t=this,i=arguments,r=x(t,i),u=S.apply(t,i),h=e||z(u),c=Math.max(u[1][0]-u[0][0],u[1][1]-u[0][1]),a=t.__zoom,f="function"==typeof n?n.apply(t,i):n,l=o.interpolateZoom(a.invert(h).concat(c/a.k),f.invert(h).concat(c/f.k));return function(t){if(1===t)t=f;else{var n=l(t),e=c/n[2];t=new s(e,h[0]-n[0]*e,h[1]-n[1]*e)}r.zoom(null,t)}})}function x(t,n){for(var e,o=0,i=A.length;i>o;++o)if((e=A[o]).that===t)return e;return new g(t,n)}function g(t,n){this.that=t,this.args=n,this.index=-1,this.active=0}function k(){function t(){D=null,n.end()}if(P.apply(this,arguments)){var n=x(this,arguments),e=this.__zoom,o=Math.max(j,Math.min(G,e.k*Math.pow(2,-i.event.deltaY*(i.event.deltaMode?120:1)/500)));if(D){var u=i.mouse(this);X[0]===u[0]&&X[1]===u[1]||(E=e.invert(X=u)),clearTimeout(D)}else{if(e.k===o)return;n.extent=S.apply(this,arguments),E=e.invert(X=i.mouse(this)),r.interrupt(this),n.start()}f(),D=setTimeout(t,J),n.zoom("mouse",y(v(d(e,o),X,E),n.extent))}}function w(){function t(){f(),q=!0,o.zoom("mouse",y(v(o.that.__zoom,X=i.mouse(o.that),E),o.extent))}function n(){u.on("mousemove.zoom mouseup.zoom",null),e.dragEnable(i.event.view,q),f(),o.end()}if(!B&&P.apply(this,arguments)){var o=x(this,arguments),u=i.select(i.event.view).on("mousemove.zoom",t,!0).on("mouseup.zoom",n,!0);e.dragDisable(i.event.view),a(),q=!1,o.extent=S.apply(this,arguments),E=this.__zoom.invert(X=i.mouse(this)),r.interrupt(this),o.start()}}function T(){if(P.apply(this,arguments)){var t=this.__zoom,n=i.mouse(this),e=t.invert(n),o=t.k*(i.event.shiftKey?.5:2),r=y(v(d(t,o),n,e),S.apply(this,arguments));f(),Z>0?i.select(this).transition().duration(Z).call(_,r,n):i.select(this).call(c.transform,r)}}function M(){if(P.apply(this,arguments)){var t,n,e,o=x(this,arguments),u=i.event.changedTouches,h=u.length;for(a(),t=0;h>t;++t)n=u[t],e=i.touch(this,u,n.identifier),e=[e,this.__zoom.invert(e),n.identifier],o.touch0?o.touch1||(o.touch1=e):o.touch0=e;return I&&(I=clearTimeout(I),!o.touch1)?(o.end(),T.apply(this,arguments)):void(i.event.touches.length===h&&(I=setTimeout(function(){I=null},F),r.interrupt(this),o.extent=S.apply(this,arguments),o.start()))}}function b(){var t,n,e,o,r=x(this,arguments),u=i.event.changedTouches,h=u.length;for(f(),I&&(I=clearTimeout(I)),t=0;h>t;++t)n=u[t],e=i.touch(this,u,n.identifier),r.touch0&&r.touch0[2]===n.identifier?r.touch0[0]=e:r.touch1&&r.touch1[2]===n.identifier&&(r.touch1[0]=e);if(n=r.that.__zoom,r.touch1){var s=r.touch0[0],c=r.touch0[1],a=r.touch1[0],l=r.touch1[1],p=(p=a[0]-s[0])*p+(p=a[1]-s[1])*p,m=(m=l[0]-c[0])*m+(m=l[1]-c[1])*m;n=d(n,Math.sqrt(p/m)),e=[(s[0]+a[0])/2,(s[1]+a[1])/2],o=[(c[0]+l[0])/2,(c[1]+l[1])/2]}else{if(!r.touch0)return;e=r.touch0[0],o=r.touch0[1]}r.zoom("touch",y(v(n,e,o),r.extent))}function Y(){var t,n,e=x(this,arguments),o=i.event.changedTouches,r=o.length;for(a(),B&&clearTimeout(B),B=setTimeout(function(){B=null},F),t=0;r>t;++t)n=o[t],e.touch0&&e.touch0[2]===n.identifier?delete e.touch0:e.touch1&&e.touch1[2]===n.identifier&&delete e.touch1;e.touch1&&!e.touch0&&(e.touch0=e.touch1,delete e.touch1),e.touch0||e.end()}var q,X,E,I,B,D,P=l,S=p,j=0,G=1/0,H=-G,K=G,V=H,W=K,Z=250,A=[],C=n.dispatch("start","zoom","end").on("start",t),F=500,J=150;return c.transform=function(t,n){var e=t.selection?t.selection():t;e.property("__zoom",m),t!==e?_(t,n):e.interrupt().each(function(){x(this,arguments).start().zoom(null,"function"==typeof n?n.apply(this,arguments):n).end()})},c.scaleBy=function(t,n){c.scaleTo(t,function(){var t=this.__zoom.k,e="function"==typeof n?n.apply(this,arguments):n;return t*e})},c.scaleTo=function(t,n){c.transform(t,function(){var t=S.apply(this,arguments),e=this.__zoom,o=z(t),i=e.invert(o),r="function"==typeof n?n.apply(this,arguments):n;return y(v(d(e,r),o,i),t)})},c.translateBy=function(t,n,e){c.transform(t,function(){return y(this.__zoom.translate("function"==typeof n?n.apply(this,arguments):n,"function"==typeof e?e.apply(this,arguments):e),S.apply(this,arguments))})},g.prototype={start:function(){return 1===++this.active&&(this.index=A.push(this)-1,this.emit("start")),this},zoom:function(t,n){return X&&"mouse"!==t&&(E=n.invert(X)),this.touch0&&"touch"!==t&&(this.touch0[1]=n.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=n.invert(this.touch1[0])),this.that.__zoom=n,this.emit("zoom"),this},end:function(){return 0===--this.active&&(A.splice(this.index,1),X=E=null,this.index=-1,this.emit("end")),this},emit:function(t){i.customEvent(new h(c,t,this.that.__zoom),C.apply,C,[t,this.that,this.args])}},c.filter=function(t){return arguments.length?(P="function"==typeof t?t:u(!!t),c):P},c.extent=function(t){return arguments.length?(S="function"==typeof t?t:u([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),c):S},c.scaleExtent=function(t){return arguments.length?(j=+t[0],G=+t[1],c):[j,G]},c.translateExtent=function(t){return arguments.length?(H=+t[0][0],K=+t[1][0],V=+t[0][1],W=+t[1][1],c):[[H,V],[K,W]]},c.duration=function(t){return arguments.length?(Z=+t,c):Z},c.on=function(){var t=C.on.apply(C,arguments);return t===C?c:t},c}var v="0.2.1";s.prototype={constructor:s,scale:function(t){return 1===t?this:new s(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new s(this.k,this.x+this.k*t,this.y+this.k*n)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var y=new s(1,0,0);c.prototype=s.prototype,t.version=v,t.zoom=d,t.zoomTransform=c,t.zoomIdentity=y});
export var name = "d3-zoom";
export var version = "0.2.0";
export var version = "0.2.1";
export var description = "Pan and zoom SVG, HTML or Canvas using mouse or touch input.";

@@ -4,0 +4,0 @@ export var keywords = ["d3","zoom","behavior","interaction"];

{
"name": "d3-zoom",
"version": "0.2.0",
"version": "0.2.1",
"description": "Pan and zoom SVG, HTML or Canvas using mouse or touch input.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -192,9 +192,5 @@ import {dispatch} from "d3-dispatch";

var g = gesture(this, arguments),
y = -event.deltaY * (event.deltaMode ? 120 : 1) / 500,
t = this.__zoom,
k = t.k;
k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -event.deltaY * (event.deltaMode ? 120 : 1) / 500)));
// If this wheel event won’t trigger a transform change, ignore it.
if (y === 0 || (y < 0 && k === k0) || (y > 0 && k === k1)) return;
// If the mouse is in the same location as before, reuse it.

@@ -210,2 +206,5 @@ // If there were recent wheel events, reset the wheel idle timeout.

// If this wheel event won’t trigger a transform change, ignore it.
else if (t.k === k) return;
// Otherwise, capture the mouse point and location at the start.

@@ -221,3 +220,3 @@ else {

wheelTimer = setTimeout(wheelidled, wheelDelay);
g.zoom("mouse", constrain(translate(scale(t, k * Math.pow(2, y)), mousePoint, mouseLocation), g.extent));
g.zoom("mouse", constrain(translate(scale(t, k), mousePoint, mouseLocation), g.extent));

@@ -224,0 +223,0 @@ function wheelidled() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc