Digraph module provides several functions for working with directed graphs (digraphs) in JavaScript.
npm i digraph --save
Use browserify.
var digraph = require('digraph');
digraph
is a factory function creates directed graph object.
var g1 = digraph();
Digraph object has node
factory function.
<Node> = g1.node(<N>)
Creates new node object if needed.
N: undefined
Constructs new noname node object.
N: {String}
Search for existing node object with this name. Constructs new node object with the name if can`t find existing node.
N: {Object}
Uses provided Object
as node object descriptor. Search for existing node object if name: 'NodeName'
is provided.
var a = g1.node('a');
var node = g1.node; // can be detached
var b = node('b');
var c = node('c');
Node object has edge
factory that will search for the relevant edge or create one if needed.
var a_b = a.edge(b);
var b_e = node('b').edge(node('e'));
var c_ = c.edge; // can be detached
var c_d = c_(d);
var c_e = c_(e);
[<Edge>] = g1.edges.from(<Node>)
Return array of all outgoing edges.
[<Edge>] = g1.edges.to(<Node>)
Return array of all incoming edges.
[<Edge>] = g1.edges.at(<Node>)
[<Node>] = g.get.nodes
Return array of nodes in no particular order.
[<Edge>] = g.get.edges
Return array of edges in no particular order.