Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
graphology-layout-forceatlas2
Advanced tools
JavaScript implementation of the ForceAtlas2 algorithm for graphology.
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
npm install graphology-layout-forceatlas2
Each node's starting position must be set before running ForceAtlas 2 layout. Two attributes called x
and y
must therefore be defined for all the graph nodes. graphology-layout can be used to initialize these attributes to a random or circular layout, if needed.
Note also that the algorithm has an edge-case where the layout cannot be computed if all of your nodes starts with x=0
and y=0
.
false
]: should the node's sizes be taken into account?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.0.5
]: Barnes-Hut approximation theta parameter.1
]: influence of the edge's weights on the layout. To consider edge weight, don't forget to pass weighted
as true
when applying the synchronous layout or when instantiating the worker.1
]: strength of the layout's gravity.false
]: whether to use Noack's LinLog model.false
]1
]1
]false
]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
weight
]: name of the edge weight attribute or getter function. Defaults to weight
.If you need to run the layout's computation in a web worker, the library comes with a utility to do so:
Example
import FA2Layout from 'graphology-layout-forceatlas2/worker';
// The parameters are the same as for the synchronous version, minus `iterations` of course
const layout = new FA2Layout(graph, {
settings: {gravity: 1}
});
// To start the layout
layout.start();
// To stop the layout
layout.stop();
// To kill the layout and release attached memory
layout.kill();
// Assess whether the layout is currently running
layout.isRunning();
WARNING!: if you are using webpack
to bundle your code, avoid the cheap-eval
-like options for the devtool
setting. Some users noticed that it interacts in mysterious ways with the library's code and cause performance to drop dramatically when using the worker. Note that this should have been fixed from v0.5.0.
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:
import forceAtlas2 from 'graphology-layout-forceatlas2';
const sensibleSettings = forceAtlas2.inferSettings(graph);
const positions = forceAtlas2(graph, {
iterations: 50,
settings: sensibleSettings
});
// Alternatively using the graph's order instead of a graph instance
const sensibleSettings = forceAtlas2.inferSettings(500);
0.10.1
#.mergeEdge
& undirected edges.FAQs
ForceAtlas 2 layout algorithm for graphology.
The npm package graphology-layout-forceatlas2 receives a total of 31,865 weekly downloads. As such, graphology-layout-forceatlas2 popularity was classified as popular.
We found that graphology-layout-forceatlas2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.