UNPKG

react-sigma

Version:

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

1 lines 16.1 kB
var Sigma=function(e){var t={};function s(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,r){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(r,n,function(t){return e[t]}.bind(null,n));return r},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=186)}({186:function(e,t,s){s(187),e.exports=s(188)},187:function(module,exports,__webpack_require__){(function(){(function(undefined){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";var _root=this,webWorkers="Worker"in _root;function Supervisor(sigInst,options){var _this=this,workerFn=sigInst.getForceAtlas2Worker&&sigInst.getForceAtlas2Worker();if(options=options||{},_root.URL=_root.URL||_root.webkitURL,this.sigInst=sigInst,this.graph=this.sigInst.graph,this.ppn=10,this.ppe=3,this.config={},this.shouldUseWorker=!1!==options.worker&&webWorkers,this.workerUrl=options.workerUrl,this.started=!1,this.running=!1,this.shouldUseWorker){if(this.workerUrl)this.worker=new Worker(this.workerUrl);else{var blob=this.makeBlob(workerFn);this.worker=new Worker(URL.createObjectURL(blob))}this.worker.postMessage=this.worker.webkitPostMessage||this.worker.postMessage}else eval(workerFn);this.msgName=this.worker?"message":"newCoords",this.listener=function(e){_this.nodesByteArray=new Float32Array(e.data.nodes),_this.running&&(_this.applyLayoutChanges(),_this.sendByteArrayToWorker(),_this.sigInst.refresh())},(this.worker||document).addEventListener(this.msgName,this.listener),this.graphToByteArrays(),sigInst.bind("kill",(function(){sigInst.killForceAtlas2()}))}Supervisor.prototype.makeBlob=function(e){var t;try{t=new Blob([e],{type:"application/javascript"})}catch(s){_root.BlobBuilder=_root.BlobBuilder||_root.WebKitBlobBuilder||_root.MozBlobBuilder,(t=new BlobBuilder).append(e),t=t.getBlob()}return t},Supervisor.prototype.graphToByteArrays=function(){var e,t,s,r=this.graph.nodes(),n=this.graph.edges(),i=r.length*this.ppn,o=n.length*this.ppe,a={};for(this.nodesByteArray=new Float32Array(i),this.edgesByteArray=new Float32Array(o),e=t=0,s=r.length;e<s;e++)a[r[e].id]=t,this.nodesByteArray[t]=r[e].x,this.nodesByteArray[t+1]=r[e].y,this.nodesByteArray[t+2]=0,this.nodesByteArray[t+3]=0,this.nodesByteArray[t+4]=0,this.nodesByteArray[t+5]=0,this.nodesByteArray[t+6]=1+this.graph.degree(r[e].id),this.nodesByteArray[t+7]=1,this.nodesByteArray[t+8]=r[e].size,this.nodesByteArray[t+9]=0,t+=this.ppn;for(e=t=0,s=n.length;e<s;e++)this.edgesByteArray[t]=a[n[e].source],this.edgesByteArray[t+1]=a[n[e].target],this.edgesByteArray[t+2]=n[e].weight||0,t+=this.ppe},Supervisor.prototype.applyLayoutChanges=function(){for(var e=this.graph.nodes(),t=0,s=0,r=this.nodesByteArray.length;s<r;s+=this.ppn)e[t].x=this.nodesByteArray[s],e[t].y=this.nodesByteArray[s+1],t++},Supervisor.prototype.sendByteArrayToWorker=function(e){var t={action:e||"loop",nodes:this.nodesByteArray.buffer},s=[this.nodesByteArray.buffer];"start"===e&&(t.config=this.config||{},t.edges=this.edgesByteArray.buffer,s.push(this.edgesByteArray.buffer)),this.shouldUseWorker?this.worker.postMessage(t,s):_root.postMessage(t,"*")},Supervisor.prototype.start=function(){if(!this.running){var e;for(e in this.running=!0,this.sigInst.cameras)this.sigInst.cameras[e].edgequadtree._enabled=!1;this.started?this.sendByteArrayToWorker():(this.sendByteArrayToWorker("start"),this.started=!0)}},Supervisor.prototype.stop=function(){if(this.running){var e,t,s;for(e in this.sigInst.cameras)(t=this.sigInst.cameras[e]).edgequadtree._enabled=!0,s=sigma.utils.getBoundaries(this.graph,t.readPrefix),t.settings("drawEdges")&&t.settings("enableEdgeHovering")&&t.edgequadtree.index(this.sigInst.graph,{prefix:t.readPrefix,bounds:{x:s.minX,y:s.minY,width:s.maxX-s.minX,height:s.maxY-s.minY}});this.running=!1}},Supervisor.prototype.killWorker=function(){this.worker?this.worker.terminate():(_root.postMessage({action:"kill"},"*"),document.removeEventListener(this.msgName,this.listener))},Supervisor.prototype.configure=function(e){if(this.config=e,this.started){var t={action:"config",config:this.config};this.shouldUseWorker?this.worker.postMessage(t):_root.postMessage(t,"*")}},sigma.prototype.startForceAtlas2=function(e){return this.supervisor||(this.supervisor=new Supervisor(this,e)),e&&this.supervisor.configure(e),this.supervisor.start(),this},sigma.prototype.stopForceAtlas2=function(){return this.supervisor?(this.supervisor.stop(),this):this},sigma.prototype.killForceAtlas2=function(){return this.supervisor?(this.supervisor.stop(),this.supervisor.killWorker(),this.supervisor=null,this):this},sigma.prototype.configForceAtlas2=function(e){return this.supervisor||(this.supervisor=new Supervisor(this,e)),this.supervisor.configure(e),this},sigma.prototype.isForceAtlas2Running=function(e){return!!this.supervisor&&this.supervisor.running}}).call(window)}).call(window)},188:function(module,exports){(function(){(function(undefined){"use strict";var _root=this,inWebWorker=!("document"in _root),Worker=function(e){var t,s,r,n={ppn:10,ppe:3,ppr:9,maxForce:10,iterations:0,converged:!1,settings:{linLogMode:!1,outboundAttractionDistribution:!1,adjustSizes:!1,edgeWeightInfluence:0,scalingRatio:1,strongGravityMode:!1,gravity:1,slowDown:1,barnesHutOptimize:!1,barnesHutTheta:.5,startingIterations:1,iterationsPerRender:1}};var i,o={x:0,y:1,dx:2,dy:3,old_dx:4,old_dy:5,mass:6,convergence:7,size:8,fixed:9},a={source:0,target:1,weight:2},d={node:0,centerX:1,centerY:2,size:3,nextSibling:4,firstChild:5,mass:6,massCenterX:7,massCenterY:8};function h(e,t){if(e%n.ppn!=0)throw"np: non correct ("+e+").";if(e!==parseInt(e))throw"np: non int.";if(t in o)return e+o[t];throw"ForceAtlas2.Worker - Inexistant node property given ("+t+")."}function p(e,t){if(e%n.ppe!=0)throw"ep: non correct ("+e+").";if(e!==parseInt(e))throw"ep: non int.";if(t in a)return e+a[t];throw"ForceAtlas2.Worker - Inexistant edge property given ("+t+")."}function g(e,t){if(e%n.ppr!=0)throw"rp: non correct ("+e+").";if(e!==parseInt(e))throw"rp: non int.";if(t in d)return e+d[t];throw"ForceAtlas2.Worker - Inexistant region property given ("+t+")."}function l(e){n.settings=function(){var e,t,s={};for(e=arguments.length-1;e>=0;e--)for(t in arguments[e])s[t]=arguments[e][t];return s}(e,n.settings)}function u(){var e,i,o,a,d,l,u,c,f,y,m,x,w,v,b,k,M,A,_;for(o=0;o<n.nodesLength;o+=n.ppn)t[h(o,"old_dx")]=t[h(o,"dx")],t[h(o,"old_dy")]=t[h(o,"dy")],t[h(o,"dx")]=0,t[h(o,"dy")]=0;if(n.settings.outboundAttractionDistribution){for(f=0,o=0;o<n.nodesLength;o+=n.ppn)f+=t[h(o,"mass")];f/=n.nodesLength}if(n.settings.barnesHutOptimize){var C,B,S=1/0,W=-1/0,Y=1/0,F=-1/0;for(r=[],o=0;o<n.nodesLength;o+=n.ppn)S=Math.min(S,t[h(o,"x")]),W=Math.max(W,t[h(o,"x")]),Y=Math.min(Y,t[h(o,"y")]),F=Math.max(F,t[h(o,"y")]);for(r[g(0,"node")]=-1,r[g(0,"centerX")]=(S+W)/2,r[g(0,"centerY")]=(Y+F)/2,r[g(0,"size")]=Math.max(W-S,F-Y),r[g(0,"nextSibling")]=-1,r[g(0,"firstChild")]=-1,r[g(0,"mass")]=0,r[g(0,"massCenterX")]=0,r[g(0,"massCenterY")]=0,e=1,o=0;o<n.nodesLength;o+=n.ppn)for(i=0;;)if(r[g(i,"firstChild")]>=0)C=t[h(o,"x")]<r[g(i,"centerX")]?t[h(o,"y")]<r[g(i,"centerY")]?r[g(i,"firstChild")]:r[g(i,"firstChild")]+n.ppr:t[h(o,"y")]<r[g(i,"centerY")]?r[g(i,"firstChild")]+2*n.ppr:r[g(i,"firstChild")]+3*n.ppr,r[g(i,"massCenterX")]=(r[g(i,"massCenterX")]*r[g(i,"mass")]+t[h(o,"x")]*t[h(o,"mass")])/(r[g(i,"mass")]+t[h(o,"mass")]),r[g(i,"massCenterY")]=(r[g(i,"massCenterY")]*r[g(i,"mass")]+t[h(o,"y")]*t[h(o,"mass")])/(r[g(i,"mass")]+t[h(o,"mass")]),r[g(i,"mass")]+=t[h(o,"mass")],i=C;else{if(r[g(i,"node")]<0){r[g(i,"node")]=o;break}if(r[g(i,"firstChild")]=e*n.ppr,u=r[g(i,"size")]/2,c=r[g(i,"firstChild")],r[g(c,"node")]=-1,r[g(c,"centerX")]=r[g(i,"centerX")]-u,r[g(c,"centerY")]=r[g(i,"centerY")]-u,r[g(c,"size")]=u,r[g(c,"nextSibling")]=c+n.ppr,r[g(c,"firstChild")]=-1,r[g(c,"mass")]=0,r[g(c,"massCenterX")]=0,r[g(c,"massCenterY")]=0,c+=n.ppr,r[g(c,"node")]=-1,r[g(c,"centerX")]=r[g(i,"centerX")]-u,r[g(c,"centerY")]=r[g(i,"centerY")]+u,r[g(c,"size")]=u,r[g(c,"nextSibling")]=c+n.ppr,r[g(c,"firstChild")]=-1,r[g(c,"mass")]=0,r[g(c,"massCenterX")]=0,r[g(c,"massCenterY")]=0,c+=n.ppr,r[g(c,"node")]=-1,r[g(c,"centerX")]=r[g(i,"centerX")]+u,r[g(c,"centerY")]=r[g(i,"centerY")]-u,r[g(c,"size")]=u,r[g(c,"nextSibling")]=c+n.ppr,r[g(c,"firstChild")]=-1,r[g(c,"mass")]=0,r[g(c,"massCenterX")]=0,r[g(c,"massCenterY")]=0,c+=n.ppr,r[g(c,"node")]=-1,r[g(c,"centerX")]=r[g(i,"centerX")]+u,r[g(c,"centerY")]=r[g(i,"centerY")]+u,r[g(c,"size")]=u,r[g(c,"nextSibling")]=r[g(i,"nextSibling")],r[g(c,"firstChild")]=-1,r[g(c,"mass")]=0,r[g(c,"massCenterX")]=0,r[g(c,"massCenterY")]=0,e+=4,C=t[h(r[g(i,"node")],"x")]<r[g(i,"centerX")]?t[h(r[g(i,"node")],"y")]<r[g(i,"centerY")]?r[g(i,"firstChild")]:r[g(i,"firstChild")]+n.ppr:t[h(r[g(i,"node")],"y")]<r[g(i,"centerY")]?r[g(i,"firstChild")]+2*n.ppr:r[g(i,"firstChild")]+3*n.ppr,r[g(i,"mass")]=t[h(r[g(i,"node")],"mass")],r[g(i,"massCenterX")]=t[h(r[g(i,"node")],"x")],r[g(i,"massCenterY")]=t[h(r[g(i,"node")],"y")],r[g(C,"node")]=r[g(i,"node")],r[g(i,"node")]=-1,C!==(B=t[h(o,"x")]<r[g(i,"centerX")]?t[h(o,"y")]<r[g(i,"centerY")]?r[g(i,"firstChild")]:r[g(i,"firstChild")]+n.ppr:t[h(o,"y")]<r[g(i,"centerY")]?r[g(i,"firstChild")]+2*n.ppr:r[g(i,"firstChild")]+3*n.ppr)){r[g(B,"node")]=o;break}i=C}}if(n.settings.barnesHutOptimize)for(y=n.settings.scalingRatio,o=0;o<n.nodesLength;o+=n.ppn)for(i=0;;)if(r[g(i,"firstChild")]>=0){if(v=Math.sqrt(Math.pow(t[h(o,"x")]-r[g(i,"massCenterX")],2)+Math.pow(t[h(o,"y")]-r[g(i,"massCenterY")],2)),2*r[g(i,"size")]/v<n.settings.barnesHutTheta){if(m=t[h(o,"x")]-r[g(i,"massCenterX")],x=t[h(o,"y")]-r[g(i,"massCenterY")],n.settings.adjustSizes?v>0?(b=y*t[h(o,"mass")]*r[g(i,"mass")]/v/v,t[h(o,"dx")]+=m*b,t[h(o,"dy")]+=x*b):v<0&&(b=-y*t[h(o,"mass")]*r[g(i,"mass")]/v,t[h(o,"dx")]+=m*b,t[h(o,"dy")]+=x*b):v>0&&(b=y*t[h(o,"mass")]*r[g(i,"mass")]/v/v,t[h(o,"dx")]+=m*b,t[h(o,"dy")]+=x*b),r[g(i,"nextSibling")]<0)break;i=r[g(i,"nextSibling")];continue}i=r[g(i,"firstChild")]}else{if(r[g(i,"node")]>=0&&r[g(i,"node")]!==o&&(m=t[h(o,"x")]-t[h(r[g(i,"node")],"x")],x=t[h(o,"y")]-t[h(r[g(i,"node")],"y")],v=Math.sqrt(m*m+x*x),n.settings.adjustSizes?v>0?(b=y*t[h(o,"mass")]*t[h(r[g(i,"node")],"mass")]/v/v,t[h(o,"dx")]+=m*b,t[h(o,"dy")]+=x*b):v<0&&(b=-y*t[h(o,"mass")]*t[h(r[g(i,"node")],"mass")]/v,t[h(o,"dx")]+=m*b,t[h(o,"dy")]+=x*b):v>0&&(b=y*t[h(o,"mass")]*t[h(r[g(i,"node")],"mass")]/v/v,t[h(o,"dx")]+=m*b,t[h(o,"dy")]+=x*b)),r[g(i,"nextSibling")]<0)break;i=r[g(i,"nextSibling")]}else for(y=n.settings.scalingRatio,a=0;a<n.nodesLength;a+=n.ppn)for(d=0;d<a;d+=n.ppn)m=t[h(a,"x")]-t[h(d,"x")],x=t[h(a,"y")]-t[h(d,"y")],n.settings.adjustSizes?(v=Math.sqrt(m*m+x*x)-t[h(a,"size")]-t[h(d,"size")])>0?(b=y*t[h(a,"mass")]*t[h(d,"mass")]/v/v,t[h(a,"dx")]+=m*b,t[h(a,"dy")]+=x*b,t[h(d,"dx")]+=m*b,t[h(d,"dy")]+=x*b):v<0&&(b=100*y*t[h(a,"mass")]*t[h(d,"mass")],t[h(a,"dx")]+=m*b,t[h(a,"dy")]+=x*b,t[h(d,"dx")]-=m*b,t[h(d,"dy")]-=x*b):(v=Math.sqrt(m*m+x*x))>0&&(b=y*t[h(a,"mass")]*t[h(d,"mass")]/v/v,t[h(a,"dx")]+=m*b,t[h(a,"dy")]+=x*b,t[h(d,"dx")]-=m*b,t[h(d,"dy")]-=x*b);for(c=n.settings.gravity/n.settings.scalingRatio,y=n.settings.scalingRatio,o=0;o<n.nodesLength;o+=n.ppn)b=0,m=t[h(o,"x")],x=t[h(o,"y")],v=Math.sqrt(Math.pow(m,2)+Math.pow(x,2)),n.settings.strongGravityMode?v>0&&(b=y*t[h(o,"mass")]*c):v>0&&(b=y*t[h(o,"mass")]*c/v),t[h(o,"dx")]-=m*b,t[h(o,"dy")]-=x*b;for(y=1*(n.settings.outboundAttractionDistribution?f:1),l=0;l<n.edgesLength;l+=n.ppe)a=s[p(l,"source")],d=s[p(l,"target")],u=s[p(l,"weight")],w=Math.pow(u,n.settings.edgeWeightInfluence),m=t[h(a,"x")]-t[h(d,"x")],x=t[h(a,"y")]-t[h(d,"y")],n.settings.adjustSizes?(v=Math.sqrt(Math.pow(m,2)+Math.pow(x,2)-t[h(a,"size")]-t[h(d,"size")]),n.settings.linLogMode?n.settings.outboundAttractionDistribution?v>0&&(b=-y*w*Math.log(1+v)/v/t[h(a,"mass")]):v>0&&(b=-y*w*Math.log(1+v)/v):n.settings.outboundAttractionDistribution?v>0&&(b=-y*w/t[h(a,"mass")]):v>0&&(b=-y*w)):(v=Math.sqrt(Math.pow(m,2)+Math.pow(x,2)),n.settings.linLogMode?n.settings.outboundAttractionDistribution?v>0&&(b=-y*w*Math.log(1+v)/v/t[h(a,"mass")]):v>0&&(b=-y*w*Math.log(1+v)/v):n.settings.outboundAttractionDistribution?(v=1,b=-y*w/t[h(a,"mass")]):(v=1,b=-y*w)),v>0&&(t[h(a,"dx")]+=m*b,t[h(a,"dy")]+=x*b,t[h(d,"dx")]-=m*b,t[h(d,"dy")]-=x*b);if(n.settings.adjustSizes)for(o=0;o<n.nodesLength;o+=n.ppn)t[h(o,"fixed")]||((k=Math.sqrt(Math.pow(t[h(o,"dx")],2)+Math.pow(t[h(o,"dy")],2)))>n.maxForce&&(t[h(o,"dx")]=t[h(o,"dx")]*n.maxForce/k,t[h(o,"dy")]=t[h(o,"dy")]*n.maxForce/k),M=t[h(o,"mass")]*Math.sqrt((t[h(o,"old_dx")]-t[h(o,"dx")])*(t[h(o,"old_dx")]-t[h(o,"dx")])+(t[h(o,"old_dy")]-t[h(o,"dy")])*(t[h(o,"old_dy")]-t[h(o,"dy")])),A=Math.sqrt((t[h(o,"old_dx")]+t[h(o,"dx")])*(t[h(o,"old_dx")]+t[h(o,"dx")])+(t[h(o,"old_dy")]+t[h(o,"dy")])*(t[h(o,"old_dy")]+t[h(o,"dy")]))/2,_=.1*Math.log(1+A)/(1+Math.sqrt(M)),t[h(o,"x")]=t[h(o,"x")]+t[h(o,"dx")]*(_/n.settings.slowDown),t[h(o,"y")]=t[h(o,"y")]+t[h(o,"dy")]*(_/n.settings.slowDown));else for(o=0;o<n.nodesLength;o+=n.ppn)t[h(o,"fixed")]||(M=t[h(o,"mass")]*Math.sqrt((t[h(o,"old_dx")]-t[h(o,"dx")])*(t[h(o,"old_dx")]-t[h(o,"dx")])+(t[h(o,"old_dy")]-t[h(o,"dy")])*(t[h(o,"old_dy")]-t[h(o,"dy")])),A=Math.sqrt((t[h(o,"old_dx")]+t[h(o,"dx")])*(t[h(o,"old_dx")]+t[h(o,"dx")])+(t[h(o,"old_dy")]+t[h(o,"dy")])*(t[h(o,"old_dy")]+t[h(o,"dy")]))/2,_=t[h(o,"convergence")]*Math.log(1+A)/(1+Math.sqrt(M)),t[h(o,"convergence")]=Math.min(1,Math.sqrt(_*(Math.pow(t[h(o,"dx")],2)+Math.pow(t[h(o,"dy")],2))/(1+Math.sqrt(M)))),t[h(o,"x")]=t[h(o,"x")]+t[h(o,"dx")]*(_/n.settings.slowDown),t[h(o,"y")]=t[h(o,"y")]+t[h(o,"dy")]*(_/n.settings.slowDown));n.iterations++}function c(e){for(var t=0;t<e;t++)u();i()}i="undefined"!=typeof window&&window.document?function(){var e;document.createEvent?(e=document.createEvent("Event")).initEvent("newCoords",!0,!1):(e=document.createEventObject()).eventType="newCoords",e.eventName="newCoords",e.data={nodes:t.buffer},requestAnimationFrame((function(){document.dispatchEvent(e)}))}:function(){self.postMessage({nodes:t.buffer},[t.buffer])};var f=function(e){switch(e.data.action){case"start":i=new Float32Array(e.data.nodes),o=new Float32Array(e.data.edges),a=(a=e.data.config)||{},t=i,s=o,n.nodesLength=t.length,n.edgesLength=s.length,l(a),c(n.settings.startingIterations);break;case"loop":t=new Float32Array(e.data.nodes),c(n.settings.iterationsPerRender);break;case"config":l(e.data.config);break;case"kill":!function(e){var t;for(t in e)"hasOwnProperty"in e&&!e.hasOwnProperty(t)||delete e[t]}(n),t=null,s=null,r=null,self.removeEventListener("message",f)}var i,o,a};self.addEventListener("message",f)};function crush(e){var t,s,r,n=["x","y","dx","dy","old_dx","old_dy","mass","convergence","size","fixed"],i=["source","target","weight"],o=["node","centerX","centerY","size","nextSibling","firstChild","mass","massCenterX","massCenterY"];for(s=0,r=o.length;s<r;s++)t=new RegExp("rp\\(([^,]*), '"+o[s]+"'\\)","g"),e=e.replace(t,0===s?"$1":"$1 + "+s);for(s=0,r=n.length;s<r;s++)t=new RegExp("np\\(([^,]*), '"+n[s]+"'\\)","g"),e=e.replace(t,0===s?"$1":"$1 + "+s);for(s=0,r=i.length;s<r;s++)t=new RegExp("ep\\(([^,]*), '"+i[s]+"'\\)","g"),e=e.replace(t,0===s?"$1":"$1 + "+s);return e}function getWorkerFn(){return";("+(crush?crush(Worker.toString()):Worker.toString())+").call(this);"}if(inWebWorker)eval(getWorkerFn());else{if("undefined"==typeof sigma)throw"sigma is not declared";sigma.prototype.getForceAtlas2Worker=getWorkerFn}}).call(window)}).call(window)}});