New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphology-layout-forceatlas2

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphology-layout-forceatlas2 - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

build/graphology-layout-forceatlas2.js

@@ -192,3 +192,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

typeof value.addUndirectedEdgeWithKey === 'function' &&
typeof value.dropNodes === 'function' &&
typeof value.dropNode === 'function' &&
typeof value.multi === 'boolean'

@@ -195,0 +195,0 @@ );

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.forceAtlas2=e():t.forceAtlas2=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(n){if(o[n])return o[n].exports;var a=o[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,e),a.l=!0,a.exports}var o={};return e.m=t,e.c=o,e.d=function(t,o,n){e.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,o){function n(t,e,o){if(!r(e))throw new Error("graphology-layout-forceatlas2: the given graph is not a valid graphology instance.");"number"==typeof o&&(o={iterations:o});var n=o.iterations;if("number"!=typeof n)throw new Error("graphology-layout-forceatlas2: invalid number of iterations.");if(n<=0)throw new Error("graphology-layout-forceatlas2: you should provide a positive number of iterations.");var a=s.assign({},u,o.settings),l=s.validateSettings(a);if(l)throw new Error("graphology-layout-forceatlas2: "+l.message);var g,f=s.graphToByteArrays(e);for(g=0;g<n;g++)i(a,f.nodes,f.edges);return t?void s.applyLayoutChanges(e,f.nodes):s.collectLayoutChanges(e,f.nodes)}function a(t){var e=t.order;return{barnesHutOptimize:e>2e3,strongGravityMode:!0,gravity:.05,scalingRatio:10,slowDown:1+Math.log(e)}}var r=o(1),i=o(2),s=o(3),u=o(4),l=n.bind(null,!1);l.assign=n.bind(null,!0),l.inferSettings=a,t.exports=l},function(t,e){t.exports=function(t){return null!==t&&"object"==typeof t&&"function"==typeof t.addUndirectedEdgeWithKey&&"function"==typeof t.dropNodes&&"boolean"==typeof t.multi}},function(t,e){t.exports=function(t,e,o){var n,a,r,i,s,u,l,g,f,h,d,b,c,p,y,M=e.length,w=o.length,m=[];for(r=0;r<M;r+=10)e[r+4]=e[r+2],e[r+5]=e[r+3],e[r+2]=0,e[r+3]=0;if(t.outboundAttractionDistribution){for(f=0,r=0;r<M;r+=10)f+=e[r+6];f/=M}if(t.barnesHutOptimize){var v,A,D,x=1/0,z=-1/0,j=1/0,q=-1/0;for(r=0;r<M;r+=10)x=Math.min(x,e[r+0]),z=Math.max(z,e[r+0]),j=Math.min(j,e[r+1]),q=Math.max(q,e[r+1]);var H=z-x,S=q-j;for(H>S?(j-=(H-S)/2,q=j+H):(x-=(S-H)/2,z=x+S),m[0]=-1,m[1]=(x+z)/2,m[2]=(j+q)/2,m[3]=Math.max(z-x,q-j),m[4]=-1,m[5]=-1,m[6]=0,m[7]=0,m[8]=0,n=1,r=0;r<M;r+=10)for(a=0,D=3;;){if(!(m[a+5]>=0)){if(m[a+0]<0){m[a+0]=r;break}if(m[a+5]=9*n,l=m[a+3]/2,g=m[a+5],m[g+0]=-1,m[g+1]=m[a+1]-l,m[g+2]=m[a+2]-l,m[g+3]=l,m[g+4]=g+9,m[g+5]=-1,m[g+6]=0,m[g+7]=0,m[g+8]=0,g+=9,m[g+0]=-1,m[g+1]=m[a+1]-l,m[g+2]=m[a+2]+l,m[g+3]=l,m[g+4]=g+9,m[g+5]=-1,m[g+6]=0,m[g+7]=0,m[g+8]=0,g+=9,m[g+0]=-1,m[g+1]=m[a+1]+l,m[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]}else{if(m[a+0]>=0&&m[a+0]!==r&&(d=e[r+0]-e[m[a+0]+0],b=e[r+1]-e[m[a+0]+1],p=Math.sqrt(d*d+b*b),t.adjustSizes?p>0?(y=h*e[r+6]*e[m[a+0]+6]/p/p,e[r+2]+=d*y,e[r+3]+=b*y):p<0&&(y=-h*e[r+6]*e[m[a+0]+6]/p,e[r+2]+=d*y,e[r+3]+=b*y):p>0&&(y=h*e[r+6]*e[m[a+0]+6]/p/p,e[r+2]+=d*y,e[r+3]+=b*y)),m[a+4]<0)break;a=m[a+4]}else for(h=t.scalingRatio,i=0;i<M;i+=10)for(s=0;s<i;s+=10)d=e[i+0]-e[s+0],b=e[i+1]-e[s+1],t.adjustSizes?(p=Math.sqrt(d*d+b*b)-e[i+8]-e[s+8],p>0?(y=h*e[i+6]*e[s+6]/p/p,e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]+=d*y,e[s+3]+=b*y):p<0&&(y=100*h*e[i+6]*e[s+6],e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]-=d*y,e[s+3]-=b*y)):(p=Math.sqrt(d*d+b*b))>0&&(y=h*e[i+6]*e[s+6]/p/p,e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]-=d*y,e[s+3]-=b*y);for(g=t.gravity/t.scalingRatio,h=t.scalingRatio,r=0;r<M;r+=10)y=0,d=e[r+0],b=e[r+1],p=Math.sqrt(Math.pow(d,2)+Math.pow(b,2)),t.strongGravityMode?p>0&&(y=h*e[r+6]*g):p>0&&(y=h*e[r+6]*g/p),e[r+2]-=d*y,e[r+3]-=b*y;for(h=1*(t.outboundAttractionDistribution?f:1),u=0;u<w;u+=3)i=o[u+0],s=o[u+1],l=o[u+2],c=Math.pow(l,t.edgeWeightInfluence),d=e[i+0]-e[s+0],b=e[i+1]-e[s+1],t.adjustSizes?(p=Math.sqrt(Math.pow(d,2)+Math.pow(b,2)-e[i+8]-e[s+8]),t.linLogMode?t.outboundAttractionDistribution?p>0&&(y=-h*c*Math.log(1+p)/p/e[i+6]):p>0&&(y=-h*c*Math.log(1+p)/p):t.outboundAttractionDistribution?p>0&&(y=-h*c/e[i+6]):p>0&&(y=-h*c)):(p=Math.sqrt(Math.pow(d,2)+Math.pow(b,2)),t.linLogMode?t.outboundAttractionDistribution?p>0&&(y=-h*c*Math.log(1+p)/p/e[i+6]):p>0&&(y=-h*c*Math.log(1+p)/p):t.outboundAttractionDistribution?(p=1,y=-h*c/e[i+6]):(p=1,y=-h*c)),p>0&&(e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]-=d*y,e[s+3]-=b*y);var O,L,R,T;if(t.adjustSizes)for(r=0;r<M;r+=10)e[r+9]||(O=Math.sqrt(Math.pow(e[r+2],2)+Math.pow(e[r+3],2)),O>10&&(e[r+2]=10*e[r+2]/O,e[r+3]=10*e[r+3]/O),L=e[r+6]*Math.sqrt((e[r+4]-e[r+2])*(e[r+4]-e[r+2])+(e[r+5]-e[r+3])*(e[r+5]-e[r+3])),R=Math.sqrt((e[r+4]+e[r+2])*(e[r+4]+e[r+2])+(e[r+5]+e[r+3])*(e[r+5]+e[r+3]))/2,T=.1*Math.log(1+R)/(1+Math.sqrt(L)),e[r+0]=e[r+0]+e[r+2]*(T/t.slowDown),e[r+1]=e[r+1]+e[r+3]*(T/t.slowDown));else for(r=0;r<M;r+=10)e[r+9]||(L=e[r+6]*Math.sqrt((e[r+4]-e[r+2])*(e[r+4]-e[r+2])+(e[r+5]-e[r+3])*(e[r+5]-e[r+3])),R=Math.sqrt((e[r+4]+e[r+2])*(e[r+4]+e[r+2])+(e[r+5]+e[r+3])*(e[r+5]+e[r+3]))/2,T=e[r+7]*Math.log(1+R)/(1+Math.sqrt(L)),e[r+7]=Math.min(1,Math.sqrt(T*(Math.pow(e[r+2],2)+Math.pow(e[r+3],2))/(1+Math.sqrt(L)))),e[r+0]=e[r+0]+e[r+2]*(T/t.slowDown),e[r+1]=e[r+1]+e[r+3]*(T/t.slowDown));return{}}},function(t,e){e.assign=function(t){t=t||{};var e,o,n,a=Array.prototype.slice.call(arguments).slice(1);for(e=0,n=a.length;e<n;e++)if(a[e])for(o in a[e])t[o]=a[e][o];return t},e.validateSettings=function(t){return"linLogMode"in t&&"boolean"!=typeof t.linLogMode?{message:"the `linLogMode` setting should be a boolean."}:"outboundAttractionDistribution"in t&&"boolean"!=typeof t.outboundAttractionDistribution?{message:"the `outboundAttractionDistribution` setting should be a boolean."}:"adjustSizes"in t&&"boolean"!=typeof t.adjustSizes?{message:"the `adjustSizes` setting should be a boolean."}:"edgeWeightInfluence"in t&&"number"!=typeof t.edgeWeightInfluence&&t.edgeWeightInfluence<0?{message:"the `edgeWeightInfluence` setting should be a number >= 0."}:"scalingRatio"in t&&"number"!=typeof t.scalingRatio&&t.scalingRatio<0?{message:"the `scalingRatio` setting should be a number >= 0."}:"strongGravityMode"in t&&"boolean"!=typeof t.strongGravityMode?{message:"the `strongGravityMode` setting should be a boolean."}:"gravity"in t&&"number"!=typeof t.gravity&&t.gravity<0?{message:"the `gravity` setting should be a number >= 0."}:"slowDown"in t&&"number"!=typeof t.slowDown&&t.slowDown<0?{message:"the `slowDown` setting should be a number >= 0."}:"barnesHutOptimize"in t&&"boolean"!=typeof t.barnesHutOptimize?{message:"the `barnesHutOptimize` setting should be a boolean."}:"barnesHutTheta"in t&&"number"!=typeof t.barnesHutTheta&&t.barnesHutTheta<0?{message:"the `barnesHutTheta` setting should be a number >= 0."}:null},e.graphToByteArrays=function(t){var e,o,n=t.nodes(),a=t.edges(),r=n.length,i=a.length,s={},u=new Float32Array(10*r),l=new Float32Array(3*i);for(e=o=0;e<r;e++)s[n[e]]=o,u[o]=t.getNodeAttribute(n[e],"x"),u[o+1]=t.getNodeAttribute(n[e],"y"),u[o+2]=0,u[o+3]=0,u[o+4]=0,u[o+5]=0,u[o+6]=1+t.degree(n[e]),u[o+7]=1,u[o+8]=t.getNodeAttribute(n[e],"size")||1,u[o+9]=0,o+=10;for(e=o=0;e<i;e++)l[o]=s[t.source(a[e])],l[o+1]=s[t.target(a[e])],l[o+2]=t.getEdgeAttribute(a[e],"weight")||0,o+=3;return{nodes:u,edges:l}},e.applyLayoutChanges=function(t,e){for(var o=t.nodes(),n=0,a=0,r=e.length;n<r;n+=10)t.setNodeAttribute(o[a],"x",e[n]),t.setNodeAttribute(o[a],"y",e[n+1]),a++},e.collectLayoutChanges=function(t,e){for(var o=t.nodes(),n=Object.create(null),a=0,r=0,i=e.length;a<i;a+=10)n[o[r]]={x:e[a],y:e[a+1]},r++;return n}},function(t,e){t.exports={linLogMode:!1,outboundAttractionDistribution:!1,adjustSizes:!1,edgeWeightInfluence:0,scalingRatio:1,strongGravityMode:!1,gravity:1,slowDown:1,barnesHutOptimize:!1,barnesHutTheta:.5}}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.forceAtlas2=e():t.forceAtlas2=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(n){if(o[n])return o[n].exports;var a=o[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,e),a.l=!0,a.exports}var o={};return e.m=t,e.c=o,e.d=function(t,o,n){e.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,o){function n(t,e,o){if(!r(e))throw new Error("graphology-layout-forceatlas2: the given graph is not a valid graphology instance.");"number"==typeof o&&(o={iterations:o});var n=o.iterations;if("number"!=typeof n)throw new Error("graphology-layout-forceatlas2: invalid number of iterations.");if(n<=0)throw new Error("graphology-layout-forceatlas2: you should provide a positive number of iterations.");var a=s.assign({},u,o.settings),l=s.validateSettings(a);if(l)throw new Error("graphology-layout-forceatlas2: "+l.message);var g,f=s.graphToByteArrays(e);for(g=0;g<n;g++)i(a,f.nodes,f.edges);return t?void s.applyLayoutChanges(e,f.nodes):s.collectLayoutChanges(e,f.nodes)}function a(t){var e=t.order;return{barnesHutOptimize:e>2e3,strongGravityMode:!0,gravity:.05,scalingRatio:10,slowDown:1+Math.log(e)}}var r=o(1),i=o(2),s=o(3),u=o(4),l=n.bind(null,!1);l.assign=n.bind(null,!0),l.inferSettings=a,t.exports=l},function(t,e){t.exports=function(t){return null!==t&&"object"==typeof t&&"function"==typeof t.addUndirectedEdgeWithKey&&"function"==typeof t.dropNode&&"boolean"==typeof t.multi}},function(t,e){t.exports=function(t,e,o){var n,a,r,i,s,u,l,g,f,h,d,b,c,p,y,M=e.length,w=o.length,m=[];for(r=0;r<M;r+=10)e[r+4]=e[r+2],e[r+5]=e[r+3],e[r+2]=0,e[r+3]=0;if(t.outboundAttractionDistribution){for(f=0,r=0;r<M;r+=10)f+=e[r+6];f/=M}if(t.barnesHutOptimize){var v,A,D,x=1/0,z=-1/0,j=1/0,q=-1/0;for(r=0;r<M;r+=10)x=Math.min(x,e[r+0]),z=Math.max(z,e[r+0]),j=Math.min(j,e[r+1]),q=Math.max(q,e[r+1]);var H=z-x,S=q-j;for(H>S?(j-=(H-S)/2,q=j+H):(x-=(S-H)/2,z=x+S),m[0]=-1,m[1]=(x+z)/2,m[2]=(j+q)/2,m[3]=Math.max(z-x,q-j),m[4]=-1,m[5]=-1,m[6]=0,m[7]=0,m[8]=0,n=1,r=0;r<M;r+=10)for(a=0,D=3;;){if(!(m[a+5]>=0)){if(m[a+0]<0){m[a+0]=r;break}if(m[a+5]=9*n,l=m[a+3]/2,g=m[a+5],m[g+0]=-1,m[g+1]=m[a+1]-l,m[g+2]=m[a+2]-l,m[g+3]=l,m[g+4]=g+9,m[g+5]=-1,m[g+6]=0,m[g+7]=0,m[g+8]=0,g+=9,m[g+0]=-1,m[g+1]=m[a+1]-l,m[g+2]=m[a+2]+l,m[g+3]=l,m[g+4]=g+9,m[g+5]=-1,m[g+6]=0,m[g+7]=0,m[g+8]=0,g+=9,m[g+0]=-1,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a=m[a+4];continue}a=m[a+5]}else{if(m[a+0]>=0&&m[a+0]!==r&&(d=e[r+0]-e[m[a+0]+0],b=e[r+1]-e[m[a+0]+1],p=Math.sqrt(d*d+b*b),t.adjustSizes?p>0?(y=h*e[r+6]*e[m[a+0]+6]/p/p,e[r+2]+=d*y,e[r+3]+=b*y):p<0&&(y=-h*e[r+6]*e[m[a+0]+6]/p,e[r+2]+=d*y,e[r+3]+=b*y):p>0&&(y=h*e[r+6]*e[m[a+0]+6]/p/p,e[r+2]+=d*y,e[r+3]+=b*y)),m[a+4]<0)break;a=m[a+4]}else for(h=t.scalingRatio,i=0;i<M;i+=10)for(s=0;s<i;s+=10)d=e[i+0]-e[s+0],b=e[i+1]-e[s+1],t.adjustSizes?(p=Math.sqrt(d*d+b*b)-e[i+8]-e[s+8],p>0?(y=h*e[i+6]*e[s+6]/p/p,e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]+=d*y,e[s+3]+=b*y):p<0&&(y=100*h*e[i+6]*e[s+6],e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]-=d*y,e[s+3]-=b*y)):(p=Math.sqrt(d*d+b*b))>0&&(y=h*e[i+6]*e[s+6]/p/p,e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]-=d*y,e[s+3]-=b*y);for(g=t.gravity/t.scalingRatio,h=t.scalingRatio,r=0;r<M;r+=10)y=0,d=e[r+0],b=e[r+1],p=Math.sqrt(Math.pow(d,2)+Math.pow(b,2)),t.strongGravityMode?p>0&&(y=h*e[r+6]*g):p>0&&(y=h*e[r+6]*g/p),e[r+2]-=d*y,e[r+3]-=b*y;for(h=1*(t.outboundAttractionDistribution?f:1),u=0;u<w;u+=3)i=o[u+0],s=o[u+1],l=o[u+2],c=Math.pow(l,t.edgeWeightInfluence),d=e[i+0]-e[s+0],b=e[i+1]-e[s+1],t.adjustSizes?(p=Math.sqrt(Math.pow(d,2)+Math.pow(b,2)-e[i+8]-e[s+8]),t.linLogMode?t.outboundAttractionDistribution?p>0&&(y=-h*c*Math.log(1+p)/p/e[i+6]):p>0&&(y=-h*c*Math.log(1+p)/p):t.outboundAttractionDistribution?p>0&&(y=-h*c/e[i+6]):p>0&&(y=-h*c)):(p=Math.sqrt(Math.pow(d,2)+Math.pow(b,2)),t.linLogMode?t.outboundAttractionDistribution?p>0&&(y=-h*c*Math.log(1+p)/p/e[i+6]):p>0&&(y=-h*c*Math.log(1+p)/p):t.outboundAttractionDistribution?(p=1,y=-h*c/e[i+6]):(p=1,y=-h*c)),p>0&&(e[i+2]+=d*y,e[i+3]+=b*y,e[s+2]-=d*y,e[s+3]-=b*y);var O,L,R,T;if(t.adjustSizes)for(r=0;r<M;r+=10)e[r+9]||(O=Math.sqrt(Math.pow(e[r+2],2)+Math.pow(e[r+3],2)),O>10&&(e[r+2]=10*e[r+2]/O,e[r+3]=10*e[r+3]/O),L=e[r+6]*Math.sqrt((e[r+4]-e[r+2])*(e[r+4]-e[r+2])+(e[r+5]-e[r+3])*(e[r+5]-e[r+3])),R=Math.sqrt((e[r+4]+e[r+2])*(e[r+4]+e[r+2])+(e[r+5]+e[r+3])*(e[r+5]+e[r+3]))/2,T=.1*Math.log(1+R)/(1+Math.sqrt(L)),e[r+0]=e[r+0]+e[r+2]*(T/t.slowDown),e[r+1]=e[r+1]+e[r+3]*(T/t.slowDown));else for(r=0;r<M;r+=10)e[r+9]||(L=e[r+6]*Math.sqrt((e[r+4]-e[r+2])*(e[r+4]-e[r+2])+(e[r+5]-e[r+3])*(e[r+5]-e[r+3])),R=Math.sqrt((e[r+4]+e[r+2])*(e[r+4]+e[r+2])+(e[r+5]+e[r+3])*(e[r+5]+e[r+3]))/2,T=e[r+7]*Math.log(1+R)/(1+Math.sqrt(L)),e[r+7]=Math.min(1,Math.sqrt(T*(Math.pow(e[r+2],2)+Math.pow(e[r+3],2))/(1+Math.sqrt(L)))),e[r+0]=e[r+0]+e[r+2]*(T/t.slowDown),e[r+1]=e[r+1]+e[r+3]*(T/t.slowDown));return{}}},function(t,e){e.assign=function(t){t=t||{};var e,o,n,a=Array.prototype.slice.call(arguments).slice(1);for(e=0,n=a.length;e<n;e++)if(a[e])for(o in a[e])t[o]=a[e][o];return t},e.validateSettings=function(t){return"linLogMode"in t&&"boolean"!=typeof t.linLogMode?{message:"the `linLogMode` setting should be a boolean."}:"outboundAttractionDistribution"in t&&"boolean"!=typeof t.outboundAttractionDistribution?{message:"the `outboundAttractionDistribution` setting should be a boolean."}:"adjustSizes"in t&&"boolean"!=typeof t.adjustSizes?{message:"the `adjustSizes` setting should be a boolean."}:"edgeWeightInfluence"in t&&"number"!=typeof t.edgeWeightInfluence&&t.edgeWeightInfluence<0?{message:"the `edgeWeightInfluence` setting should be a number >= 0."}:"scalingRatio"in t&&"number"!=typeof t.scalingRatio&&t.scalingRatio<0?{message:"the `scalingRatio` setting should be a number >= 0."}:"strongGravityMode"in t&&"boolean"!=typeof t.strongGravityMode?{message:"the `strongGravityMode` setting should be a boolean."}:"gravity"in t&&"number"!=typeof t.gravity&&t.gravity<0?{message:"the `gravity` setting should be a number >= 0."}:"slowDown"in t&&"number"!=typeof t.slowDown&&t.slowDown<0?{message:"the `slowDown` setting should be a number >= 0."}:"barnesHutOptimize"in t&&"boolean"!=typeof t.barnesHutOptimize?{message:"the `barnesHutOptimize` setting should be a boolean."}:"barnesHutTheta"in t&&"number"!=typeof t.barnesHutTheta&&t.barnesHutTheta<0?{message:"the `barnesHutTheta` setting should be a number >= 0."}:null},e.graphToByteArrays=function(t){var e,o,n=t.nodes(),a=t.edges(),r=n.length,i=a.length,s={},u=new Float32Array(10*r),l=new Float32Array(3*i);for(e=o=0;e<r;e++)s[n[e]]=o,u[o]=t.getNodeAttribute(n[e],"x"),u[o+1]=t.getNodeAttribute(n[e],"y"),u[o+2]=0,u[o+3]=0,u[o+4]=0,u[o+5]=0,u[o+6]=1+t.degree(n[e]),u[o+7]=1,u[o+8]=t.getNodeAttribute(n[e],"size")||1,u[o+9]=0,o+=10;for(e=o=0;e<i;e++)l[o]=s[t.source(a[e])],l[o+1]=s[t.target(a[e])],l[o+2]=t.getEdgeAttribute(a[e],"weight")||0,o+=3;return{nodes:u,edges:l}},e.applyLayoutChanges=function(t,e){for(var o=t.nodes(),n=0,a=0,r=e.length;n<r;n+=10)t.setNodeAttribute(o[a],"x",e[n]),t.setNodeAttribute(o[a],"y",e[n+1]),a++},e.collectLayoutChanges=function(t,e){for(var o=t.nodes(),n=Object.create(null),a=0,r=0,i=e.length;a<i;a+=10)n[o[r]]={x:e[a],y:e[a+1]},r++;return n}},function(t,e){t.exports={linLogMode:!1,outboundAttractionDistribution:!1,adjustSizes:!1,edgeWeightInfluence:0,scalingRatio:1,strongGravityMode:!1,gravity:1,slowDown:1,barnesHutOptimize:!1,barnesHutTheta:.5}}])});
{
"name": "graphology-layout-forceatlas2",
"version": "0.2.0",
"version": "0.2.1",
"description": "ForceAtlas 2 layout algorithm for graphology.",

@@ -45,5 +45,5 @@ "main": "index.js",

"eslint": "^4.7.2",
"graphology": "0.11.4",
"graphology-generators": "^0.9.0",
"mocha": "^3.0.2",
"graphology": "0.13.1",
"graphology-generators": "^0.10.1",
"mocha": "^5.2.0",
"seedrandom": "^2.4.3",

@@ -60,4 +60,4 @@ "webpack": "^3.6.0",

"dependencies": {
"graphology-utils": "^1.1.1"
"graphology-utils": "^1.3.1"
}
}

@@ -5,2 +5,90 @@ [![Build Status](https://travis-ci.org/graphology/graphology-layout-forceatlas2.svg)](https://travis-ci.org/graphology/graphology-layout-forceatlas2)

WIP
JavaScript implementation of the [ForceAtlas2](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0098679) algorithm for [graphology](https://graphology.github.io).
## Reference
> Jacomy M, Venturini T, Heymann S, Bastian M (2014) ForceAtlas2, a Continuous Graph Layout Algorithm for Handy Network Visualization Designed for the Gephi Software. PLoS ONE 9(6): e98679. https://doi.org/10.1371/journal.pone.0098679
## Installation
```
npm install graphology-layout-forceatlas2
```
## Usage
* [Settings](#settings)
* [Synchronous layout](#synchronous-layout)
* [Webworker](#webworker)
* [#.inferSettings](#infersettings)
### Settings
* **adjustSizes** *?boolean* [`false`]: should the node's sizes be taken into account?
* **barnesHutOptimize** *?boolean* [`false`]: whether to use the Barnes-Hut approximation to compute repulsion in `O(n*log(n))` rather than default `O(n^2)`, `n` being the number of nodes.
* **barnesHutTheta** *?number* [`0.5`]: Barnes-Hut approximation theta parameter.
* **edgeWeightInfluence** *?number* [`0`]: influence of the edge's weights on the layout.
* **gravity** *?number* [`1`]: strength of the layout's gravity.
* **linLogMode** *?boolean* [`false`]: whether to use Noack's LinLog model.
* **outboundAttractionDistribution** *?boolean* [`false`]
* **scalingRatio** *?number* [`1`]
* **slowDown** *?number* [`1`]
* **strongGravityMode** *?boolean* [`false`]
### Synchronous layout
```js
import forceAtlas2 from 'graphology-layout-forceatlas2';
const positions = forceAtlas2(graph, {iterations: 50});
// With settings:
const positions = forceAtlas2(graph, {
iterations: 50,
settings: {
gravity: 10
}
});
// To directly assign the positions to the nodes:
forceAtlas2.assign(graph);
```
*Arguments*
* **graph** *Graph*: target graph.
* **options** *object*: options:
- **iterations** *number*: number of iterations to perform.
- **settings** *?object*: the layout's settings (see [#settings](#settings)).
### Webworker
If you need to run the layout's computation in a web worker, the library comes with a utility to do so:
*Example*
```js
import FA2Layout from 'graphology-layout-forceatlas2/worker';
const layout = new FA2Layout(graph);
// To start the layout
layout.start({settings: {gravity: 1}});
// To stop the layout
layout.stop();
// To kill the layout and release attached memory
layout.kill();
```
### #.inferSettings
If you don't know how to tune the layout's settings and want to infer them from your graph, you can use the `#.inferSettings` method:
```js
import forceAtlas2 from 'graphology-layout-forceatlas2';
const saneSettings = forceAtlas2.inferSettings(graph);
const positions = forceAtlas2(graph, {iterations: 50, settings: saneSettings});
```

@@ -307,3 +307,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

typeof value.addUndirectedEdgeWithKey === 'function' &&
typeof value.dropNodes === 'function' &&
typeof value.dropNode === 'function' &&
typeof value.multi === 'boolean'

@@ -310,0 +310,0 @@ );

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc