digraph
v1.6.1
Published
Directed graph library
Downloads
47
Readme
digraph
Digraph module provides several functions for working with directed graphs (digraphs) in JavaScript.
node.js
npm i digraph --save
browser
Use browserify.
API
var digraph = require('digraph');
digraph
is a factory function creates directed graph object.
var g1 = digraph();
g.node() -> n
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.
Examples:
var a = g1.node('a');
var node = g1.node; // can be detached
var b = node('b');
var c = node('c');
n.edge(n) -> e
Node object has edge
factory that will search for the relevant edge or create one if needed.
Examples:
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);
g.edges
[<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>)
g.get
[<Node>] = g.get.nodes
Return array of nodes in no particular order.
[<Edge>] = g.get.edges
Return array of edges in no particular order.