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

@pinging/dagrejs

v1.0.1

Published

Layered layout for directed acyclic graph

Downloads

4,429

Readme

dagrejs - Layered layout for directed acyclic graph

This project is a fork from dagre. For more information prelase refer to origin project.

Enhanced features

New features:

  • support specify layer(rank) for certain node
  • support manually control nodes' order
  • support keep origin layout when re-layout with nodes added

Optimizations:

  • rewrite rank algorithm to support assign layer
  • consider previous iteration result at node-ordering step
  • support generate edgeLabelSpacing or not, which controls generate dummy node between nodes

Usage

For full usage please refer to dagre's documentation: https://github.com/dagrejs/dagre/wiki.

edgeLabelSpace

Default dagre always generate dummy node for every edge, which can be used for edge's curve drawing, etc. If you do not need it, disable it in layout's options:

dagre.layout(g, {
  edgeLabelSpace: false
})

Bellow shows graph with or without edgeLabelSpace:

Specify layer

Now you can manually specify node's layer(rank) by add layer in node's attribute:

const data = {
    nodes: [
        { id: '0' },
        { id: '1', layer: 1 },
        { id: '2', layer: 3 },
        { id: '3' },
    ],
    // edges: [...]
}

data.nodes.forEach((n) => {
    g.setNode(n.id, n);
});

Caution:

  • layer is 0-indexed, which means the root node's layer is 0
  • manual layer should not violate DAG's properties (e.g. You cannot assign a layer value for a target node greater or equal to cresponding source node.)

Control nodes' order

Sometimes we want to manually control nodes' order in every layer in case of unexpected result caused by alogrithm. Now we can also configurate in options.

dagre.layout(g, {
  keepNodeOrder: true,
  nodeOrder: ['3', '2', '1', '0'] // an array of nodes's ID.
});

A common usage is keeping data's order:

const data = {
    nodes: [
        { id: '0' },
        { id: '2' },
        { id: '3' },
        { id: '1' },
    ],
    // edges: [...]
}

dagre.layout(g, {
  keepNodeOrder: true,
  nodeOrder: data.nodes.map(n => n.id)
});

Caution:

  • The order only work at same layer ordering step. It does not affect the layer assignment step.
  • Like specifying layer, internally the library added fixorder attribute for each node. Of cause you can manually set this attribute, but it introduces ambiguity.

Keep origin layout

When re-layout with small modification, we may want to keep origin layout result. Now we can pass the origin graph to new layout function:

dagre.layout(originGraph) // layout() will internally modify originGraph
dagre.layout(
  g,
  {
    prevGraph: originGraph // pass originGraph to new function
  }
);

For full example please refer to add-subgraph example in examples folder.