forked from dagrejs/graphlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9c37e9
Showing
8 changed files
with
960 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/graphlib.min.js | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "0.8" | ||
- "0.6" | ||
script: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2012-2013 Chris Pettitt | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
NODE?=node | ||
NPM?=npm | ||
MOCHA?=node_modules/mocha/bin/mocha | ||
MOCHA_OPTS?= | ||
JS_COMPILER=node_modules/uglify-js/bin/uglifyjs | ||
JS_COMPILER_OPTS?=--no-seqs | ||
|
||
MAIN_JS=graphlib.js | ||
MAIN_MIN_JS=graphlib.min.js | ||
|
||
# There does not appear to be an easy way to define recursive expansion, so | ||
# we do our own expansion a few levels deep. | ||
JS_TEST:=$(wildcard test/*.js test/*/*.js test/*/*/*.js) | ||
|
||
all: $(MAIN_MIN_JS) test | ||
|
||
$(MAIN_MIN_JS): $(MAIN_JS) | ||
@rm -f $@ | ||
$(NODE) $(JS_COMPILER) $(JS_COMPILER_OPTS) $< > $@ | ||
@chmod a-w $@ | ||
|
||
lib/version.js: src/version.js package.json | ||
$(NODE) src/version.js > $@ | ||
|
||
node_modules: package.json | ||
$(NPM) install | ||
|
||
.PHONY: test | ||
test: $(MAIN_JS) $(JS_TEST) | ||
$(NODE) $(MOCHA) $(MOCHA_OPTS) $(JS_TEST) | ||
|
||
clean: | ||
rm -f $(MAIN_MIN_JS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Graphlib | ||
|
||
Graphlib is a JavaScript library that provides an implementation of a directed | ||
multi-graph. This library is used as part of the | ||
[dagre])https://github.com/cpettitt/dagre) library, but is available here in a | ||
light-weight, standalone form. | ||
|
||
# Build / Install | ||
|
||
Before building this library you need to install the [npm package manager]. | ||
|
||
To get graphlib from npm, use: | ||
|
||
$ npm install graphlib | ||
|
||
# Use | ||
|
||
Graphlib currently exports a single Graph object. The graphlib.js file includes | ||
documentation for each of the functions on this Object. | ||
|
||
Here we'll show a running example of the Graph API. | ||
|
||
```js | ||
var Graph = require("graphlib").Graph; | ||
|
||
// Create a new empty graph | ||
var g = new Graph(); | ||
|
||
// Add node "A" to the graph with no value | ||
g.addNode("A"); | ||
|
||
// This returns true | ||
g.hasNode("A"); | ||
|
||
// Add node "B" to the graph with a String value | ||
g.addNode("B", "B's value"); | ||
|
||
// Prints `B's value` | ||
console.log(g.node("B")); | ||
|
||
// Add node "C" to the graph with an Object value | ||
g.addNode("C", { k: 123 }); | ||
g.addNode("D"); | ||
|
||
// Prints `[ 'A', 'B', 'C', 'D' ]` | ||
console.log(g.nodes()); | ||
|
||
// Add a directed edge with the ID "AB" from "A" to "B", but assign no value | ||
g.addEdge("AB", "A", "B"); | ||
|
||
// Add a directed edge with no ID (Graph will assign one) from "B" to "C" | ||
g.addEdge(null, "B", "C"); | ||
|
||
// Add a directed edge from "C" to "D" with an Object value | ||
g.addEdge("CD", "C", "D", { k: 456 }); | ||
|
||
// Since Graph is a multi-graph, we can have multiple edges incident on the | ||
// same source and target nodes. | ||
g.addEdge("AB2", "A", "B"); | ||
|
||
// Prints `[ 'AB', '_ANON-1', 'CD', 'AB2' ]`. `_ANON-1` is the edge from "B" to "C" | ||
console.log(g.edges()); | ||
|
||
// Which edges go from "A" to "B"? This prints `[ 'AB', 'AB2' ]` | ||
console.log(g.edges("A", "B")); | ||
|
||
// Which edges are incident on "D"? This prints `[ 'CD' ]` | ||
console.log(g.edges("D")); | ||
|
||
// How about a subgraph? | ||
var g2 = g.subgraph(["A", "B", "C"]); | ||
|
||
// Prints `[ 'A', 'B', 'C' ]` | ||
console.log(g2.nodes()); | ||
|
||
// Prints `[ 'AB', '_ANON-1', 'AB2' ]`. Note that edges that have both their | ||
// source and target nodes in the graph are also included in the subgraph. | ||
console.log(g2.edges()); | ||
``` | ||
There are a number of other functions for doing queries on `Graph` objects. | ||
Please see `graphlib.js` which includes documentation for each of the | ||
functions. | ||
|
||
# License | ||
|
||
Graphlib is licensed under the terms of the MIT License. See the LICENSE file | ||
for details. | ||
|
||
[npm package manager]: http://npmjs.org/ |
Oops, something went wrong.