New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apexsankey

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apexsankey

A JavaScript library to create Sankey diagrams built on SVG

  • 1.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
332
increased by3.75%
Maintainers
0
Weekly downloads
 
Created
Source

ApexSankey

A JavaScript library to create Sankey diagrams built on SVG

apex-sankey-chart

Dependency

Include svg.js

<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js"></script>

Installation

To add the ApexSankey to your project and its dependencies, install the package from npm.

npm install apexsankey

Usage

import ApexSankey from "apexsankey";

To create a basic sankey with minimal configuration, write as follows:

<div id="sankey-container"></div>
 const data = {
   ...(data with format provided below)
 }
 const options = {
    width: 800,
    height: 800,
    canvasStyle: 'border: 1px solid #caced0; background: #f6f6f6;',
    spacing: 100,
    nodeWidth: 20,
 };
 const sankey = new ApexSankey(document.getElementById('sankey-container'), options);
 const graph = sankey.render(data);

ApexSankey Options

The layout can be configured by either setting the properties in the table below by passing a second arg to ApexSankey with these properties set. The latter takes precedence.

OptionsDefaultDescription
width800The width of graph container
height800The height of graph container
canvasStyleNoneThe css styles for canvas root container
spacing100The spacing from top and left of graph container
nodeWidth20The width of graph nodes
nodeBorderWidth1The border width of the nodes in pixels
nodeBorderColornoneThe border color of the nodes
onNodeClickempty functionThe callback function for node click. Node object will be parameter for callback.
edgeOpacity0.4The opacity value for edges. Values must be between 0 to 1 and in fraction.
enableTooltipfalseEnable tooltip on hover of nodes
tooltipIdsankey-tooltip-containerThe tooltip HTML element id
tooltipTemplatetooltipTemplateThe HTML template for tooltip
tooltipBorderColor#BCBCBCThe border color of tooltip
tooltipBGColor#FFFFFFThe background color of tooltip
fontSize14pxThe size of font of nodes
fontFamilyNoneThe font family of nodes
fontWeight400The font weight of nodes
fontColor#000000The font color of nodes

Default tooltip template

const tooltipTemplate = ({source, target, value}) => {
    return `
      <div style='display:flex;align-items:center;gap:5px;'>
        <div style='width:12px;height:12px;background-color:${source.color}'></div>
        <div>${source.title}</div>
        <div>=></div>
        <div style='width:12px;height:12px;background-color:${target.color}'></div>
        <div>${target.title}</div>
        <div>: ${value}</div>
      </div>
    `;
  },

Expected data format

Passed data should be an object containing nodes, edges and options. Nodes, edges and options should be in below format.

  • nodes : Passed node object should contain id and title. Id is for uniquely identifying nodes and title is for node titles. It will be also used for showing tooltips for node-to-node connections.
{
  "id": "1", // required
  "title": "A" // required
}
  • edges : Passed edge object should contain source, target, value and type. source is id value of source node for edge, target is id value of target node for edge, value indicates edge size and type is for grouping nodes.
{
    "source": "a",    // required
    "target": "b",    // required
    "value": 1,       // required
    "type": "x",      // optional
},
  • options : ApexSankey supports two options order and alightLinkTypes.

    • order: optional list of layers

      If order is not specified, the nodes are automatically assigned to layers. If order is specified, it is used directly and no rank assignment or ordering algorithm takes place.

      The order structure has three nested lists: order is a list of layers, each of which is a list of bands, each of which is a list of node ids. For example,

      {
          "order": [
              [["a", "b"]],
              [["c"]],
          ],
      },
      
    • alignLinkTypes: boolean (default false). Whether to align link types across nodes, or order links to minimise crossings.

Example

const data = {
  nodes: [
    {
      id: "a",
      title: "AAA",
    },
    {
      id: "b",
      title: "BBB",
    },
    {
      id: "c",
      title: "CCC",
    },
  ],
  edges: [
    {
      source: "a",
      target: "c",
      value: 1,
      type: "A",
    },
    {
      source: "b",
      target: "c",
      value: 2,
      type: "A",
    },
  ],
  options: {
    order: [[["a", "b"]], [["c"]]],
  },
};

FAQs

Package last updated on 23 Dec 2024

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