JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q49439F
  • License MIT

Simiple DAG (Directed Acyclic Graph) module with edge tagging

Package Exports

  • dagjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dagjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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