graphology is a specification and reference implementation for a robust & multipurpose JavaScript Graph object.

It aims at supporting various kinds of graphs with the same unified interface.

A graphology graph can therefore be directed, undirected or mixed and can be simple or support parallel edges.

Along with those specifications, one will also find a standard library full of graph theory algorithms and common utilities such as graph generators, layouts etc.


To install the reference implementation:

npm install --save graphology

The source of the reference implementation can be found on this github repository.

Quick Start

const Graph = require('graphology');

const graph = new Graph();
graph.addEdge('John', 'Martha');

console.log('Number of nodes', graph.order);
console.log('Number of edges', graph.size);

graph.forEachNode(node => {
  graph.forEachNeighbor(node, neighbor => console.log(node, neighbor));

Standard library

Implementing graphology

graphology merely is a specification so that anyone can implement it its own way if necessary while keeping the advantages of being able to use the standard library.

Graphs are complex structures and, while we designed the reference implementation to handle most common cases with good performance, one will always be able to implement the present specifications in a more performant fashion for specific use cases.

It is therefore possible to test your custom implementation against the specifications' unit tests.

Directions about this can be found here.