ht-overview.js 3.7 KB

1
  1. !function(I,h){"use strict";var k="ht",W=k+".graph.",G=I[k],a=G.graph,B=G.Default,O=G.Color,$=null,N="px",D=B.getInternal(),C=D.getPinchDist,J=B.preventDefault,d=B.getTouchCount,s=B.startDragging;D.addMethod(B,{overviewBackground:O.widgetBackground,overviewMaskBackground:O.transparent,overviewContentBorderColor:O.widgetBorder,overviewContentBackground:O.background},!0),a.Overview=function(X){var S=this,w=S._view=D.createView(1,S);S._canvas=D.createCanvas(w),w.style.background=B.overviewBackground,w.appendChild(S._mask=D.createDiv()),S.setGraphView(X),S.addListeners()},B.def(W+"Overview",h,{ms_v:1,ms_fire:1,ms_listener:1,ms_ac:["maskBackground","contentBorderColor","contentBackground","autoUpdate"],_autoUpdate:!0,_rate:1,_scrollRect:{x:0,y:0,width:0,height:0},_maskBackground:B.overviewMaskBackground,_contentBorderColor:B.overviewContentBorderColor,_contentBackground:B.overviewContentBackground,getGraphView:function(){return this.gv},setGraphView:function(V){var h=this;if(h.gv!==V){var U=h.gv;h.gv=V,U&&(U.removeViewListener(h.handleGraphViewChanged,h),U.ump(h.handleGraphViewPropertyChanged,h)),V&&(V.addViewListener(h.handleGraphViewChanged,h),V.mp(h.handleGraphViewPropertyChanged,h)),h.fp("graphView",U,V),h.redraw()}},getCanvas:function(){return this._canvas},getMask:function(){return this._mask},dispose:function(){this.setGraphView(null)},onPropertyChanged:function(){this.redraw()},handleGraphViewChanged:function(D){this._autoUpdate&&"validate"===D.kind&&this.redraw()},handleGraphViewPropertyChanged:function(Z){"canvasBackground"===Z.property&&this.redraw()},redraw:function(){var C=this;C._redraw||(C._redraw=1,C.iv(50))},validateImpl:function(){var b=this,U=b.gv,R=b._canvas,s=b.getWidth(),L=b.getHeight(),_=b._redraw;if(U){var X=b._mask,d=X.style,V=U.getViewRect(),c=U.getScrollRect(),a=c.x,g=c.y,i=c.width,G=c.height,j=b._rate=Math.max(i/s,G/L),k=b._x=(s-i/j)/2,M=b._y=(L-G/j)/2;if(0!==V.width&&0!==V.height||b.hasRetry||(B.callLater(b.iv,b,$),b.hasRetry=!0),(s!==R.clientWidth||L!==R.clientHeight)&&(D.setCanvas(R,s,L),_=1),D.isSameRect(c,b._scrollRect)||(b._scrollRect=c,_=1),_){var y=D.initContext(R),t=U.getDataModel().getBackground()||b._contentBackground,C=b._contentBorderColor,m=B.devicePixelRatio;y.clearRect(0,0,s*m,L*m),t&&D.fillRect(y,k*m,M*m,i/j*m,G/j*m,t),D.translateAndScale(y,-a/j+k,-g/j+M,1/j),U._42(y),y.restore(),C&&D.drawBorder(y,C,k*m,M*m,i/j*m,G/j*m)}d.background=b._maskBackground,d.left=k+(V.x-a)/j+N,d.top=M+(V.y-g)/j+N,d.width=V.width/j+N,d.height=V.height/j+N,b._redraw=null}else if(_){var y=D.initContext(R);y.clearRect(0,0,s,L),y.restore(),b._redraw=null}},center:function(q){var f=this,Y=f.gv;if(Y){var T=Y._zoom,v=Y._29I,V=f._rate,a=f._scrollRect,r=B.getLogicalPoint(q,f._canvas),X=a.x+(r.x-f._x)*V,j=a.y+(r.y-f._y)*V;Y.setTranslate((v.width/2-X)*T,(v.height/2-j)*T)}},handle_mousedown:function(s){this.handle_touchstart(s)},handleWindowMouseUp:function(t){this.handleWindowTouchEnd(t)},handleWindowMouseMove:function(Y){this.handleWindowTouchMove(Y)},handle_mousewheel:function(e){this.handleScroll(e,e.wheelDelta)},handle_DOMMouseScroll:function(X){2===X.axis&&this.handleScroll(X,-X.detail)},handleScroll:function(m,z){if(J(m),this.gv){var b=this.gv;z>0?b.scrollZoomIn():0>z&&b.scrollZoomOut()}},handle_touchstart:function(G){if(J(G),this.gv&&B.isLeftButton(G)){var A=this,z=A.gv,K=d(G);1===K?B.isDoubleClick(G)&&z.isResettable()?z.reset():(A.center(G),s(A,G)):2===K&&(A._dist=C(G),s(A,G))}},handleWindowTouchEnd:function(){delete this._dist},handleWindowTouchMove:function(a){if(this.gv){var z=this,H=z._dist,M=d(a);1===M?z.center(a):2===M&&H!=$&&z.gv.handlePinch($,C(a),H)}}})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:this,Object);