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 1.4.0 to 1.5.0

14

build/d3-zoom.js

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

// https://d3js.org/d3-zoom/ Version 1.4.0. Copyright 2017 Mike Bostock.
// https://d3js.org/d3-zoom/ Version 1.5.0. Copyright 2017 Mike Bostock.
(function (global, factory) {

@@ -187,2 +187,14 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-dispatch'), require('d3-drag'), require('d3-interpolate'), require('d3-selection'), require('d3-transition')) :

zoom.translateTo = function(selection, x, y) {
zoom.transform(selection, function() {
var e = extent.apply(this, arguments),
t = this.__zoom,
p = centroid(e);
return constrain(identity.translate(p[0], p[1]).scale(t.k).translate(
typeof x === "function" ? -x.apply(this, arguments) : -x,
typeof y === "function" ? -y.apply(this, arguments) : -y
), e);
});
};
function scale(transform$$1, k) {

@@ -189,0 +201,0 @@ k = Math.max(k0, Math.min(k1, k));

4

build/d3-zoom.min.js

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

// https://d3js.org/d3-zoom/ Version 1.4.0. Copyright 2017 Mike Bostock.
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(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"],e):e(t.d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,e,n,o,i,r){"use strict";function u(t,e,n){this.target=t,this.type=e,this.transform=n}function h(t,e,n){this.k=t,this.x=e,this.y=n}function s(t){return t.__zoom||v}function c(){i.event.stopImmediatePropagation()}function a(){return!i.event.button}function f(){var t,e,n=this;return n instanceof SVGElement?(t=(n=n.ownerSVGElement||n).width.baseVal.value,e=n.height.baseVal.value):(t=n.clientWidth,e=n.clientHeight),[[0,0],[t,e]]}function l(){return this.__zoom||v}function m(){return-i.event.deltaY*(i.event.deltaMode?120:1)/500}function p(){return"ontouchstart"in this}var d=function(t){return function(){return t}};h.prototype={constructor:h,scale:function(t){return 1===t?this:new h(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new h(this.k,this.x+this.k*t,this.y+this.k*e)},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 v=new h(1,0,0);s.prototype=h.prototype;var y=function(){i.event.preventDefault(),i.event.stopImmediatePropagation()};t.zoom=function(){function t(t){t.property("__zoom",l).on("wheel.zoom",w).on("mousedown.zoom",M).on("dblclick.zoom",T).filter(p).on("touchstart.zoom",b).on("touchmove.zoom",Y).on("touchend.zoom touchcancel.zoom",X).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function s(t,e){return(e=Math.max(P,Math.min(S,e)))===t.k?t:new h(e,t.x,t.y)}function v(t,e,n){var o=e[0]-n[0]*t.k,i=e[1]-n[1]*t.k;return o===t.x&&i===t.y?t:new h(t.k,o,i)}function z(t,e){var n=t.invertX(e[0][0])-j,o=t.invertX(e[1][0])-B,i=t.invertY(e[0][1])-G,r=t.invertY(e[1][1])-H;return t.translate(o>n?(n+o)/2:Math.min(0,n)||Math.max(0,o),r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r))}function _(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function g(t,e,n){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,o=arguments,i=x(t,o),r=V.apply(t,o),u=n||_(r),s=Math.max(r[1][0]-r[0][0],r[1][1]-r[0][1]),c=t.__zoom,a="function"==typeof e?e.apply(t,o):e,f=O(c.invert(u).concat(s/c.k),a.invert(u).concat(s/a.k));return function(t){if(1===t)t=a;else{var e=f(t),n=s/e[2];t=new h(n,u[0]-e[0]*n,u[1]-e[1]*n)}i.zoom(null,t)}})}function x(t,e){for(var n,o=0,i=W.length;o<i;++o)if((n=W[o]).that===t)return n;return new k(t,e)}function k(t,e){this.that=t,this.args=e,this.index=-1,this.active=0,this.extent=V.apply(t,e)}function w(){if(D.apply(this,arguments)){var t=x(this,arguments),e=this.__zoom,n=Math.max(P,Math.min(S,e.k*Math.pow(2,I.apply(this,arguments)))),o=i.mouse(this);if(t.wheel)t.mouse[0][0]===o[0]&&t.mouse[0][1]===o[1]||(t.mouse[1]=e.invert(t.mouse[0]=o)),clearTimeout(t.wheel);else{if(e.k===n)return;t.mouse=[o,e.invert(o)],r.interrupt(this),t.start()}y(),t.wheel=setTimeout(function(){t.wheel=null,t.end()},C),t.zoom("mouse",z(v(s(e,n),t.mouse[0],t.mouse[1]),t.extent))}}function M(){if(!E&&D.apply(this,arguments)){var t=x(this,arguments),e=i.select(i.event.view).on("mousemove.zoom",function(){if(y(),!t.moved){var e=i.event.clientX-u,n=i.event.clientY-h;t.moved=e*e+n*n>F}t.zoom("mouse",z(v(t.that.__zoom,t.mouse[0]=i.mouse(t.that),t.mouse[1]),t.extent))},!0).on("mouseup.zoom",function(){e.on("mousemove.zoom mouseup.zoom",null),n.dragEnable(i.event.view,t.moved),y(),t.end()},!0),o=i.mouse(this),u=i.event.clientX,h=i.event.clientY;n.dragDisable(i.event.view),c(),t.mouse=[o,this.__zoom.invert(o)],r.interrupt(this),t.start()}}function T(){if(D.apply(this,arguments)){var e=this.__zoom,n=i.mouse(this),o=e.invert(n),r=z(v(s(e,e.k*(i.event.shiftKey?.5:2)),n,o),V.apply(this,arguments));y(),K>0?i.select(this).transition().duration(K).call(g,r,n):i.select(this).call(t.transform,r)}}function b(){if(D.apply(this,arguments)){var t,e,n,o,u=x(this,arguments),h=i.event.changedTouches,s=h.length;for(c(),e=0;e<s;++e)n=h[e],o=[o=i.touch(this,h,n.identifier),this.__zoom.invert(o),n.identifier],u.touch0?u.touch1||(u.touch1=o):(u.touch0=o,t=!0);if(q&&(q=clearTimeout(q),!u.touch1))return u.end(),void((o=i.select(this).on("dblclick.zoom"))&&o.apply(this,arguments));t&&(q=setTimeout(function(){q=null},A),r.interrupt(this),u.start())}}function Y(){var t,e,n,o,r=x(this,arguments),u=i.event.changedTouches,h=u.length;for(y(),q&&(q=clearTimeout(q)),t=0;t<h;++t)e=u[t],n=i.touch(this,u,e.identifier),r.touch0&&r.touch0[2]===e.identifier?r.touch0[0]=n:r.touch1&&r.touch1[2]===e.identifier&&(r.touch1[0]=n);if(e=r.that.__zoom,r.touch1){var c=r.touch0[0],a=r.touch0[1],f=r.touch1[0],l=r.touch1[1],m=(m=f[0]-c[0])*m+(m=f[1]-c[1])*m,p=(p=l[0]-a[0])*p+(p=l[1]-a[1])*p;e=s(e,Math.sqrt(m/p)),n=[(c[0]+f[0])/2,(c[1]+f[1])/2],o=[(a[0]+l[0])/2,(a[1]+l[1])/2]}else{if(!r.touch0)return;n=r.touch0[0],o=r.touch0[1]}r.zoom("touch",z(v(e,n,o),r.extent))}function X(){var t,e,n=x(this,arguments),o=i.event.changedTouches,r=o.length;for(c(),E&&clearTimeout(E),E=setTimeout(function(){E=null},A),t=0;t<r;++t)e=o[t],n.touch0&&n.touch0[2]===e.identifier?delete n.touch0:n.touch1&&n.touch1[2]===e.identifier&&delete n.touch1;n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0?n.touch0[1]=this.__zoom.invert(n.touch0[0]):n.end()}var q,E,D=a,V=f,I=m,P=0,S=1/0,j=-S,B=S,G=j,H=B,K=250,O=o.interpolateZoom,W=[],Z=e.dispatch("start","zoom","end"),A=500,C=150,F=0;return t.transform=function(t,e){var n=t.selection?t.selection():t;n.property("__zoom",l),t!==n?g(t,e):n.interrupt().each(function(){x(this,arguments).start().zoom(null,"function"==typeof e?e.apply(this,arguments):e).end()})},t.scaleBy=function(e,n){t.scaleTo(e,function(){return this.__zoom.k*("function"==typeof n?n.apply(this,arguments):n)})},t.scaleTo=function(e,n){t.transform(e,function(){var t=V.apply(this,arguments),e=this.__zoom,o=_(t),i=e.invert(o);return z(v(s(e,"function"==typeof n?n.apply(this,arguments):n),o,i),t)})},t.translateBy=function(e,n,o){t.transform(e,function(){return z(this.__zoom.translate("function"==typeof n?n.apply(this,arguments):n,"function"==typeof o?o.apply(this,arguments):o),V.apply(this,arguments))})},k.prototype={start:function(){return 1==++this.active&&(this.index=W.push(this)-1,this.emit("start")),this},zoom:function(t,e){return this.mouse&&"mouse"!==t&&(this.mouse[1]=e.invert(this.mouse[0])),this.touch0&&"touch"!==t&&(this.touch0[1]=e.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=e.invert(this.touch1[0])),this.that.__zoom=e,this.emit("zoom"),this},end:function(){return 0==--this.active&&(W.splice(this.index,1),this.index=-1,this.emit("end")),this},emit:function(e){i.customEvent(new u(t,e,this.that.__zoom),Z.apply,Z,[e,this.that,this.args])}},t.wheelDelta=function(e){return arguments.length?(I="function"==typeof e?e:d(+e),t):I},t.filter=function(e){return arguments.length?(D="function"==typeof e?e:d(!!e),t):D},t.extent=function(e){return arguments.length?(V="function"==typeof e?e:d([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),t):V},t.scaleExtent=function(e){return arguments.length?(P=+e[0],S=+e[1],t):[P,S]},t.translateExtent=function(e){return arguments.length?(j=+e[0][0],B=+e[1][0],G=+e[0][1],H=+e[1][1],t):[[j,G],[B,H]]},t.duration=function(e){return arguments.length?(K=+e,t):K},t.interpolate=function(e){return arguments.length?(O=e,t):O},t.on=function(){var e=Z.on.apply(Z,arguments);return e===Z?t:e},t.clickDistance=function(e){return arguments.length?(F=(e=+e)*e,t):Math.sqrt(F)},t},t.zoomTransform=s,t.zoomIdentity=v,Object.defineProperty(t,"__esModule",{value:!0})});
// https://d3js.org/d3-zoom/ Version 1.5.0. Copyright 2017 Mike Bostock.
!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=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,n,e,o,i,r){"use strict";function u(t,n,e){this.target=t,this.type=n,this.transform=e}function h(t,n,e){this.k=t,this.x=n,this.y=e}function s(t){return t.__zoom||v}function c(){i.event.stopImmediatePropagation()}function a(){return!i.event.button}function f(){var t,n,e=this;return e instanceof SVGElement?(t=(e=e.ownerSVGElement||e).width.baseVal.value,n=e.height.baseVal.value):(t=e.clientWidth,n=e.clientHeight),[[0,0],[t,n]]}function l(){return this.__zoom||v}function m(){return-i.event.deltaY*(i.event.deltaMode?120:1)/500}function p(){return"ontouchstart"in this}var d=function(t){return function(){return t}};h.prototype={constructor:h,scale:function(t){return 1===t?this:new h(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new h(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 v=new h(1,0,0);s.prototype=h.prototype;var y=function(){i.event.preventDefault(),i.event.stopImmediatePropagation()};t.zoom=function(){function t(t){t.property("__zoom",l).on("wheel.zoom",M).on("mousedown.zoom",T).on("dblclick.zoom",b).filter(p).on("touchstart.zoom",Y).on("touchmove.zoom",X).on("touchend.zoom touchcancel.zoom",q).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function s(t,n){return(n=Math.max(S,Math.min(j,n)))===t.k?t:new h(n,t.x,t.y)}function z(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 h(t.k,o,i)}function _(t,n){var e=t.invertX(n[0][0])-B,o=t.invertX(n[1][0])-G,i=t.invertY(n[0][1])-H,r=t.invertY(n[1][1])-K;return t.translate(o>e?(e+o)/2:Math.min(0,e)||Math.max(0,o),r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r))}function g(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function k(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,o=arguments,i=x(t,o),r=I.apply(t,o),u=e||g(r),s=Math.max(r[1][0]-r[0][0],r[1][1]-r[0][1]),c=t.__zoom,a="function"==typeof n?n.apply(t,o):n,f=W(c.invert(u).concat(s/c.k),a.invert(u).concat(s/a.k));return function(t){if(1===t)t=a;else{var n=f(t),e=s/n[2];t=new h(e,u[0]-n[0]*e,u[1]-n[1]*e)}i.zoom(null,t)}})}function x(t,n){for(var e,o=0,i=Z.length;o<i;++o)if((e=Z[o]).that===t)return e;return new w(t,n)}function w(t,n){this.that=t,this.args=n,this.index=-1,this.active=0,this.extent=I.apply(t,n)}function M(){if(V.apply(this,arguments)){var t=x(this,arguments),n=this.__zoom,e=Math.max(S,Math.min(j,n.k*Math.pow(2,P.apply(this,arguments)))),o=i.mouse(this);if(t.wheel)t.mouse[0][0]===o[0]&&t.mouse[0][1]===o[1]||(t.mouse[1]=n.invert(t.mouse[0]=o)),clearTimeout(t.wheel);else{if(n.k===e)return;t.mouse=[o,n.invert(o)],r.interrupt(this),t.start()}y(),t.wheel=setTimeout(function(){t.wheel=null,t.end()},F),t.zoom("mouse",_(z(s(n,e),t.mouse[0],t.mouse[1]),t.extent))}}function T(){if(!D&&V.apply(this,arguments)){var t=x(this,arguments),n=i.select(i.event.view).on("mousemove.zoom",function(){if(y(),!t.moved){var n=i.event.clientX-u,e=i.event.clientY-h;t.moved=n*n+e*e>J}t.zoom("mouse",_(z(t.that.__zoom,t.mouse[0]=i.mouse(t.that),t.mouse[1]),t.extent))},!0).on("mouseup.zoom",function(){n.on("mousemove.zoom mouseup.zoom",null),e.dragEnable(i.event.view,t.moved),y(),t.end()},!0),o=i.mouse(this),u=i.event.clientX,h=i.event.clientY;e.dragDisable(i.event.view),c(),t.mouse=[o,this.__zoom.invert(o)],r.interrupt(this),t.start()}}function b(){if(V.apply(this,arguments)){var n=this.__zoom,e=i.mouse(this),o=n.invert(e),r=_(z(s(n,n.k*(i.event.shiftKey?.5:2)),e,o),I.apply(this,arguments));y(),O>0?i.select(this).transition().duration(O).call(k,r,e):i.select(this).call(t.transform,r)}}function Y(){if(V.apply(this,arguments)){var t,n,e,o,u=x(this,arguments),h=i.event.changedTouches,s=h.length;for(c(),n=0;n<s;++n)e=h[n],o=[o=i.touch(this,h,e.identifier),this.__zoom.invert(o),e.identifier],u.touch0?u.touch1||(u.touch1=o):(u.touch0=o,t=!0);if(E&&(E=clearTimeout(E),!u.touch1))return u.end(),void((o=i.select(this).on("dblclick.zoom"))&&o.apply(this,arguments));t&&(E=setTimeout(function(){E=null},C),r.interrupt(this),u.start())}}function X(){var t,n,e,o,r=x(this,arguments),u=i.event.changedTouches,h=u.length;for(y(),E&&(E=clearTimeout(E)),t=0;t<h;++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 c=r.touch0[0],a=r.touch0[1],f=r.touch1[0],l=r.touch1[1],m=(m=f[0]-c[0])*m+(m=f[1]-c[1])*m,p=(p=l[0]-a[0])*p+(p=l[1]-a[1])*p;n=s(n,Math.sqrt(m/p)),e=[(c[0]+f[0])/2,(c[1]+f[1])/2],o=[(a[0]+l[0])/2,(a[1]+l[1])/2]}else{if(!r.touch0)return;e=r.touch0[0],o=r.touch0[1]}r.zoom("touch",_(z(n,e,o),r.extent))}function q(){var t,n,e=x(this,arguments),o=i.event.changedTouches,r=o.length;for(c(),D&&clearTimeout(D),D=setTimeout(function(){D=null},C),t=0;t<r;++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.touch0[1]=this.__zoom.invert(e.touch0[0]):e.end()}var E,D,V=a,I=f,P=m,S=0,j=1/0,B=-j,G=j,H=B,K=G,O=250,W=o.interpolateZoom,Z=[],A=n.dispatch("start","zoom","end"),C=500,F=150,J=0;return t.transform=function(t,n){var e=t.selection?t.selection():t;e.property("__zoom",l),t!==e?k(t,n):e.interrupt().each(function(){x(this,arguments).start().zoom(null,"function"==typeof n?n.apply(this,arguments):n).end()})},t.scaleBy=function(n,e){t.scaleTo(n,function(){return this.__zoom.k*("function"==typeof e?e.apply(this,arguments):e)})},t.scaleTo=function(n,e){t.transform(n,function(){var t=I.apply(this,arguments),n=this.__zoom,o=g(t),i=n.invert(o);return _(z(s(n,"function"==typeof e?e.apply(this,arguments):e),o,i),t)})},t.translateBy=function(n,e,o){t.transform(n,function(){return _(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof o?o.apply(this,arguments):o),I.apply(this,arguments))})},t.translateTo=function(n,e,o){t.transform(n,function(){var t=I.apply(this,arguments),n=this.__zoom,i=g(t);return _(v.translate(i[0],i[1]).scale(n.k).translate("function"==typeof e?-e.apply(this,arguments):-e,"function"==typeof o?-o.apply(this,arguments):-o),t)})},w.prototype={start:function(){return 1==++this.active&&(this.index=Z.push(this)-1,this.emit("start")),this},zoom:function(t,n){return this.mouse&&"mouse"!==t&&(this.mouse[1]=n.invert(this.mouse[0])),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&&(Z.splice(this.index,1),this.index=-1,this.emit("end")),this},emit:function(n){i.customEvent(new u(t,n,this.that.__zoom),A.apply,A,[n,this.that,this.args])}},t.wheelDelta=function(n){return arguments.length?(P="function"==typeof n?n:d(+n),t):P},t.filter=function(n){return arguments.length?(V="function"==typeof n?n:d(!!n),t):V},t.extent=function(n){return arguments.length?(I="function"==typeof n?n:d([[+n[0][0],+n[0][1]],[+n[1][0],+n[1][1]]]),t):I},t.scaleExtent=function(n){return arguments.length?(S=+n[0],j=+n[1],t):[S,j]},t.translateExtent=function(n){return arguments.length?(B=+n[0][0],G=+n[1][0],H=+n[0][1],K=+n[1][1],t):[[B,H],[G,K]]},t.duration=function(n){return arguments.length?(O=+n,t):O},t.interpolate=function(n){return arguments.length?(W=n,t):W},t.on=function(){var n=A.on.apply(A,arguments);return n===A?t:n},t.clickDistance=function(n){return arguments.length?(J=(n=+n)*n,t):Math.sqrt(J)},t},t.zoomTransform=s,t.zoomIdentity=v,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "d3-zoom",
"version": "1.4.0",
"version": "1.5.0",
"description": "Pan and zoom SVG, HTML or Canvas using mouse or touch input.",

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

@@ -126,7 +126,11 @@ # d3-zoom

If *selection* is a selection, [translates](#transform_translate) the [current zoom transform](#zoomTransform) of the selected elements by *x* and *y*, such that the new *t<sub>x1</sub>* = *t<sub>x0</sub>* + *k* × *x* and *t<sub>y1</sub>* = *t<sub>y0</sub>* + *k* × *y*. If *selection* is a transition, defines a “zoom” tween translating the current transform. This method is a convenience method for [*zoom*.transform](#zoom_transform). The *x* and *y* translation amounts may be specified either as numbers or as functions that returns numbers. If a function, it is invoked for each selected element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element.
If *selection* is a selection, [translates](#transform_translate) the [current zoom transform](#zoomTransform) of the selected elements by *x* and *y*, such that the new *t<sub>x1</sub>* = *t<sub>x0</sub>* + *kx* and *t<sub>y1</sub>* = *t<sub>y0</sub>* + *ky*. If *selection* is a transition, defines a “zoom” tween translating the current transform. This method is a convenience method for [*zoom*.transform](#zoom_transform). The *x* and *y* translation amounts may be specified either as numbers or as functions that returns numbers. If a function, it is invoked for each selected element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element.
<a href="#zoom_translateTo" name="zoom_translateTo">#</a> <i>zoom</i>.<b>translateTo</b>(<i>selection</i>, <i>x</i>, <i>y</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/zoom.js#L118 "Source")
If *selection* is a selection, [translates](#transform_translate) the [current zoom transform](#zoomTransform) of the selected elements such that the specified position ⟨*x*,*y*⟩ appears at the center of the [viewport extent](#zoom_extent). The new *t<sub>x</sub>* = *c<sub>x</sub>* - *kx* and *t<sub>y</sub>* = *c<sub>y</sub>* - *ky*, where ⟨*c<sub>x</sub>*,*c<sub>y</sub>*⟩ is the center. If *selection* is a transition, defines a “zoom” tween translating the current transform. This method is a convenience method for [*zoom*.transform](#zoom_transform). The *x* and *y* coordinates may be specified either as numbers or as functions that returns numbers. If a function, it is invoked for each selected element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element.
<a href="#zoom_scaleBy" name="zoom_scaleBy">#</a> <i>zoom</i>.<b>scaleBy</b>(<i>selection</i>, <i>k</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/zoom.js#L90 "Source")
If *selection* is a selection, [scales](#transform_scale) the [current zoom transform](#zoomTransform) of the selected elements by *k*, such that the new *k₁* = *k₀* × *k*. If *selection* is a transition, defines a “zoom” tween translating the current transform. This method is a convenience method for [*zoom*.transform](#zoom_transform). The *k* scale factor may be specified either as numbers or as functions that returns numbers. If a function, it is invoked for each selected element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element.
If *selection* is a selection, [scales](#transform_scale) the [current zoom transform](#zoomTransform) of the selected elements by *k*, such that the new *k₁* = *k₀k*. If *selection* is a transition, defines a “zoom” tween translating the current transform. This method is a convenience method for [*zoom*.transform](#zoom_transform). The *k* scale factor may be specified either as numbers or as functions that returns numbers. If a function, it is invoked for each selected element, being passed the current datum `d` and index `i`, with the `this` context as the current DOM element.

@@ -252,3 +256,3 @@ <a href="#zoom_scaleTo" name="zoom_scaleTo">#</a> <i>zoom</i>.<b>scaleTo</b>(<i>selection</i>, <i>k</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/zoom.js#L98 "Source")

(This matrix is capable of representing only scale and translation; a future release may also allow rotation, though this would probably not be a backwards-compatible change.) The position ⟨*x*,*y*⟩ is transformed to ⟨*x* × *k* + *t<sub>x</sub>*,*y* × *k* + *t<sub>y</sub>*⟩. The transform object exposes the following properties:
(This matrix is capable of representing only scale and translation; a future release may also allow rotation, though this would probably not be a backwards-compatible change.) The position ⟨*x*,*y*⟩ is transformed to ⟨*xk* + *t<sub>x</sub>*,*yk* + *t<sub>y</sub>*⟩. The transform object exposes the following properties:

@@ -295,3 +299,3 @@ * *transform*.x - the translation amount *t<sub>x</sub>* along the *x*-axis.

Returns a transform whose scale *k₁* is equal to *k₀* × *k*, where *k₀* is this transform’s scale.
Returns a transform whose scale *k₁* is equal to *k₀k*, where *k₀* is this transform’s scale.

@@ -304,11 +308,11 @@ <a href="#transform_translate" name="transform_translate">#</a> <i>transform</i>.<b>translate</b>(<i>x</i>, <i>y</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/transform.js#L12 "Source")

Returns the transformation of the specified *point* which is a two-element array of numbers [*x*, *y*]. The returned point is equal to [*x* × *k* + *t<sub>x</sub>*, *y* × *k* + *t<sub>y</sub>*].
Returns the transformation of the specified *point* which is a two-element array of numbers [*x*, *y*]. The returned point is equal to [*xk* + *t<sub>x</sub>*, *yk* + *t<sub>y</sub>*].
<a href="#transform_applyX" name="transform_applyX">#</a> <i>transform</i>.<b>applyX</b>(<i>x</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/transform.js#L18 "Source")
Returns the transformation of the specified *x*-coordinate, *x* × *k* + *t<sub>x</sub>*.
Returns the transformation of the specified *x*-coordinate, *xk* + *t<sub>x</sub>*.
<a href="#transform_applyY" name="transform_applyY">#</a> <i>transform</i>.<b>applyY</b>(<i>y</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/transform.js#L21 "Source")
Returns the transformation of the specified *y*-coordinate, *y* × *k* + *t<sub>y</sub>*.
Returns the transformation of the specified *y*-coordinate, *yk* + *t<sub>y</sub>*.

@@ -315,0 +319,0 @@ <a href="#transform_invert" name="transform_invert">#</a> <i>transform</i>.<b>invert</b>(<i>point</i>) [<>](https://github.com/d3/d3-zoom/blob/master/src/transform.js#L24 "Source")

@@ -118,2 +118,14 @@ import {dispatch} from "d3-dispatch";

zoom.translateTo = function(selection, x, y) {
zoom.transform(selection, function() {
var e = extent.apply(this, arguments),
t = this.__zoom,
p = centroid(e);
return constrain(identity.translate(p[0], p[1]).scale(t.k).translate(
typeof x === "function" ? -x.apply(this, arguments) : -x,
typeof y === "function" ? -y.apply(this, arguments) : -y
), e);
});
};
function scale(transform, k) {

@@ -120,0 +132,0 @@ k = Math.max(k0, Math.min(k1, k));

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