-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.layout.ForceDirected.min.js
More file actions
14 lines (8 loc) · 3.04 KB
/
joint.layout.ForceDirected.min.js
File metadata and controls
14 lines (8 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! Rappid v3.1.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2020-06-11
This Source Code Form is subject to the terms of the Rappid Trial License
, v. 2.0. If a copy of the Rappid License was not distributed with this
file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
this.joint=this.joint||{},function(t,i,a){"use strict";var e=(i=i&&i.hasOwnProperty("default")?i.default:i).Model.extend({defaults:{linkDistance:10,linkStrength:1,charge:10,x:0,y:0},cacheAttribute:"_fcache",initialize:function(){var t,i,e=this.get("graph");if(Array.isArray(e)){var s=e;t=[],i=[];for(var h=0,r=s.length;h<r;h++){var n=s[h];n.isLink()?t.push(n):i.push(n)}}else i=e.getElements(),t=e.getLinks();this.links=t,this.elements=i,this.x=this.get("x"),this.y=this.get("y"),this.width=this.get("width"),this.height=this.get("height"),this.gravityCenter=this.get("gravityCenter"),this.t=1,this.energy=1/0,this.progress=0},start:function(){var h=this.width,r=this.height,n=this.x,g=this.y;this.elements.forEach(function(t){var i=a.g.random(n,n+h),e=a.g.random(g,g+r);t.position(i,e,{forceDirected:!0});var s=t[this.cacheAttribute]={};s.charge=t.get("charge")||this.get("charge"),s.weight=t.get("weight")||1,s.x=s.px=i,s.y=s.py=e,s.fx=0,s.fy=0},this),this.links.forEach(function(t){var i=t[this.cacheAttribute]={};i.source=t.getSourceElement(),i.target=t.getTargetElement(),i.strength=t.get("strength")||this.get("linkStrength"),i.distance=t.get("distance")||this.get("linkDistance")},this)},step:function(){if(.99*this.t<.005)return this.notifyEnd();var t,i,e,s,h,r,n,g,a,y,o,c=this.cacheAttribute,f=this.width,x=this.height,l=this.x,u=this.y,d=this.gravityCenter,p=this.energy,m=this.energy=0,v=0,k=0,w=0,E=this.elements.length,M=this.links.length;for(t=0;t<E-1;t++)for(m+=(e=this.elements[t][c]).x,v+=e.y,i=t+1;i<E;i++)n=(h=(s=this.elements[i][c]).x-e.x)*h+(r=s.y-e.y)*r,g=Math.sqrt(n),y=(a=this.t*e.charge/n)*h,o=a*r,e.fx-=y,e.fy-=o,s.fx+=y,s.fy+=o,this.energy+=y*y+o*o;var A,b,j,D,q,C,S=this.elements[E-1][c];for(m+=S.x,v+=S.y,t=0;t<M;t++)e=(A=this.links[t][c]).source[c],n=(h=(s=A.target[c]).x-e.x)*h+(r=s.y-e.y)*r,g=Math.sqrt(n),y=(b=this.t*A.strength*(g-A.distance)/g)*h,o=b*r,j=e.weight/(e.weight+s.weight),e.x+=y*(1-j),e.y+=o*(1-j),s.x-=y*j,s.y-=o*j,this.energy+=y*y+o*o;for(t=0;t<E;t++){C={x:(q=(D=this.elements[t])[c]).x,y:q.y},d&&(C.x+=(d.x-C.x)*this.t*.1,C.y+=(d.y-C.y)*this.t*.1),C.x+=q.fx,C.y+=q.fy,C.x=Math.max(l,Math.min(l+f,C.x)),C.y=Math.max(u,Math.min(l+x,C.y));C.x+=.9*(q.px-C.x),C.y+=.9*(q.py-C.y),q.px=C.x,q.py=C.y,q.fx=q.fy=0,q.x=C.x,q.y=C.y,k+=q.x,w+=q.y,this.notify(D,t,C)}this.t=this.cool(this.t,this.energy,p);var L=m-k,z=v-w;Math.sqrt(L*L+z*z)<1&&this.notifyEnd()},cool:function(t,i,e){return i<e?(this.progress+=1,5<=this.progress?(this.progress=0,t/.99):t):(this.progress=0,.99*t)},notify:function(t,i,e){t.set("position",e,{forceDirected:!0})},notifyEnd:function(){this.trigger("end")}});t.ForceDirected=e}(this.joint.layout=this.joint.layout||{},Backbone,joint);