You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
graphology is a robust & multipurpose Graph object for JavaScript and TypeScript.
It aims at supporting various kinds of graphs with the same unified interface.
A graphology graph can therefore be directed, undirected or mixed, allow self-loops or not, and can be simple or support parallel edges.
Along with this Graph object, one will also find a comprehensive standard library full of graph theory algorithms and common utilities such as graph generators, layouts, traversals etc.
Finally, graphology graphs are able to emit a wide variety of events, which makes them ideal to build interactive renderers for the browser. It is for instance used by sigma.js as its data backend.
Installation
To install graphology using npm, run the following command:
npm install graphology
Legacy bundle
Standalone builds of graphology and its full standard library can be found in the repository's releases if you can only rely on your own script tags to load code.
<!-- To use a Graph object --><scriptsrc="graphology.min.js"></script><!-- This exposes a global variable named "graphology" --><script>constgraph=newgraphology.Graph();const{UndirectedGraph, DirectedGraph}=graphology;</script><!-- To use the standard library --><scriptsrc="graphology-library.min.js"></script><!-- This exposes a global variable named "graphologyLibrary" --><script>constdensity=graphologyLibrary.metrics.graph.density(graph);</script>
Be warned that the standard library bundle often lags behind and is not always completely up to date.
TypeScript usage
Note that graphology also exports type declaration that are installed along using peer dependencies so it can be used with TypeScript out of the box.
If your version of npm is a bit old, you may need to install graphology-types yourself if the peer dependency resolution is not made for you already:
npm install graphology-types
It can also be useful to pin graphology-types version in your package.json to avoid resolution issues sometimes.