0.1.4 • Published 6 years ago

dagjs v0.1.4

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

dag.js npm version Build Status Coverage Status

Simple DAG (Directed Acyclic Graph) module with edge tagging.

Install

$ npm install dagjs

Usage

let Dag = require('dagjs');

let dag = new Dag();
// ...

Analytics

Examples

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();
0.1.4

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago