UNPKG

sigma

Version:

A JavaScript library dedicated to graph drawing.

2 lines 10.4 kB
(()=>{var e,t={9076:(e,t,r)=>{var n=r(8782);e.exports=function(e,t){if(!n(e))throw new Error("graphology-generators/classic/empty: invalid Graph constructor.");var r,o=new e;for(r=0;r<t;r++)o.addNode(r);return o}},4495:e=>{e.exports={gridSize:20,margin:5,expansion:1.1,ratio:1,speed:3}},9654:(e,t)=>{t.validateSettings=function(e){return"gridSize"in e&&"number"!=typeof e.gridSize||e.gridSize<=0?{message:"the `gridSize` setting should be a positive number."}:"margin"in e&&"number"!=typeof e.margin||e.margin<0?{message:"the `margin` setting should be 0 or a positive number."}:"expansion"in e&&"number"!=typeof e.expansion||e.expansion<=0?{message:"the `expansion` setting should be a positive number."}:"ratio"in e&&"number"!=typeof e.ratio||e.ratio<=0?{message:"the `ratio` setting should be a positive number."}:"speed"in e&&"number"!=typeof e.speed||e.speed<=0?{message:"the `speed` setting should be a positive number."}:null},t.graphToByteArray=function(e,t){var r=e.order,n=new Float32Array(3*r),o=0;return e.forEachNode((function(e,r){"function"==typeof t&&(r=t(e,r)),n[o]=r.x,n[o+1]=r.y,n[o+2]=r.size||1,o+=3})),n},t.assignLayoutChanges=function(e,t,r){var n=0;e.forEachNode((function(o){var i={x:t[n],y:t[n+1]};"function"==typeof r&&(i=r(o,i)),e.mergeNodeAttributes(o,i),n+=3}))},t.collectLayoutChanges=function(e,t,r){var n={},o=0;return e.forEachNode((function(e){var i={x:t[o],y:t[o+1]};"function"==typeof r&&(i=r(e,i)),n[e]=i,o+=3})),n},t.createWorker=function(e){var t=window.URL||window.webkitURL,r=e.toString(),n=t.createObjectURL(new Blob(["("+r+").call(this);"],{type:"text/javascript"})),o=new Worker(n);return t.revokeObjectURL(n),o}},2977:(e,t,r)=>{var n=r(3105),o=r(1338),i=r(9654),a=r(4495);function s(e,t,r){if(!n(t))throw new Error("graphology-layout-noverlap: the given graph is not a valid graphology instance.");var s=(r="number"==typeof r?{maxIterations:r}:r||{}).maxIterations||500;if("number"!=typeof s)throw new Error("graphology-layout-noverlap: invalid number of maximum iterations.");if(s<=0)throw new Error("graphology-layout-noverlap: you should provide a positive number of maximum iterations.");var u=Object.assign({},a,r.settings),l=i.validateSettings(u);if(l)throw new Error("graphology-layout-noverlap: "+l.message);var d,h=i.graphToByteArray(t,r.inputReducer),p=!1;for(d=0;d<s&&!p;d++)p=o(u,h).converged;if(!e)return i.collectLayoutChanges(t,h,r.outputReducer);i.assignLayoutChanges(t,h,r.outputReducer)}var u=s.bind(null,!1);u.assign=s.bind(null,!0),e.exports=u},1338:e=>{function t(){return.01*(.5-Math.random())}e.exports=function(e,r){var n,o,i,a,s,u,l=e.margin,d=e.ratio,h=e.expansion,p=e.gridSize,f=e.speed,g=!0,c=r.length,v=c/3|0,y=new Float32Array(v),m=new Float32Array(v),b=1/0,w=1/0,k=-1/0,x=-1/0;for(n=0;n<c;n+=3)i=r[n+0],a=r[n+1],u=r[n+2]*d+l,b=Math.min(b,i-u),k=Math.max(k,i+u),w=Math.min(w,a-u),x=Math.max(x,a+u);var M=k-b,A=x-w,O=(b+k)/2,E=(w+x)/2;b=O-h*M/2,k=O+h*M/2,w=E-h*A/2,x=E+h*A/2;var S,j,R,C,L,F,z,_,N,T,I,W,P=new Array(p*p),U=P.length;for(S=0;S<U;S++)P[S]=[];for(n=0;n<c;n+=3)for(i=r[n+0],a=r[n+1],j=i-(u=r[n+2]*d+l),R=i+u,C=a-u,L=a+u,F=Math.floor(p*(j-b)/(k-b)),z=Math.floor(p*(R-b)/(k-b)),_=Math.floor(p*(C-w)/(x-w)),N=Math.floor(p*(L-w)/(x-w)),T=F;T<=z;T++)for(I=_;I<=N;I++)P[T*p+I].push(n);var B,G,q,D,K,V,H,J,Q,X,Y,Z,$=new Set;for(S=0;S<U;S++)for(n=0,s=(W=P[S]).length;n<s;n++)for(q=r[(B=W[n])+0],K=r[B+1],H=r[B+2],o=n+1;o<s;o++)Q=B+"§"+(G=W[o]),U>1&&$.has(Q)||(U>1&&$.add(Q),D=r[G+0],V=r[G+1],J=r[G+2],X=D-q,Y=V-K,(Z=Math.sqrt(X*X+Y*Y))<H*d+l+(J*d+l)&&(g=!1,G=G/3|0,Z>0?(y[G]+=X/Z*(1+H),m[G]+=Y/Z*(1+H)):(y[G]+=M*t(),m[G]+=A*t())));for(n=0,o=0;n<c;n+=3,o++)r[n+0]+=.1*y[o]*f,r[n+1]+=.1*m[o]*f;return{converged:g}}},3105:e=>{e.exports=function(e){return null!==e&&"object"==typeof e&&"function"==typeof e.addUndirectedEdgeWithKey&&"function"==typeof e.dropNode&&"boolean"==typeof e.multi}},8807:e=>{e.exports=function(){var e,t={};!function(){function e(){return.01*(.5-Math.random())}t.exports=function(t,r){var n,o,i,a,s,u,l=t.margin,d=t.ratio,h=t.expansion,p=t.gridSize,f=t.speed,g=!0,c=r.length,v=c/3|0,y=new Float32Array(v),m=new Float32Array(v),b=1/0,w=1/0,k=-1/0,x=-1/0;for(n=0;n<c;n+=3)i=r[n+0],a=r[n+1],u=r[n+2]*d+l,b=Math.min(b,i-u),k=Math.max(k,i+u),w=Math.min(w,a-u),x=Math.max(x,a+u);var M=k-b,A=x-w,O=(b+k)/2,E=(w+x)/2;b=O-h*M/2,k=O+h*M/2,w=E-h*A/2,x=E+h*A/2;var S,j,R,C,L,F,z,_,N,T,I,W,P=new Array(p*p),U=P.length;for(S=0;S<U;S++)P[S]=[];for(n=0;n<c;n+=3)for(i=r[n+0],a=r[n+1],j=i-(u=r[n+2]*d+l),R=i+u,C=a-u,L=a+u,F=Math.floor(p*(j-b)/(k-b)),z=Math.floor(p*(R-b)/(k-b)),_=Math.floor(p*(C-w)/(x-w)),N=Math.floor(p*(L-w)/(x-w)),T=F;T<=z;T++)for(I=_;I<=N;I++)P[T*p+I].push(n);var B,G,q,D,K,V,H,J,Q,X,Y,Z,$=new Set;for(S=0;S<U;S++)for(n=0,s=(W=P[S]).length;n<s;n++)for(q=r[(B=W[n])+0],K=r[B+1],H=r[B+2],o=n+1;o<s;o++)Q=B+"§"+(G=W[o]),U>1&&$.has(Q)||(U>1&&$.add(Q),D=r[G+0],V=r[G+1],J=r[G+2],X=D-q,Y=V-K,(Z=Math.sqrt(X*X+Y*Y))<H*d+l+(J*d+l)&&(g=!1,G=G/3|0,Z>0?(y[G]+=X/Z*(1+H),m[G]+=Y/Z*(1+H)):(y[G]+=M*e(),m[G]+=A*e())));for(n=0,o=0;n<c;n+=3,o++)r[n+0]+=.1*y[o]*f,r[n+1]+=.1*m[o]*f;return{converged:g}}}();var r=t.exports;self.addEventListener("message",(function(t){var n=t.data;e=new Float32Array(n.nodes);var o=r(n.settings,e);self.postMessage({result:o,nodes:e.buffer},[e.buffer])}))}},4142:(e,t,r)=>{var n=r(8807),o=r(3105),i=r(9654),a=r(4495);function s(e,t){if(t=t||{},!o(e))throw new Error("graphology-layout-noverlap/worker: the given graph is not a valid graphology instance.");var r=Object.assign({},a,t.settings),n=i.validateSettings(r);if(n)throw new Error("graphology-layout-noverlap/worker: "+n.message);this.worker=null,this.graph=e,this.settings=r,this.matrices=null,this.converged=!1,this.running=!1,this.killed=!1,this.inputReducer=t.inputReducer,this.outputReducer=t.outputReducer,this.callbacks={onConverged:"function"==typeof t.onConverged?t.onConverged:null},this.handleMessage=this.handleMessage.bind(this);var s=!1,u=this;this.handleAddition=function(){s||(s=!0,u.spawnWorker(),setImmediate((function(){s=!1})))},e.on("nodeAdded",this.handleAddition),e.on("edgeAdded",this.handleAddition),this.spawnWorker()}s.prototype.spawnWorker=function(){this.worker&&this.worker.terminate(),this.worker=i.createWorker(n),this.worker.addEventListener("message",this.handleMessage),this.running&&(this.running=!1,this.start())},s.prototype.handleMessage=function(e){if(this.running){var t=new Float32Array(e.data.nodes);if(i.assignLayoutChanges(this.graph,t,this.outputReducer),this.matrices.nodes=t,this.converged=e.data.result.converged,e.data.result.converged)return this.callbacks.onConverged&&this.callbacks.onConverged(),void this.stop();this.askForIterations()}},s.prototype.askForIterations=function(){var e=this.matrices,t={settings:this.settings,nodes:e.nodes.buffer},r=[e.nodes.buffer];return this.worker.postMessage(t,r),this},s.prototype.start=function(){if(this.killed)throw new Error("graphology-layout-noverlap/worker.start: layout was killed.");return this.running||(this.matrices={nodes:i.graphToByteArray(this.graph,this.inputReducer)},this.running=!0,this.askForIterations()),this},s.prototype.stop=function(){return this.running=!1,this},s.prototype.kill=function(){if(this.killed)return this;this.running=!1,this.killed=!0,this.matrices=null,this.worker.terminate(),this.graph.removeListener("nodeAdded",this.handleAddition),this.graph.removeListener("edgeAdded",this.handleAddition)},e.exports=s},5639:function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var i=r(9807),a=o(r(5656)),s=o(r(9076)),u=o(r(2977)),l=o(r(4142)),d=o(r(6558)),h=o(r(315)),p=o(r(4780)),f=r(8458),g=r(7610),c={margin:2,ratio:1,speed:3},v=document.getElementById("container"),y=s.default(i.UndirectedGraph,1e3);a.default.assign(y),y.forEachNode((function(e){y.mergeNodeAttributes(e,{label:e,size:h.default(2,10),color:d.default.random().hex()})}));var m=new p.default(y,v);function b(e,t){var r=document.createElement("button");r.textContent=e,r.style.position="absolute",r.style.left="10px";var n=10;return n+=40*t,r.style.top=n+"px",v.appendChild(r),r}var w=function(e,t){return n(n({},t),m.graphToViewport(t))},k=function(e,t){return n(n({},t),m.viewportToGraph(t))};b("noverlap 500",0).onclick=function(){console.time("noverlap");var e=u.default(y,{inputReducer:w,outputReducer:k,maxIterations:500,settings:c});console.timeEnd("noverlap"),f.animateNodes(y,e,{duration:100,easing:"linear"},(function(){return console.log("done")}))};var x=new l.default(y,{inputReducer:w,outputReducer:k,settings:c}),M=b("start",1),A=b("stop",2);M.onclick=function(){x.start()},A.onclick=function(){x.stop()},g.globalize({graph:y,renderer:m})}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={id:e,loaded:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,e=[],n.O=(t,r,o,i)=>{if(!r){var a=1/0;for(l=0;l<e.length;l++){for(var[r,o,i]=e[l],s=!0,u=0;u<r.length;u++)(!1&i||a>=i)&&Object.keys(n.O).every((e=>n.O[e](r[u])))?r.splice(u--,1):(s=!1,i<a&&(a=i));s&&(e.splice(l--,1),t=o())}return t}i=i||0;for(var l=e.length;l>0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[r,o,i]},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),(()=>{var e={527:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var o,i,[a,s,u]=r,l=0;for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(u)var d=u(n);for(t&&t(r);l<a.length;l++)i=a[l],n.o(e,i)&&e[i]&&e[i][0](),e[a[l]]=0;return n.O(d)},r=self.webpackChunk=self.webpackChunk||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var o=n.O(void 0,[351],(()=>n(5639)));o=n.O(o)})(); //# sourceMappingURL=noverlap.bundle.js.map