Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-sankey

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-sankey

Visualize flow between nodes in a directed acyclic network.

  • 0.3.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
209K
decreased by-79.91%
Maintainers
2
Weekly downloads
 
Created

What is d3-sankey?

The d3-sankey npm package is a plugin for D3.js that provides tools for creating Sankey diagrams. Sankey diagrams are a type of flow diagram in which the width of the arrows is proportional to the flow rate. They are typically used to visualize energy or material transfers between processes.

What are d3-sankey's main functionalities?

Creating a Sankey Diagram

This code demonstrates how to create a basic Sankey diagram using the d3-sankey package. It defines nodes and links, sets up the Sankey generator, and generates the Sankey layout.

const { sankey, sankeyLinkHorizontal } = require('d3-sankey');
const data = {
  nodes: [
    { name: 'A' },
    { name: 'B' },
    { name: 'C' }
  ],
  links: [
    { source: 0, target: 1, value: 10 },
    { source: 1, target: 2, value: 5 }
  ]
};
const sankeyGenerator = sankey().nodeWidth(15).nodePadding(10).extent([[1, 1], [500, 500]]);
const sankeyData = sankeyGenerator(data);
console.log(sankeyData);

Customizing Node Width and Padding

This code shows how to customize the node width and padding in a Sankey diagram. By adjusting these parameters, you can control the appearance and spacing of the nodes in the diagram.

const { sankey } = require('d3-sankey');
const data = {
  nodes: [
    { name: 'A' },
    { name: 'B' },
    { name: 'C' }
  ],
  links: [
    { source: 0, target: 1, value: 10 },
    { source: 1, target: 2, value: 5 }
  ]
};
const sankeyGenerator = sankey().nodeWidth(20).nodePadding(15).extent([[1, 1], [500, 500]]);
const sankeyData = sankeyGenerator(data);
console.log(sankeyData);

Generating Sankey Links

This code demonstrates how to generate the path for a Sankey link using the sankeyLinkHorizontal function. This function creates a path string that can be used to render the link in an SVG element.

const { sankey, sankeyLinkHorizontal } = require('d3-sankey');
const data = {
  nodes: [
    { name: 'A' },
    { name: 'B' },
    { name: 'C' }
  ],
  links: [
    { source: 0, target: 1, value: 10 },
    { source: 1, target: 2, value: 5 }
  ]
};
const sankeyGenerator = sankey().nodeWidth(15).nodePadding(10).extent([[1, 1], [500, 500]]);
const sankeyData = sankeyGenerator(data);
const linkPath = sankeyLinkHorizontal();
const link = sankeyData.links[0];
console.log(linkPath(link));

Other packages similar to d3-sankey

Keywords

FAQs

Package last updated on 05 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc