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

bihisankey

v1.0.3

Published

Bi-directional hierarchical sankey diagram

Downloads

212

Readme

BiDirectional Hierarchical Sankey Diagram

This is a d3 javascript plugin/library for generating bidirectional hierarchial sankey diagrams

The sourcecode is almost entirely forked from @Neilos's work. Kudos to him ! I've mostly created a npm wrapper and added a depth property to the nodes along with some basic typings

### Live Code Demonstration

For a a full demonstration of the use of this library: http://bl.ocks.org/duhaime/3865371eea1bd32b36f53e63dabb6b72

Overview

To Set the diagram properties:

biHiSankey
  .nodeWidth(30) // sets the pixel width of all nodes (heights are variable, widths are fixed)
  .nodeSpacing(10) // sets the minimum vertical pixel spacing between nodes
  .linkSpacing(4) // sets the vertical pixel spacing between links
  .arrowheadScaleFactor(0.5) // Specifies the proportion of a link's stroke width that should be allowed for the marker at the end of the link e.g. an arrow
  .size([someWidth, someHeight]); // sets the width and height of the diagram in pixels

To (re)initialize the sankey diagram with data

var someNodes = [
  {"type": "A", "id": 1, "parent": null, "name": "Node 1", Xdepth: 0, Ydepth: 1},
  {"type": "A", "id": 2, "parent": "1", "name": "Node 2"},
  {"type": "A", "id": 3, "parent": "1", "name": "Node 3"},
  {"type": "B", "id": 4, "parent": null, "name": "Node 4", Xdepth: 1, Ydepth: 3},
  {"type": "B", "id": 5, "parent": "4", "name": "Node 5"},
  {"type": "C", "id": 6, "parent": "5", "name": "Node 6"},
]
var someLinks = [
  {source: 3, target: 2, value: 20},
  {source: 2, target: 3, value: 90},
  {source: 3, target: 6, value: 40},
  {source: 6, target: 2, value: 70},
  {source: 6, target: 3, value: 10},
]

biHiSankey
  .nodes(someNodes) // pass in the nodes
  .links(someLinks) // pass in the nodes
  .initializeNodes(function (node) {
    // amend or add properties to each node as required
    // ...
  })

If two nodes (n1, n2) have different Xdepths: n1.Xdepth < n2.Xdepth then the node n1 will be placed to the left of n2 If two nodes (n1, n2) have different Ydepths: n1.Ydepth < n2.Ydepth then the node n1 will be placed on top of n2

To (re)calculate the attributes of all nodes and links:

biHiSankey.layout(20); // pass in a maximum number of iterations

To (re)calculate link paths and node heights but do not change the node positions:

biHiSankey.relayout();

To return any of the previously set properties:

biHiSankey.links();
biHiSankey.visibleLinks();
biHiSankey.linkSpacing();
biHiSankey.nodes();
biHiSankey.nodeWidth();
biHiSankey.nodeSpacing();
biHiSankey.size();

License

BiHiSankey is released under the MIT License.