Simple DAG (Directed Acyclic Graph) module with edge tagging.
$ npm install dagjs
let Dag = require('dagjs');
let dag = new Dag();
// ...
Adding edges:
let dag = new Dag();
// add(from, to, tags, weight)
dag.add('Mike', 'Josh', 'follows', 3);
dag.add('Mary', 'Josh', ['follows', 'likes'], 50);
dag.add('Josh', 'John', ['follows', 'admires']);
dag.add('Mike', 'Mary', 'likes', 100);
// It results in a DAG:
// follows admires
// Mike ----3---> Josh --------> John
// | ^
// | |
// | 50 follows and likes
// | likes |
// -----100---> Mary
Filtering by tag:
let likeDag = dag.filterByTag('likes');
// likeDag =
// likes follows and likes
// Mike --100--> Mary ---------50--------> Josh
Neighbouring:
let edgesToJosh = dag.edgesTo('Josh');
// edgesToJosh =
// [
// {from:'Mike', to:'Josh', tags:['follows'], weight:3},
// {from: 'Mary', to:'Josh', tags:['follows', 'likes'], weight: 50}
// ]
let edgesFromMary = dag.edgesFrom('Mary');
// edgesFromMary =
// [
// {from: 'Mary', to:'Josh', tags:['follows', 'likes'], weight: 50}
// ]
let neighbourhoodOfJosh = dag.neighbourhood('Josh');
// neighbourhoodOfJosh =
// follows admires
// Mike ----3---> Josh --------> John
// ^
// |
// 50 follows and likes
// |
// Mary
Clones:
// shallow-clone
let shallowDag = dag.clone();
// deep-clone
let deepDag = dag.deepClone();