UNPKG

react-sigma

Version:

Lightweight but powerful library for drawing network graphs built on top of SigmaJS

1 lines 9.33 kB
var Sigma=function(e){var n={};function r(o){if(n[o])return n[o].exports;var t=n[o]={i:o,l:!1,exports:{}};return e[o].call(t.exports,t,t.exports,r),t.l=!0,t.exports}return r.m=e,r.c=n,r.d=function(e,n,o){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var t in e)r.d(o,t,function(n){return e[n]}.bind(null,t));return o},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=371)}({371:function(e,n){(function(){(function(e){"use strict";if("undefined"==typeof sigma)throw new Error("sigma is not declared");function n(e){return e==e&&"[object Number]"===Object.prototype.toString.call(e)}function r(e){return"object"==typeof e&&!!e}sigma.utils.pkg("sigma.plugins"),sigma.plugins.generators={},sigma.plugins.generators.random=function(e){if(!e)throw new Error("Missing argument: options");if(!r(e))throw new TypeError("Invalid argument: options is not an object, was "+e);if(!n(e.nbNodes)||e.nbNodes<1)throw new TypeError("Invalid argument: options.nbNodes is not a positive number, was "+e.nbNodes);if(!n(e.nbEdges)||e.nbEdges<1)throw new TypeError("Invalid argument: options.nbEdges is not a number, was "+e.nbEdges);var o,t=e.nbNodes,a=e.nbEdges,s={nodes:[],edges:[]};for(o=0;o<t;o++)s.nodes.push({id:"n"+o,label:"Node "+o,x:Math.random(),y:Math.random(),size:1});for(o=0;o<a;o++)s.edges.push({id:"e"+o,label:"Edge "+o,source:"n"+(Math.random()*t|0),target:"n"+(Math.random()*t|0)});return s},sigma.plugins.generators.balancedTree=function(e){if(!e)throw new Error("Missing argument: options");if(!r(e))throw new TypeError("Invalid argument: options is not an object, was "+e);if(!n(e.nbChildren)||e.nbChildren<1)throw new TypeError("Invalid argument: options.nbChildren is not a positive number, was "+e.nbChildren);if(!n(e.height)||e.height<1)throw new TypeError("Invalid argument: options.height is not a positive number, was "+e.height);var o,t,a,s,i,d=0,u=0,l=e.nbChildren,g=e.height,p={nodes:[{id:"n0",label:"Node 0",x:Math.random(),y:Math.random(),size:1,index:0}],edges:[]},h=[];for(o=0;o<l;o++)s={id:"n"+ ++d,label:"Node "+d,x:Math.random(),y:Math.random(),size:1,index:d-1},p.nodes.push(s),h.push(s),p.edges.push({id:"e"+u++,label:"Edge "+u,source:"n0",target:"n"+d});for(a=1;a<g;a++)for(i=h,h=[],t=0;t<i.length;t++)for(o=0;o<l;o++)s={id:"n"+ ++d,label:"Node "+d,x:Math.random(),y:Math.random(),size:1,index:d-1},h.push(s),p.nodes.push(s),p.edges.push({id:"e"+u++,label:"Edge "+u,source:"n"+i[t].index,target:"n"+d});return p},sigma.plugins.generators.erdosRenyi=function(e){if(!e)throw new Error("Missing argument: options");if(!r(e))throw new TypeError("Invalid argument: options is not an object, was "+e);if(!n(e.nbNodes)||e.nbNodes<1)throw new TypeError("Invalid argument: options.nbNodes is not a positive number, was "+e.nbNodes);if(e.nbNodes<3)throw new TypeError("Invalid argument: options.nbNodes is smaller than 3, was "+e.nbNodes);if("nbEdges"in e&&"p"in e)throw new TypeError("Invalid argument: choose between options.nbEdges and options.p");var o,t,a,s={nodes:[],edges:[]},i=0,d=e.nbNodes,u=e.p;if(e.p>=0){if(!n(e.p)||e.p<0)throw new TypeError("Invalid argument: options.p is not a positive number, was "+e.p);for(t=0;t<d;t++)for(s.nodes.push({id:"n"+t,label:"Node "+t,x:Math.random(),y:Math.random(),size:1}),a=0;a<t;a++)Math.random()<u&&s.edges.push({id:"e"+i++,label:"Edge "+i,source:"n"+t,target:"n"+a})}else{if(!n(e.nbEdges)||e.nbEdges<1)throw new TypeError("Invalid argument: options.nbEdges is not a positive number, was "+e.nbEdges);var l=[],g=e.nbEdges;for(t=0;t<d;t++)for(s.nodes.push({id:"n"+t,label:"Node "+t,x:Math.random(),y:Math.random(),size:1}),a=t+1;a<d;a++)l.push({source:"n"+t,target:"n"+a});for(i=l.length-1,t=0;t<g;t++)(o=l.splice(Math.floor(Math.random()*i),1)[0]).id="e"+t,o.label="Edge "+t,s.edges.push(o),i--}return s},sigma.plugins.generators.barabasiAlbert=function(e){if(!e)throw new Error("Missing argument: options");if(!r(e))throw new TypeError("Invalid argument: options is not an object, was "+e);if(!n(e.nbNodes)||e.nbNodes<1)throw new TypeError("Invalid argument: options.nbNodes is not a positive number, was "+e.nbNodes);if(e.nbNodes<3)throw new TypeError("Invalid argument: options.nbNodes is smaller than 3, was "+e.nbNodes);if(!n(e.m0)||e.m0<=0)throw new TypeError("Invalid argument: options.m0 is not a positive number, was "+e.m0);if(!n(e.m)||e.m<=0)throw new TypeError("Invalid argument: options.m is not a positive number, was "+e.m);if(e.m0>=e.nbNode)throw new TypeError("Invalid argument: options.m0 is greater than options.nbNodes, was "+e.m0);if(e.m>e.m0)throw new TypeError("Invalid argument: options.m is strictly greater than options.m0, was "+e.m);var o,t,a,s,i,d,u,l,g={nodes:[],edges:[]},p={},h=[],m=0,b=e.nbNodes,f=e.m0,w=e.m;for(o=0;o<f;o++)g.nodes.push({id:"n"+o,label:"node "+o,x:Math.random(),y:Math.random(),size:1}),h[o]=0;for(o=0;o<f;o++)for(t=o+1;t<f;t++)p[(a={id:"e"+m++,label:"Edge "+m,source:"n"+o,target:"n"+t}).source+"-"+a.target]=a,g.edges.push(a),h[o]++,h[t]++;for(o=f;o<b;o++){for(g.nodes.push({id:"n"+o,label:"node "+o,x:Math.random(),y:Math.random(),size:1}),h[o]=0,s=0,t=0;t<o;t++)s+=h[t];for(i=0,d=0;d<w;d++)for(u=Math.random(),l=0,t=0;t<o;t++)if(!p[o+"-"+t]&&!p[t+"-"+o]&&(1==o?l=1:l+=h[t]/s+i/(o-d),u<=l)){i+=h[t]/s,p[(a={id:"e"+m++,label:"Edge "+m,source:"n"+o,target:"n"+t}).source+"-"+a.target]=a,g.edges.push(a),h[o]++,h[t]++;break}}return g},sigma.plugins.generators.wattsStrogatz=function(e){if(!e)throw new Error("Missing argument: options");if(!r(e))throw new TypeError("Invalid argument: options is not an object, was "+e);if(!n(e.nbNodes)||e.nbNodes<1)throw new TypeError("Invalid argument: options.nbNodes is not a positive number, was "+e.nbNodes);if(e.nbNodes<3)throw new TypeError("Invalid argument: options.nbNodes is smaller than 3, was "+e.nbNodes);if(!n(e.k)||e.k%2!=0)throw new TypeError("Invalid argument: options.k is not an even integer, was "+e.k);var o,t,a,s={nodes:[],edges:[]},i=0,d={},u=e.nbNodes,l=e.k;function g(n,r){if(n==r||d[n+"-"+r])return 0;var o=function(e,n){var r,o=0;for(r=0;r<u;r++)r!=e&&r!=n&&d[e+"-"+r]&&d[n+"-"+r]&&o++;return o}(n,r);return o>=l?1:0===o?f:Math.pow(o/l,e.alpha)*(1-f)+f}if("alpha"in e){if(!n(e.alpha)||e.alpha<0||e.alpha>1)throw new TypeError("Invalid argument: options.alpha is not a number between [0,1], was "+e.alpha);var p,h,m,b,f=Math.pow(10,-10),w=0,c=[],v=u*l/2;for(o=0;o<u;o++)s.nodes.push({id:"n"+o,label:"Node "+o,x:Math.random(),y:Math.random(),size:1}),a={id:"e"+i++,label:"Edge "+i,source:"n"+o,target:"n"+(o+1)%u},d[a.source+"-"+a.target]=a,s.edges.push(a),w++;for(;w<v;){for(o=0;o<u;o++)c.push(o);for(;w<v&&c.length>0;){for(o=c.splice(Math.floor(Math.random()*c.length),1)[0],p=[],h=0,t=0;t<u;t++)p[t]=g(o,t),h+=p[t];for(m=Math.random(),b=0,t=0;t<u;t++)o!=t&&m<=(b+=p[t]/h)&&(a={id:"e"+i++,label:"Edge "+i,source:"n"+o,target:"n"+t},s.edges.push(a),w++,d[a.source+"-"+a.target]=a)}}}else{if(!n(e.beta)||e.beta<0||e.beta>1)throw new TypeError("Invalid argument: options.beta is not a number between [0,1], was "+e.beta);var y;for(l>>=1,o=0;o<u;o++)for(s.nodes.push({id:"n"+o,label:"node "+o,x:Math.random(),y:Math.random(),size:1}),t=1;t<=l;t++)a={id:"e"+i++,label:"Edge "+i,source:"n"+o,target:"n"+(o+t)%u},d[a.source+"-"+a.target]=a,s.edges.push(a);for(o=0;o<u;o++)for(t=1;t<=l;t++)if(Math.random()<=e.beta){do{y=Math.floor(Math.random()*(u-1))}while(y==o||d["n"+o+"-n"+y]);var E=(o+t)%u;d["n"+o+"-n"+E].target="n"+y,d["n"+o+"-n"+y]=d["n"+o+"-n"+E],delete d["n"+o+"-n"+E]}}return s},sigma.plugins.generators.path=function(e){if(!e||e<0)throw new TypeError('Invalid argument: "length" is not a positive number, was '+e);for(var n={nodes:[{id:"n0",label:"Node 0",x:Math.random(),y:Math.random(),size:1}],edges:[]},r=1;r<e;++r)n.nodes.push({id:"n"+r,label:"Node "+r,x:Math.random(),y:Math.random(),size:1}),n.edges.push({id:"e"+r,label:"Edge "+r,source:"n"+(r-1),target:"n"+r});return n},sigma.plugins.generators.grid=function(e,n){if(e<1)throw new TypeError('Invalid argument: "n" is not a positive integer, was '+e);if(n<1)throw new TypeError('Invalid argument: "m" is not a positive integer, was '+n);var r,o,t,a,s={nodes:[],edges:[]},i=0,d=[];if(d.length=e*n,1===e&&1===n)return s.nodes.push({id:"n0",label:"Node 0",x:Math.random(),y:Math.random(),size:1}),s;for(r=0;r<e;++r)for(o=0;o<n;++o)d[t=r+o*e]||(s.nodes.push({id:"n"+t,label:"Node "+t,x:Math.random(),y:Math.random(),size:1}),d[t]=!0),r>0&&(d[a=r-1+o*e]||(s.nodes.push({id:"n"+a,label:"Node "+a,x:Math.random(),y:Math.random(),size:1}),d[a]=!0),s.edges.push({id:"e"+i++,label:"Edge "+i,source:"n"+t,target:"n"+a})),o>0&&(d[a=r+(o-1)*e]||(s.nodes.push({id:"n"+a,label:"Node "+a,x:Math.random(),y:Math.random(),size:1}),d[a]=!0),s.edges.push({id:"e"+i++,label:"Edge "+i,source:"n"+t,target:"n"+a}));return s}}).call(this)}).call(window)}});