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

5 years ago
// 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.mo