You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
8.7 KiB

// https://d3js.org/d3-zoom/ Version 1.7.1. 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||y}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||y}function m(){return-i.event.deltaY*(i.event.deltaMode?120:1)/500}function p(){return"ontouchstart"in this}function d(t,n,e){var o=t.invertX(n[0][0])-e[0][0],i=t.invertX(n[1][0])-e[1][0],r=t.invertY(n[0][1])-e[0][1],u=t.invertY(n[1][1])-e[1][1];return t.translate(i>o?(o+i)/2:Math.min(0,o)||Math.max(0,i),u>r?(r+u)/2:Math.min(0,r)||Math.max(0,u))}var v=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 y=new h(1,0,0);s.prototype=h.prototype;var z=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(j).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(B[0],Math.min(B[1],n)))===t.k?t:new h(n,t.x,t.y)}function _(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 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=K(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=O.length;o<i;++o)if((e=O[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(B[0],Math.min(B[1],n.k*Math.pow(2,S.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()}z(),t.wheel=setTimeout(function(){t.wheel=null,t.end()},A),t.zoom("mouse",P(_(s(n,e),t.mouse[0],t.mouse[1]),t.extent,G))}}function T(){if(!D&&V.apply(this,arguments)){var t=x(this,arguments),n=i.select(i.event.view).on("mousemove.zoom",function(){if(z(),!t.moved){var n=i.event.clientX-u,e=i.event.clientY-h;t.moved=n*n+e*e>C}t.zoom("mouse",P(_(t.that.__zoom,t.mouse[0]=i.mouse(t.that),t.mouse[1]),t.extent,G))},!0).on("mouseup.zoom",function(){n.on("mousemove.zoom mouseup.zoom",null),e.dragEnable(i.event.view,t.moved),z(),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=n.k*(i.event.shiftKey?.5:2),u=P(_(s(n,r),e,o),I.apply(this,arguments),G);z(),H>0?i.select(this).transition().duration(H).call(k,u,e):i.select(this).call(t.transform,u)}}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},Z),r.interrupt(this),u.start())}}function X(){var t,n,e,o,r=x(this,arguments),u=i.event.changedTouches,h=u.length;for(z(),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",P(_(n,e,o),r.extent,G))}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},Z),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=d,S=m,j=p,B=[0,1/0],G=[[-1/0,-1/0],[1/0,1/0]],H=250,K=o.interpolateZoom,O=[],W=n.dispatch("start","zoom","end"),Z=500,A=150,C=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),r="function"==typeof e?e.apply(this,arguments):e;return P(_(s(n,r),o,i),t,G)})},t.translateBy=function(n,e,o){t.transform(n,function(){return P(this.__zoom.translate("function"==typeof e?e.apply(this,arguments):e,"function"==typeof o?o.apply(this,arguments):o),I.apply(this,arguments),G)})},t.translateTo=function(n,e,o){t.transform(n,function(){var t=I.apply(this,arguments),n=this.__zoom,i=g(t);return P(y.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,G)})},w.prototype={start:function(){return 1==++this.active&&(this.index=O.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&&(O.splice(this.index,1),this.index=-1,this.emit("end")),this},emit:function(n){i.customEvent(new u(t,n,this.that.__zoom),W.apply,W,[n,this.that,this.args])}},t.wheelDelta=function(n){return arguments.length?(S="function"==typeof n?n:v(+n),t):S},t.filter=function(n){return arguments.length?(V="function"==typeof n?n:v(!!n),t):V},t.touchable=function(n){return arguments.length?(j="function"==typeof n?n:v(!!n),t):j},t.extent=function(n){return arguments.length?(I="function"==typeof n?n:v([[+n[0][0],+n[0][1]],[+n[1][0],+n[1][1]]]),t):I},t.scaleExtent=function(n){return arguments.length?(B[0]=+n[0],B[1]=+n[1],t):[B[0],B[1]]},t.translateExtent=function(n){return arguments.length?(G[0][0]=+n[0][0],G[1][0]=+n[1][0],G[0][1]=+n[0][1],G[1][1]=+n[1][1],t):[[G[0][0],G[0][1]],[G[1][0],G[1][1]]]},t.constrain=function(n){return arguments.length?(P=n,t):P},t.duration=function(n){return arguments.length?(H=+n,t):H},t.interpolate=function(n){return arguments.length?(K=n,t):K},t.on=function(){var n=W.on.apply(W,arguments);return n===W?t:n},t.clickDistance=function(n){return arguments.length?(C=(n=+n)*n,t):Math.sqrt(C)},t},t.zoomTransform=s,t.zoomIdentity=y,Object.defineProperty(t,"__esModule",{value:!0})});