HMPlot

Sankey

A flow diagram layout, with nodes in columns and links as thick as their values.

Rectangles, with flow. x from 0 to 1, y from 0 to 1. 4 rectangles.

Static preview; loading the interactive plot

<script>
  import { Plot, Sankey, Edges, Nodes, Flow, Rect, GraphData } from "hmplot";
  const data = {
    source: ["in", "in", "a", "b"],
    target: ["a", "b", "out", "out"],
    value: [3, 2, 3, 2],
  };
</script>

<Plot {data} height={300}>
  <GraphData source="source" target="target"
    ><Sankey value="value">
      <Edges>
        <Flow
          startLower="startLower"
          endLower="endLower"
          startUpper="startUpper"
          endUpper="endUpper"
        />
      </Edges>
      <Nodes><Rect x0="x0" x1="x1" y0="y0" y1="y1" /></Nodes>
    </Sankey></GraphData
  >
</Plot>

Options

valuecolumn
The edge table's column of nonnegative flows, which set the links' thickness.
orientation"left" | "right" | "down" | "up"
The direction the flow runs. Default: "right".
nodeWidthnumber
The thickness of each node's bar along the flow; the layout spans 0 to 1. Default: 0.025 data units.
nodePaddingnumber
The gap between neighboring nodes in a column; the layout spans 0 to 1. Default: 0.02 data units.
iterationsnumber
Relaxation passes that straighten the links. Default: 8.
align"left" | "right" | "center" | "justify"
Which column each node takes: its depth from the sources (left), its distance to the sinks (right), beside its targets for a source (center), or left with every sink in the last column (justify). Default: "justify".

Usage

Sankey consumes GraphData and lays out nonnegative flows in an acyclic directed graph. Nodes expose x0, x1, y0, y1, x, y, position, depth, and throughput. Edges expose four attachment corners for Flow, plus the original edge columns. Explicit GraphData node tables can include isolated nodes.

Related examples

Sankey flow