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
3.6 KiB

5 years ago
// https://d3js.org/d3-drag/ Version 1.2.1. Copyright 2017 Mike Bostock.
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-dispatch"),require("d3-selection")):"function"==typeof define&&define.amd?define(["exports","d3-dispatch","d3-selection"],e):e(t.d3=t.d3||{},t.d3,t.d3)}(this,function(t,e,n){"use strict";function o(){n.event.stopImmediatePropagation()}function i(t,e){var o=t.document.documentElement,i=n.select(t).on("dragstart.drag",null);e&&(i.on("click.drag",l,!0),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in o?i.on("selectstart.drag",null):(o.style.MozUserSelect=o.__noselect,delete o.__noselect)}function r(t,e,n,o,i,r,c,u,s,a){this.target=t,this.type=e,this.subject=n,this.identifier=o,this.active=i,this.x=r,this.y=c,this.dx=u,this.dy=s,this._=a}function c(){return!n.event.button}function u(){return this.parentNode}function s(t){return null==t?{x:n.event.x,y:n.event.y}:t}function a(){return"ontouchstart"in this}var l=function(){n.event.preventDefault(),n.event.stopImmediatePropagation()},d=function(t){var e=t.document.documentElement,o=n.select(t).on("dragstart.drag",l,!0);"onselectstart"in e?o.on("selectstart.drag",l,!0):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")},f=function(t){return function(){return t}};r.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};t.drag=function(){function t(t){t.on("mousedown.drag",h).filter(M).on("touchstart.drag",g).on("touchmove.drag",m).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(){if(!T&&j.apply(this,arguments)){var t=b("mouse",k.apply(this,arguments),n.mouse,this,arguments);t&&(n.select(n.event.view).on("mousemove.drag",p,!0).on("mouseup.drag",v,!0),d(n.event.view),o(),x=!1,_=n.event.clientX,w=n.event.clientY,t("start"))}}function p(){if(l(),!x){var t=n.event.clientX-_,e=n.event.clientY-w;x=t*t+e*e>P}q.mouse("drag")}function v(){n.select(n.event.view).on("mousemove.drag mouseup.drag",null),i(n.event.view,x),l(),q.mouse("end")}function g(){if(j.apply(this,arguments)){var t,e,i=n.event.changedTouches,r=k.apply(this,arguments),c=i.length;for(t=0;t<c;++t)(e=b(i[t].identifier,r,n.touch,this,arguments))&&(o(),e("start"))}}function m(){var t,e,o=n.event.changedTouches,i=o.length;for(t=0;t<i;++t)(e=q[o[t].identifier])&&(l(),e("drag"))}function y(){var t,e,i=n.event.changedTouches,r=i.length;for(T&&clearTimeout(T),T=setTimeout(function(){T=null},500),t=0;t<r;++t)(e=q[i[t].identifier])&&(o(),e("end"))}function b(e,o,i,c,u){var s,a,l,d=i(o,e),f=z.copy();if(n.customEvent(new r(t,"beforestart",s,e,D,d[0],d[1],0,0,f),function(){return null!=(n.event.subject=s=E.apply(c,u))&&(a=s.x-d[0]||0,l=s.y-d[1]||0,!0)}))return function h(p){var v,g=d;switch(p){case"start":q[e]=h,v=D++;break;case"end":delete q[e],--D;case"drag":d=i(o,e),v=D}n.customEvent(new r(t,p,s,e,v,d[0]+a,d[1]+l,d[0]-g[0],d[1]-g[1],f),f.apply,f,[p,c,u])}}var _,w,x,T,j=c,k=u,E=s,M=a,q={},z=e.dispatch("start","drag","end"),D=0,P=0;return t.filter=function(e){return arguments.length?(j="function"==typeof e?e:f(!!e),t):j},t.container=function(e){return arguments.length?(k="function"==typeof e?e:f(e),t):k},t.subject=function(e){return arguments.length?(E="function"==typeof e?e:f(e),t):E},t.touchable=function(e){return arguments.length?(M="function"==typeof e?e:f(!!e),t):M},t.on=function(){var e=z.on.apply(z,arguments);return e===z?t:e},t.clickDistance=function(e){return arguments.length?(P=(e=+e)*e,t):Math.sqrt(P)},t},t.dragDisable=d,t.dragEnable=i,Object.defineProperty(t,"__esModule",{value:!0})});