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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-apexsankey

v1.0.0

Published

React wrapper for ApexSankey - A JavaScript library to create Sankey diagrams

Readme

react-apexsankey

React wrapper for ApexSankey — a JavaScript library for creating Sankey diagrams.

Installation

npm install react-apexsankey apexsankey

Note: apexsankey is a peer dependency and must be installed alongside react-apexsankey.

Basic Usage

import { ApexSankey } from "react-apexsankey";

const data = {
  nodes: [
    { id: "oil", title: "Oil" },
    { id: "gas", title: "Natural Gas" },
    { id: "coal", title: "Coal" },
    { id: "fossil", title: "Fossil Fuels" },
    { id: "energy", title: "Energy" },
  ],
  edges: [
    { source: "oil", target: "fossil", value: 15, type: "flow" },
    { source: "gas", target: "fossil", value: 20, type: "flow" },
    { source: "coal", target: "fossil", value: 25, type: "flow" },
    { source: "fossil", target: "energy", value: 60, type: "flow" },
  ],
};

function App() {
  return (
    <ApexSankey
      data={data}
      options={{
        width: 800,
        height: 500,
        nodeWidth: 20,
      }}
    />
  );
}

License Setup

If you have a commercial license, set it once at app initialization before rendering any charts:

import { setApexSankeyLicense } from "react-apexsankey";

setApexSankeyLicense("your-license-key-here");

Using Refs

Access the underlying SankeyGraph instance via refs:

import { useRef, useEffect } from "react";
import { ApexSankey, ApexSankeyRef } from "react-apexsankey";

function App() {
  const chartRef = useRef<ApexSankeyRef>(null);

  useEffect(() => {
    if (chartRef.current?.graph) {
      console.log("Max rank:", chartRef.current.graph.maxRank);
    }
  }, []);

  return <ApexSankey ref={chartRef} data={data} options={options} />;
}

Props

| Prop | Type | Default | Description | | ----------- | ------------------------ | ------------ | ------------------------------------- | | data | GraphData | required | Sankey data (nodes and edges) | | options | Partial<SankeyOptions> | - | Sankey configuration (see below) | | className | string | - | CSS class for the container | | style | CSSProperties | - | Inline styles for the container |

SankeyOptions

All Sankey configuration is passed through the options prop. SankeyOptions is an intersection of the sub-interfaces below — pass a partial; any omitted field falls back to its default.

Canvas & layout

| Option | Type | Default | Description | | ---------------- | ------------------ | -------- | ------------------------------------------------------------------- | | width | number \| string | '100%' | Canvas width (pixel number or CSS percentage) | | height | number \| string | 'auto' | Canvas height. 'auto' derives from width at 1.6:1 | | spacing | number | 20 | Horizontal spacing between node columns in pixels | | viewPortWidth | number | 800 | Internal SVG viewport width | | viewPortHeight | number | 500 | Internal SVG viewport height | | whitespace | number | 0.18 | Fraction of vertical space used as margins between nodes (0–1) | | canvasStyle | string | '' | Arbitrary CSS injected onto the SVG root container | | enableToolbar | boolean | true | Show the zoom/pan/export toolbar |

Nodes

| Option | Type | Default | Description | | ----------------- | --------------------------------- | ------- | ---------------------------------------------------------- | | nodeWidth | number | 20 | Width of each node rectangle in pixels | | nodeBorderWidth | number | 1 | Border width of each node in pixels | | nodeBorderColor | string \| null | null | Node border color | | onNodeClick | (node: SankeyNode) => void | - | Callback fired when a node is clicked |

Edges

| Option | Type | Default | Description | | ------------------ | --------- | ------- | --------------------------------------------------------------- | | edgeOpacity | number | 0.4 | Opacity of edges (0–1) | | edgeGradientFill | boolean | true | Fill edges with a gradient between source and target colors | | edgeGap | number | 2 | Gap in pixels between adjacent edges at their connection points |

Font

| Option | Type | Default | Description | | ------------ | -------- | ----------- | -------------------------------- | | fontSize | string | '14px' | CSS font-size for node labels | | fontFamily | string | '' | CSS font-family for node labels | | fontWeight | string | '400' | CSS font-weight for node labels | | fontColor | string | '#212121' | CSS color for node labels |

Tooltip

| Option | Type | Default | Description | | --------------------- | ------------------------------------------------- | ---------------------------------- | ---------------------------------------------------- | | enableTooltip | boolean | true | Show edge tooltips on hover | | tooltipTheme | 'light' \| 'dark' | - | Shortcut for dark/light color presets | | tooltipBGColor | string | '#FFFFFF' | Tooltip background color | | tooltipBorderColor | string | '#E2E8F0' | Tooltip border color | | tooltipFontColor | string | '#1a1a1a' | Tooltip font color | | tooltipId | string | 'apexsankey-tooltip-container' | HTML id for the tooltip container | | tooltipTemplate | (content: TooltipContent) => string | - | Custom edge (source→target) tooltip HTML | | nodeTooltipTemplate | (content: NodeTooltipContent) => string | - | Custom per-node tooltip HTML |

Interaction & animation

| Option | Type | Default | Description | | ------------------------ | --------- | ------- | --------------------------------------------------------------- | | highlightConnectedPath | boolean | true | Highlight the connected flow path on hover | | dimOpacity | number | 0.15 | Opacity for dimmed (unrelated) elements during highlighting | | animation.enabled | boolean | true | Play entrance animation (disabled if prefers-reduced-motion) | | animation.duration | number | 800 | Entrance animation duration in ms |

Accessibility

| Option | Type | Default | Description | | -------------------- | --------- | ------- | ------------------------------------------------------------ | | a11y.enabled | boolean | true | Enable WCAG 2.1 AA accessibility features | | a11y.diagramLabel | string | - | Override the auto-generated aria-label on the SVG root | | a11y.description | string | - | Populates the <desc> element for a longer description |

Data Structure

interface GraphData {
  nodes: SankeyGraphNode[];
  edges: SankeyGraphEdge[];
}

interface SankeyGraphNode {
  id: string;       // unique identifier
  title: string;    // display label
  color?: string;   // override auto-assigned palette color
}

interface SankeyGraphEdge {
  source: string;   // id of upstream node
  target: string;   // id of downstream node
  value: number;    // flow value — determines edge band width
  type: string;     // category label (used for grouping and tooltip)
}

Custom Tooltip

<ApexSankey
  data={data}
  options={{
    enableTooltip: true,
    tooltipTemplate: ({ source, target, value }) => `
      <div style="padding: 8px;">
        <strong>${source?.title}</strong> → <strong>${target?.title}</strong>
        <br />
        Value: ${value}
      </div>
    `,
  }}
/>

TypeScript Support

Full TypeScript support with exported types:

import type {
  ApexSankeyProps,
  ApexSankeyRef,
  GraphData,
  SankeyGraphNode,
  SankeyGraphEdge,
  SankeyOptions,
  SankeyNode,
  TooltipContent,
  NodeTooltipContent,
} from "react-apexsankey";

SSR Support

This component is SSR-safe and renders an empty container on the server. The chart is only rendered client-side after hydration.

License

react-apexsankey uses the same dual-license model as ApexCharts. See LICENSE for details.

  • Free for individuals, non-profits, and small businesses (< $2M revenue)
  • Commercial license required for larger organizations

Links