mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
3 lines
10 KiB
JavaScript
3 lines
10 KiB
JavaScript
|
import{dispatch as t}from"d3-dispatch";import{dragDisable as o,dragEnable as e}from"d3-drag";import{interpolateZoom as n}from"d3-interpolate";import{select as i,pointer as r}from"d3-selection";import{interrupt as u}from"d3-transition";var constant=t=>()=>t;function ZoomEvent(t,{sourceEvent:o,target:e,transform:n,dispatch:i}){Object.defineProperties(this,{type:{value:t,enumerable:true,configurable:true},sourceEvent:{value:o,enumerable:true,configurable:true},target:{value:e,enumerable:true,configurable:true},transform:{value:n,enumerable:true,configurable:true},_:{value:i}})}function Transform(t,o,e){this.k=t;this.x=o;this.y=e}Transform.prototype={constructor:Transform,scale:function(t){return 1===t?this:new Transform(this.k*t,this.x,this.y)},translate:function(t,o){return 0===t&0===o?this:new Transform(this.k,this.x+this.k*t,this.y+this.k*o)},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 s=new Transform(1,0,0);transform.prototype=Transform.prototype;function transform(t){while(!t.__zoom)if(!(t=t.parentNode))return s;return t.__zoom}function nopropagation(t){t.stopImmediatePropagation()}function noevent(t){t.preventDefault();t.stopImmediatePropagation()}function defaultFilter(t){return(!t.ctrlKey||"wheel"===t.type)&&!t.button}function defaultExtent(){var t=this;if(t instanceof SVGElement){t=t.ownerSVGElement||t;if(t.hasAttribute("viewBox")){t=t.viewBox.baseVal;return[[t.x,t.y],[t.x+t.width,t.y+t.height]]}return[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}return[[0,0],[t.clientWidth,t.clientHeight]]}function defaultTransform(){return this.__zoom||s}function defaultWheelDelta(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function defaultTouchable(){return navigator.maxTouchPoints||"ontouchstart"in this}function defaultConstrain(t,o,e){var n=t.invertX(o[0][0])-e[0][0],i=t.invertX(o[1][0])-e[1][0],r=t.invertY(o[0][1])-e[0][1],u=t.invertY(o[1][1])-e[1][1];return t.translate(i>n?(n+i)/2:Math.min(0,n)||Math.max(0,i),u>r?(r+u)/2:Math.min(0,r)||Math.max(0,u))}function zoom(){var a,h,c,l=defaultFilter,m=defaultExtent,f=defaultConstrain,p=defaultWheelDelta,d=defaultTouchable,v=[0,Infinity],z=[[-Infinity,-Infinity],[Infinity,Infinity]],y=250,g=n,_=t("start","zoom","end"),w=500,T=150,k=0,x=10;function zoom(t){t.property("__zoom",defaultTransform).on("wheel.zoom",wheeled,{passive:false}).on("mousedown.zoom",mousedowned).on("dblclick.zoom",dblclicked).filter(d).on("touchstart.zoom",touchstarted).on("touchmove.zoom",touchmoved).on("touchend.zoom touchcancel.zoom",touchended).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}zoom.transform=function(t,o,e,n){var i=t.selection?t.selection():t;i.property("__zoom",defaultTransform);t!==i?schedule(t,o,e,n):i.interrupt().each((function(){gesture(this,arguments).event(n).start().zoom(null,"function"===typeof o?o.apply(this,arguments):o).end()}))};zoom.scaleBy=function(t,o,e,n){zoom.scaleTo(t,(function(){var t=this.__zoom.k,e="function"===typeof o?o.apply(this,arguments):o;return t*e}),e,n)};zoom.scaleTo=function(t,o,e,n){zoom.transform(t,(function(){var t=m.apply(this,arguments),n=this.__zoom,i=null==e?centroid(t):"function"===typeof e?e.apply(this,arguments):e,r=n.invert(i),u="function"===typeof o?o.apply(this,arguments):o;return f(translate(scale(n,u),i,r),t,z)}),e,n)};zoom.translateBy=function(t,o,e,n){zoom.transform(t,(function(){return f(this.__zoom.translate("function"===typeof o?o.apply(this,arguments):o,"function"===typeof e?e.apply(this,arguments):e),m.apply(this,arguments),z)}),null,n)};zoom.translateTo=function
|
||
|
|