Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stephanhoyer/sigmar
Digraph library for node.js
https://github.com/stephanhoyer/sigmar
Last synced: 3 months ago
JSON representation
Digraph library for node.js
- Host: GitHub
- URL: https://github.com/stephanhoyer/sigmar
- Owner: StephanHoyer
- License: mit
- Created: 2013-09-16T07:46:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T08:31:15.000Z (about 1 year ago)
- Last Synced: 2024-04-13T22:24:43.299Z (9 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 46
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/StephanHoyer/sigmar.png?branch=master)](https://travis-ci.org/StephanHoyer/sigmar)
#sigmar
Digraph library for node.js.
**Note:** This is work in progress. API can change.
##Installation
npm install sigmar
##Example Usage
var sigmar = require('sigmar');
var graph = sigmar();
graph
.from('foo')
.to('bar')
.childrenOf('foo').items
// { bar: null }## API
### Create node
Adds a node to the graph with given content. Name must be a string.graph.node(name, content);
### Create an edgeCreates an edge from given node to given node. Node is created if
it does not exist. If content is given, it will be attached to node.
If node exists and content is given, the conten will be overwritten.graph.from(name, content).to(name, content);
It's also possible to create multiple nodes at once:
graph.from([name, ...], content).to([name, ...], content);
If content is given, all nodes get the same content. Notice that all
from nodes are now connected to all to nodes.Objects are possible too:
graph.from({name: content, ...}).to({name: content, ...})
### Chaining
All operations can be chained:
graph.from(name).and(name).to(name).and(name);
graph.from(name).to(name).and.from(name).to(name);
Chained to's are also possible:graph.from('foo').to('bar').to('baz')
// foo -> bar -> bazLook at the tests for more ways to define your graph.
### Selectors
graph.ancestorsOf(name, depth)
// selects all ancestors of given node respecting the depth
graph.parentsOf(name)
// selects all parents of given node.graph.descendantsOf(name, depth)
// selects all descendants of given node respecting the depth
graph.childrenOf(name)
// selects all children of given node.