// https://d3js.org/d3-brush/ v1.1.5 Copyright 2019 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=t||self).d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,e,n,r,i,s){"use strict";function u(t){return function(){return t}}function a(t,e,n){this.target=t,this.type=e,this.selection=n}function o(){i.event.stopImmediatePropagation()}function l(){i.event.preventDefault(),i.event.stopImmediatePropagation()}var c={name:"drag"},h={name:"space"},f={name:"handle"},d={name:"center"};function p(t){return[+t[0],+t[1]]}function v(t){return[p(t[0]),p(t[1])]}var y={name:"x",handles:["w","e"].map(k),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},m={name:"y",handles:["n","s"].map(k),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},b={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(k),input:function(t){return null==t?null:v(t)},output:function(t){return t}},w={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"},g={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},x={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},M={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},_={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function k(t){return{type:t}}function z(){return!i.event.ctrlKey&&!i.event.button}function A(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function q(){return navigator.maxTouchPoints||"ontouchstart"in this}function K(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function E(t){var p,b=A,E=z,P=q,T=!0,V=e.dispatch("start","brush","end"),S=6;function j(e){var n=e.property("__brush",O).selectAll(".overlay").data([k("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",w.overlay).merge(n).each(function(){var t=K(this).extent;i.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])}),e.selectAll(".selection").data([k("selection")]).enter().append("rect").attr("class","selection").attr("cursor",w.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=e.selectAll(".handle").data(t.handles,function(t){return t.type});r.exit().remove(),r.enter().append("rect").attr("class",function(t){return"handle handle--"+t.type}).attr("cursor",function(t){return w[t.type]}),e.each(B).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",I).filter(P).on("touchstart.brush",I).on("touchmove.brush",G).on("touchend.brush touchcancel.brush",N).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function B(){var t=i.select(this),e=K(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",function(t){return"e"===t.type[t.type.length-1]?e[1][0]-S/2:e[0][0]-S/2}).attr("y",function(t){return"s"===t.type[0]?e[1][1]-S/2:e[0][1]-S/2}).attr("width",function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+S:S}).attr("height",function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+S:S})):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function C(t,e,n){return!n&&t.__brush.emitter||new D(t,e)}function D(t,e){this.that=t,this.args=e,this.state=t.__brush,this.active=0}function I(){if((!p||i.event.touches)&&E.apply(this,arguments)){var e,r,u,a,v,b,k,z,A,q,P,V,S=this,j=i.event.target.__data__.type,D="selection"===(T&&i.event.metaKey?j="overlay":j)?c:T&&i.event.altKey?d:f,I=t===m?null:M[j],G=t===y?null:_[j],N=K(S),O=N.extent,X=N.selection,Y=O[0][0],F=O[0][1],H=O[1][0],J=O[1][1],L=0,Q=0,R=I&&G&&T&&i.event.shiftKey,U=i.event.touches?(V=i.event.changedTouches[0].identifier,function(t){return i.touch(t,i.event.touches,V)}):i.mouse,W=U(S),Z=W,$=C(S,arguments,!0).beforestart();"overlay"===j?(X&&(A=!0),N.selection=X=[[e=t===m?Y:W[0],u=t===y?F:W[1]],[v=t===m?H:e,k=t===y?J:u]]):(e=X[0][0],u=X[0][1],v=X[1][0],k=X[1][1]),r=e,a=u,b=v,z=k;var tt=i.select(S).attr("pointer-events","none"),et=tt.selectAll(".overlay").attr("cursor",w[j]);if(i.event.touches)$.moved=rt,$.ended=st;else{var nt=i.select(i.event.view).on("mousemove.brush",rt,!0).on("mouseup.brush",st,!0);T&&nt.on("keydown.brush",function(){switch(i.event.keyCode){case 16:R=I&&G;break;case 18:D===f&&(I&&(v=b-L*I,e=r+L*I),G&&(k=z-Q*G,u=a+Q*G),D=d,it());break;case 32:D!==f&&D!==d||(I<0?v=b-L:I>0&&(e=r-L),G<0?k=z-Q:G>0&&(u=a-Q),D=h,et.attr("cursor",w.selection),it());break;default:return}l()},!0).on("keyup.brush",function(){switch(i.event.keyCode){case 16:R&&(q=P=R=!1,it());break;case 18:D===d&&(I<0?v=b:I>0&&(e=r),G<0?k=z:G>0&&(u=a),D=f,it());break;case 32:D===h&&(i.event.altKey?(I&&(v=b-L*I,e=r+L*I),G&&(k=z-Q*G,u=a+Q*G),D=d):(I<0?v=b:I>0&&(e=r),G<0?k=z:G>0&&(u=a),D=f),et.attr("cursor",w[j]),it());break;default:return}l()},!0),n.dragDisable(i.event.view)}o(),s.interrupt(S),B.call(S),$.start()}function rt(){var t=U(S);!R||q||P||(Math.abs(t[0]-Z[0])>Math.abs(t[1]-Z[1])?P=!0:q=!0),Z=t,A=!0,l(),it()}function it(){var t;switch(L=Z[0]-W[0],Q=Z[1]-W[1],D){case h:case c:I&&(L=Math.max(Y-e,Math.min(H-v,L)),r=e+L,b=v+L),G&&(Q=Math.max(F-u,Math.min(J-k,Q)),a=u+Q,z=k+Q);break;case f:I<0?(L=Math.max(Y-e,Math.min(H-e,L)),r=e+L,b=v):I>0&&(L=Math.max(Y-v,Math.min(H-v,L)),r=e,b=v+L),G<0?(Q=Math.max(F-u,Math.min(J-u,Q)),a=u+Q,z=k):G>0&&(Q=Math.max(F-k,Math.min(J-k,Q)),a=u,z=k+Q);break;case d:I&&(r=Math.max(Y,Math.min(H,e-L*I)),b=Math.max(Y,Math.min(H,v+L*I))),G&&(a=Math.max(F,Math.min(J,u-Q*G)),z=Math.max(F,Math.min(J,k+Q*G)))}b