https://github.com/drom/digraph
Directed graph library
https://github.com/drom/digraph
digraph graph math
Last synced: 12 months ago
JSON representation
Directed graph library
- Host: GitHub
- URL: https://github.com/drom/digraph
- Owner: drom
- License: mit
- Created: 2013-07-16T02:29:15.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2020-04-10T02:37:01.000Z (almost 6 years ago)
- Last Synced: 2025-03-13T03:32:54.878Z (12 months ago)
- Topics: digraph, graph, math
- Language: JavaScript
- Homepage:
- Size: 70.3 KB
- Stars: 1
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/digraph)
[](https://travis-ci.org/drom/digraph)
[](https://coveralls.io/github/drom/digraph?branch=master)
# digraph
Digraph module provides several functions for working with
[directed graph](http://en.wikipedia.org/wiki/Directed_graph)s (digraphs)
in JavaScript.
## node.js
```js
npm i digraph --save
```
## browser
Use browserify.
## API
```js
var digraph = require('digraph');
```
`digraph` is a factory function creates directed graph object.
```js
var g1 = digraph();
```
### `g.node() -> n`
Digraph object has `node` factory function.
```js
= g1.node()
```
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:
```js
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:
```js
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`
```js
[] = g1.edges.from()
```
Return array of all outgoing edges.
```js
[] = g1.edges.to()
```
Return array of all incoming edges.
```js
[] = g1.edges.at()
```
### `g.get`
```js
[] = g.get.nodes
```
Return array of nodes in no particular order.
```js
[] = g.get.edges
```
Return array of edges in no particular order.