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.

3 lines
8.3 KiB

1 year ago
// https://d3js.org/d3-brush/ v1.0.6 Copyright 2018 Mike Bostock
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-selection"),require("d3-dispatch"),require("d3-drag"),require("d3-interpolate"),require("d3-transition")):"function"==typeof define&&define.amd?define(["exports","d3-selection","d3-dispatch","d3-drag","d3-interpolate","d3-transition"],e):e(t.d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,e,n,r,s,i){"use strict";function a(t){return function(){return t}}function u(t,e,n){this.target=t,this.type=e,this.selection=n}function o(){e.event.stopImmediatePropagation()}function l(){e.event.preventDefault(),e.event.stopImmediatePropagation()}var c={name:"drag"},h={name:"space"},f={name:"handle"},p={name:"center"},d={name:"x",handles:["e","w"].map(_),input:function(t,e){return t&&[[t[0],e[0][1]],[t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},v={name:"y",handles:["n","s"].map(_),input:function(t,e){return t&&[[e[0][0],t[0]],[e[1][0],t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},m={name:"xy",handles:["n","e","s","w","nw","ne","se","sw"].map(_),input:function(t){return t},output:function(t){return t}},y={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},b={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},w={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},g={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},x={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function _(t){return{type:t}}function M(){return!e.event.button}function k(){var t=this.ownerSVGElement||this;return[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function z(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function A(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}function q(t){var m,q=k,E=M,K=n.dispatch(S,"start","brush","end"),P=6;function S(n){var r=n.property("__brush",D).selectAll(".overlay").data([_("overlay")]);r.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",y.overlay).merge(r).each(function(){var t=z(this).extent;e.select(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])}),n.selectAll(".selection").data([_("selection")]).enter().append("rect").attr("class","selection").attr("cursor",y.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var s=n.selectAll(".handle").data(t.handles,function(t){return t.type});s.exit().remove(),s.enter().append("rect").attr("class",function(t){return"handle handle--"+t.type}).attr("cursor",function(t){return y[t.type]}),n.each(T).attr("fill","none").attr("pointer-events","all").style("-webkit-tap-highlight-color","rgba(0,0,0,0)").on("mousedown.brush touchstart.brush",C)}function T(){var t=e.select(this),n=z(this).selection;n?(t.selectAll(".selection").style("display",null).attr("x",n[0][0]).attr("y",n[0][1]).attr("width",n[1][0]-n[0][0]).attr("height",n[1][1]-n[0][1]),t.selectAll(".handle").style("display",null).attr("x",function(t){return"e"===t.type[t.type.length-1]?n[1][0]-P/2:n[0][0]-P/2}).attr("y",function(t){return"s"===t.type[0]?n[1][1]-P/2:n[0][1]-P/2}).attr("width",function(t){return"n"===t.type||"s"===t.type?n[1][0]-n[0][0]+P:P}).attr("height",function(t){return"e"===t.type||"w"===t.type?n[1][1]-n[0][1]+P:P})):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function V(t,e){return t.__brush.emitter||new j(t,e)}function j(t,e){this.that=t,this.args=e,this.state=t.__brush,this.active=0}function C(){if(e.event.touches){if(e.event.changedTouches.length<e.event.touches.length)return l()}else if(m)return;if(E.apply(this,arguments)){var n,s,a,u,_,M,k,q,K,P,S,j,C,D=this,I=e.event.target.__data__.type,G="selection"===(e.event.metaKey?I="overlay":I)?c:e.event.altKey?p:f,N=t===v?null:g[I],O=t===d?null:x[I],X=z(D),Y=X.extent,B=X.selection,F=Y[0][0],H=Y[0][1],J=Y[1][0],L=Y[1][1],Q=N&&O&&e.event.shiftKey,R=e.mou