1 |
- !function(N,t){"use strict";var W="ht",p=W+".layout.",S=N[W]||module.parent.exports.ht,V=S.List,F=S.DataModel,T=S.Node,s=S.Edge,o=S.Group,k=Math,r=k.sqrt,G=k.random,M=k.max,C=k.min,l=function(f){return f*f};S.Default.getInternal().addMSMap({ms_force:function(Y){Y._interval=50,Y._stepCount=10,Y._motionLimit=.01,Y._edgeRepulsion=.65,Y._nodeRepulsion=.65,Y._damper=1,Y._maxMotion=0,Y._motionRatio=0,Y.init=function(r){var C=this;r instanceof F?C.dm=r:C.gv=r,C._nodeMap={},C._nodes=new V,C._edges=new V},Y.start=function(){var V=this,P=V.gv;if(!V._timer){var u=V.cdm=P?P.dm():V.dm;u.mm(V.handleDataModelChange,V),u.md(V.handleDataPropertyChange,V),P&&P.mp(V.handleGV,V),u.each(function(D){if(V.isVisible(D)&&V.isLayoutable(D)&&D instanceof T)if(V instanceof J){var u=D.p3();D.p3([u[0]+G(),u[1]+G(),u[2]+G()])}else u=D.p(),D.p(u.x+G(),u.y+G())}),V._timer=setInterval(function(){V.relax()},V._interval),V._damper=1}},Y.stop=function(){var T=this;T._timer&&(T.cdm.umm(T.handleDataModelChange,T),T.cdm.umd(T.handleDataPropertyChange,T),T.gv&&T.gv.ump(T.handleGV,T),clearInterval(T._timer),delete T._timer,delete T.cdm)},Y.handleGV=function(B){var v=this;if("dataModel"===B.property){var E=B.oldValue,x=B.newValue;E&&(E.umm(v.handleDataModelChange,v),E.umd(v.handleDataPropertyChange,v)),this.cdm=x,x.mm(v.handleDataModelChange,v),x.md(v.handleDataPropertyChange,v)}},Y.relax=function(){var K=this;if(!(K._damper<.1&&K._maxMotion<K._motionLimit)){this.cdm.each(function(u){K.isVisible(u)&&(u instanceof s?K.addEdge(u):u instanceof T&&K.addNode(u))});for(var k,A,R=0,J=K._edges,Q=K._nodes,z=Q.size();R<K._stepCount;R++){for(J.each(K.relaxEdge,K),k=0;z>k;k++)for(A=0;z>A;A++)K.relaxNode(Q.get(k),Q.get(A));K.moveNode()}K._isAdjusting=1,Q.each(function(V){V.fix||(V.p?V.v.p3(V.p):V.v.p(V.x,V.y))}),delete K._isAdjusting,K._nodeMap={},Q.clear(),J.clear(),K.onRelaxed()}},Y.onRelaxed=function(){},Y.isRunning=function(){return!!this._timer},Y.isVisible=function(e){return e.s("layoutable")===!1?!1:this.gv?this.gv.isVisible(e):!0},Y.isLayoutable=function(K){if(K.s("layoutable")===!1)return!1;if(K instanceof o)return!1;var _=this;return _.gv?_.gv.isMovable(K)&&!_.gv.isSelected(K):!(_.cdm||_.dm).sm().co(K)},Y.getNodeRepulsion=function(){return this._nodeRepulsion},Y.setNodeRepulsion=function(i){this._nodeRepulsion=i,this._damper=1},Y.getEdgeRepulsion=function(){return this._edgeRepulsion},Y.setEdgeRepulsion=function(X){this._edgeRepulsion=X,this._damper=1},Y.getStepCount=function(){return this._stepCount},Y.setStepCount=function(L){this._stepCount=L,this._damper=1},Y.getInterval=function(){return this._interval},Y.setInterval=function(k){var u=this;u._interval!==k&&(u._interval=k,u._timer&&(clearInterval(u._timer),u._timer=setInterval(function(){u.relax()},k)))},Y.handleDataPropertyChange=function(E){!this._isAdjusting&&this.isVisible(E.data)&&(this._damper=1)},Y.handleDataModelChange=function(){this._damper=1},Y.damp=function(){var C=this._maxMotion,o=this._damper;this._motionRatio<=.001&&((.2>C||C>1&&.9>o)&&o>.01?this._damper-=.01:.4>C&&o>.003?this._damper-=.003:o>1e-4&&(this._damper-=1e-4)),C<this._motionLimit&&(this._damper=0)}}}),S.layout.ForceLayout=function(H){this.init(H)},S.Default.def(p+"ForceLayout",t,{ms_force:1,getLimitBounds:function(){return this._limitBounds},setLimitBounds:function(b){this._limitBounds=b,this._damper=1},getNodeSize:function(a){var n=this.gv;return n&&n.getDataUIBounds?n.getDataUIBounds(a):a.getRect()},addNode:function(A){var K=this,F=K._nodeMap[A._id];if(F)return F;var b=A.p();F={v:A,x:b.x,y:b.y,dx:0,dy:0,fix:!K.isLayoutable(A),s:K.getNodeSize(A)};var q=F.s,n=r(l(q.width)+l(q.height))*K._nodeRepulsion;return F.r=1>n?100:n,K._nodeMap[A._id]=F,K._nodes.add(F),F},addEdge:function(J){if(J._40I&&J._41I){var N=this,u=N.addNode(J._40I),m=N.addNode(J._41I),Y={s:u,t:m};m=m.s,u=u.s;var n=m.width+u.width,y=m.height+u.height;Y.length=r(n*n+y*y)*N._edgeRepulsion,Y.length<=0&&(Y.length=100),N._edges.add(Y)}},relaxEdge:function(g){var i=g.t,C=g.s,q=i.x-C.x,G=i.y-C.y,l=r(q*q+G*G),p=100*g.length,_=.25*q/p*l,u=.25*G/p*l;i.dx=i.dx-_,i.dy=i.dy-u,C.dx=C.dx+_,C.dy=C.dy+u},relaxNode:function(Z,S){if(Z!==S){var x=0,T=0,y=Z.x-S.x,N=Z.y-S.y,V=y*y+N*N;0===V?(x=G(),T=G()):36e4>V&&(x=y/V,T=N/V);var f=Z.r*S.r/400;x*=f,T*=f,Z.dx+=x,Z.dy+=T,S.dx-=x,S.dy-=T}},moveNode:function(){var p=this,n=p._limitBounds,z=p._maxMotion,t=0,s=p._damper;p._nodes.each(function(q){if(!q.fix){var i=q.dx*s,x=q.dy*s;if(q.dx=i/2,q.dy=x/2,t=M(r(i*i+x*x),t),q.x+=M(-40,C(40,i)),q.y+=M(-40,C(40,x)),n){q.x<n.x&&(q.x=n.x,p.adjust(1,0)),q.y<n.y&&(q.y=n.y,p.adjust(0,1));var D=q.s;q.x+D.width>n.x+n.width&&(q.x=n.x+n.width-D.width,p.adjust(-1,0)),q.y+D.height>n.y+n.height&&(q.y=n.y+n.height-D.height,p.adjust(0,-1))}}}),p._maxMotion=t,p._motionRatio=t>0?z/t-1:0,p.damp()},adjust:function(y,p){var j=this._limitBounds;this._nodes.each(function(L){y>0?(!j||L.x+L.s.width+y<j.x+j.width)&&(L.x+=y):(!j||L.x+y>j.x)&&(L.x+=y),p>0?(!j||L.y+L.s.height+p<j.y+j.height)&&(L.y+=p):(!j||L.y+p>j.y)&&(L.y+=p)})}});var J=S.layout.Force3dLayout=function(K){this.init(K)};S.Default.def(p+"Force3dLayout",t,{ms_force:1,getNodeSize3d:function(r){return r.s3()},addNode:function(e){var n=this,o=n._nodeMap[e._id];if(o)return o;o={v:e,p:e.p3(),d:[0,0,0],fix:!n.isLayoutable(e),s:n.getNodeSize3d(e)};var h=o.s,U=S.Default.getDistance(h)*n._nodeRepulsion;return o.r=1>U?100:U,n._nodeMap[e._id]=o,n._nodes.add(o),o},addEdge:function(e){if(e._40I&&e._41I){var g=this,T=g.addNode(e._40I),f=g.addNode(e._41I),W={s:T,t:f};f=f.s,T=T.s,W.length=r(l(f[0]+T[0])+l(f[1]+T[1])+l(f[2]+T[2]))*g._edgeRepulsion,W.length<=0&&(W.length=100),g._edges.add(W)}},relaxEdge:function(b){var s=b.t.p,l=b.s.p,u=b.t.d,q=b.s.d,B=s[0]-l[0],J=s[1]-l[1],Y=s[2]-l[2],y=r(B*B+J*J+Y*Y),P=100*b.length,x=.25*B/P*y,C=.25*J/P*y,H=.25*Y/P*y;u[0]-=x,u[1]-=C,u[2]-=H,q[0]+=x,q[1]+=C,q[2]+=H},relaxNode:function(H,B){if(H!==B){var r=H.p,F=B.p,u=0,Y=0,n=0,i=r[0]-F[0],T=r[1]-F[1],$=r[2]-F[2],c=i*i+T*T+$*$;0===c?(u=G(),Y=G(),n=G()):216e6>c&&(u=i/c,Y=T/c,n=$/c);var A=H.r*B.r/400,v=H.d,X=B.d;u*=A,Y*=A,n*=A,v[0]+=u,v[1]+=Y,v[2]+=n,X[0]-=u,X[1]-=Y,X[2]-=n}},moveNode:function(){var W=this,y=W._maxMotion,U=0,H=W._damper;W._nodes.each(function(L){if(!L.fix){var T=L.p,j=L.d,K=j[0]*H,G=j[1]*H,B=j[2]*H;j[0]=K/2,j[1]=G/2,j[2]=B/2,U=M(r(K*K+G*G+B*B),U),T[0]+=M(-40,C(40,K)),T[1]+=M(-40,C(40,G)),T[2]+=M(-40,C(40,B))}}),W._maxMotion=U,W._motionRatio=U>0?y/U-1:0,W.damp()}})}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:this,Object);
|