npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nodesoup.cxx

v1.2020.9

Published

Force-directed graph layout with Fruchterman-Reingold; Olivier (2018).

Readme

Graph untangling

Force-directed graph layout simulates forces to give motion to vertices and arrange them in a way that is visually pleasing and/or reveals structure. The Fruchterman-Reingold algorithm assigns a repelling force to vertices pair of the graph, effectively pushing apart vertices so they don't overlap, and a attraction force between each adjacent vertices pair, thus dragging closer connected vertices. The forces attenuate when the vertices get respectively further apart or closer, and a global temperature also serves as a simulated annealing, capping the maximum vertex displacement at each iteration. As the forces between each component and the temperature gradually diminish, the layout stabilizes.

Another method, the Kamada Kawai algorithm, relies on the simulation of springs between each vertex, which strength is determined by the length of the shortest path between both vertices. The potential energy of each vertex, ie the sum of the energy of all its springs, is then computed. The goal being to reduce the global energy of the layout, each vertex is moved step-by-step until its potential energy is considered low-enough, using a Newton-Raphson algorithm.

Implementation

This implementation of Fruchterman-Reingold starts by positioning all vertices on a circle as this appears to favor "unmangling" compared to random positions. The radius of the circle is alway 1.0, and all further computations are performed with floating point values, without knowledge of the canvas dimensions. In consequence, contrary to the original Fruchterman-Reingold algorithm, no bound checking is performed, and the layout can spread constraint-free. The final result is then scaled to fit into the canvas dimensions.

A Kamada-Kawai algorithm is also provided, mostly for comparison purpose. Its complexity makes it rather unsuitable for larger graphs.

Installation

Run:

$ npm i nodesoup.cxx

And then include nodesoup.hpp as follows:

// main.cxx
#define NODESOUP_IMPLEMENTATION
#include "node_modules/nodesoup.cxx/nodesoup.hpp"

int main() { /* ... */ }

And then compile with clang++ or g++ as usual.

$ clang++ main.cxx  # or, use g++
$ g++     main.cxx

You may also use a simpler approach:

// main.cxx
#define NODESOUP_IMPLEMENTATION
#include <nodesoup.hpp>

int main() { /* ... */ }

If you add the path node_modules/nodesoup.cxx to your compiler's include paths.

$ clang++ -I./node_modules/nodesoup.cxx main.cxx  # or, use g++
$ g++     -I./node_modules/nodesoup.cxx main.cxx

Results

Click for full-scale image

K6 graph

| Fruchterman-Reingold | Kamada-Kawai | Graphviz | | :-----------------------: | :-----------------------: | :-----------------------: | | | | | | x.xxs | x.xxs | x.xxs |

DOT file from graphs.grevian.org

Small dense graph

| Fruchterman-Reingold | Kamada-Kawai | Graphviz | | :-----------------------: | :-----------------------: | :-----------------------: | | | | | | x.xxs | x.xxs | x.xxs |

DOT file from graphs.grevian.org

Binary tree

| Fruchterman-Reingold | Kamada-Kawai | Graphviz | | :-----------------------: | :-----------------------: | :-----------------------: | | | | | | x.xxs | x.xxs | x.xxs |

Quad tree

| Fruchterman-Reingold | Kamada-Kawai | Graphviz | | :-----------------------: | :-----------------------: | :-----------------------: | | | | | | x.xxs | x.xxs | x.xxs |

Large graph with disconnected components

| Fruchterman-Reingold | Graphviz | | :-----------------------: | :-----------------------: | | | | | x.xxs | x.xxs |

GML file from gephi based on dataset by M. E. J. Newman

It might take some twiddling with the k parameter (a constant used to compute attractive and repulsive forces between vertices), as well as of the number of iterations, in order to get a layout perfectly free of edge-crossing. A better solution could be to introduce a "fine-tuning" phase during which we slightly raise again the temperature (and possibly the k value?) so as to shake the layout a bit before cooling it down again.

ORG