@amaui/graph
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

amaui logo

amaui Graph

Graph


MIT license     Production ready     UMD 2.2kb gzipped     100% test cov     Browser and Nodejs

Very simple code     Modern code     Junior friendly     Typescript     Made with 💛


Getting started

Add

  // yarn
  yarn add @amaui/graph

  // npm
  npm install @amaui/graph

Use cases

  • Social media network
  • Maps, roads connections, GPS
  • Search result relevancy algorithm
  • etc.

Use

  import AmauiGraph from '@amaui/graph';

  // Make a new graph instance
  const amauiGraph = new AmauiGraph({ weighted: true });

  // Add nodes
  amauiGraph
    .addNode('a')
    .addNode('b')
    .addNode('c')
    .addNode('d')
    .addNode('e')
    .addNode('f')
    .addNode('g');

  // Add connections
  amauiGraph
    .addConnection('a', 'b', 2)
    .addConnection('a', 'c', 7)
    .addConnection('b', 'd', 5)
    .addConnection('c', 'd', 7)
    .addConnection('d', 'e', 14)
    .addConnection('d', 'f', 11)
    .addConnection('e', 'f', 4)
    .addConnection('f', 'g', 2)
    .addConnection('e', 'g', 4);

  // matrix
  amauiGraph.array;
  // [
  //   [ 0, 2, 7, 0, 0, 0, 0 ],
  //   [ 2, 0, 0, 5, 0, 0, 0 ],
  //   [ 7, 0, 0, 7, 0, 0, 0 ],
  //   [ 0, 5, 7, 0, 14, 11, 0 ],
  //   [ 0, 0, 0, 14, 0, 4, 4 ],
  //   [ 0, 0, 0, 11, 4, 0, 2 ],
  //   [ 0, 0, 0, 0, 4, 2, 0 ]
  // ]

  // Shortest path
  amauiGraph.shortestPath('a', 'g');

  // {
  //   distance: 20,
  //   path: 'a-b-d-f-g'
  // }

Dev

Install

  yarn

Test

  yarn test

Prod

Build

  yarn build

Docs

Might be soon...

Package Sidebar

Install

npm i @amaui/graph

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

41.5 kB

Total Files

11

Last publish

Collaborators

  • lazareric