npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

digraphs-layered-layout

v0.1.8

Published

A library for layered, hierarchical layout of digraphs.

Downloads

15

Readme

markdown

Digraphs Layered Layout

A JavaScript library for creating layered layouts of directed graphs (digraphs). This library helps to organize nodes in a visually appealing manner by extracting weakly connected components from a graph, for each of them running Coffman-Graham algorithm, then adding dummy nods, and running barycentric algorithm for x positioning, after this task grid of grids of nodes is normalized and united in a single grid where -2 represents offset of component, -1 offset of node, n >= nodes size is a dummy vector and a nodes size <= value >= 0 is a vertex

Features

  • Centered node placement within each layer.
  • Maximizes distance between nodes in each layer for better visualization.
  • Simple and easy-to-use API.

Installation

Via npm

To install the package via npm, use the following command:

npm install digraphs-layered-layout

Via GitHub

Alternatively, you can add it directly from the GitHub repository:


npm install git+https://github.com/Nikolozi-Potskhishvili/digraphs-layered-layout.git

Usage

Here's how you can use the digraphs-layered-layout library in your project:


import { DiGraph } from 'digraphs-layered-layout';
//create new Digraph object:
const graph = new DiGraph(1);
// Example input: nodes and their connections:
graph.addNode(0);
graph.addNode(1);
graph.addNode(2);
graph.addNode(3);
graph.addNode(4);
graph.addNode(5);
graph.addNode(6);
graph.addNode(7);
graph.addNode(8);
graph.addNode(9);

graph.addEdge(0, 1);
graph.addEdge(0, 2);
graph.addEdge(1, 3);
graph.addEdge(2, 4);
graph.addEdge(0, 4);
graph.addEdge(9, 1);
graph.addEdge(9, 3);
graph.addEdge(9, 4);


// choose desired maximal width of a component and call method below
const width = 3;
const finalGrid = graph.getLayeredDiGraphLayout();

API

DiGraph(type)

creates DiGraph object of a desired type

Parameters: type of an object you will add to the graph.
Returns: void.

getLayeredDiGraphLayout(width)

returns matrix of a weakly connected components

Parameters: width, desired maximal width of every component.
Returns: An array of arrays with values -2 representing component offset, -1 node offset, graph.getSize()>=value>=0 representing nodes and other values - dummy nodes.

Example

Given the following input:

let graph = new DiGraph(1);
graph.addNode(0);
graph.addNode(1);
graph.addNode(2);
graph.addNode(3);
graph.addNode(4);
graph.addNode(5);
graph.addNode(6);
graph.addNode(7);
graph.addNode(8);
graph.addNode(9);

const width = 3;

graph.addEdge(0, 1);
graph.addEdge(0, 2);
graph.addEdge(1, 3);
graph.addEdge(2, 4);
graph.addEdge(0, 4);
graph.addEdge(9, 1);
graph.addEdge(9, 3);
graph.addEdge(9, 4);

const finalGrid = graph.getLayeredDiGraphLayout(width);
finalGrid.forEach((row, index) => console.log(index + " row", row));

The library will output:

0 row [
  -2, 5, -2,  7, -2, -1,
  -1, 9,  0, -1, -2,  8,
  -2, 6, -2
]
1 row [
  -2, -1, -2, -1, -2, 12,
   1,  2, 10, -1, -2, -1,
  -2, -1, -2
]
2 row [
  -2, -1, -2, -1, -2, -1,
  -1,  3,  4, -1, -2, -1,
  -2, -1, -2
]

Development

Running Tests

To run the test suite, use the following command:


npm test

Contributing

Contributions are welcome(especially more tests)! Please feel free to submit a pull request or open an issue. License

This project is licensed under the MIT License - see the LICENSE file for details.