Docs
📊 ⏐ Charts
Sankey Plot

Sankey Chart

Sankey diagrams in REAVIZ provide a powerful way to visualize and analyze flows of energy, materials, or costs within a system. They help in identifying major transfers and understanding resource distribution, making them a valuable tool for data visualization.

Where to use:

  • Visualize Flow Quantities: Ideal for displaying flows of energy, materials, or costs.
  • Highlight Major Transfers: Useful for emphasizing significant transfers within a system.
  • Analyze Resource Distribution: Great for analyzing how resources are distributed and transferred.

Quick Start

To create Sankey Chart, import the Sankey, SankeyNode and SankeyLink and then define the nodes and then links. The chart will automatically configure itself with the default options exposed via props.

As default, the Sankey chart shows the link/flow with gradation based on the given colorScheme. You can turn off the gradation by passing false to SankeyLink component's gradient property (e.g. gradient={false}).

Configuration

To render, the nodes and links of the Sankey component are required and colorScheme is optianal but is recommended to spacify to make Sankeys easier to interpret.

  • Nodes: Define the nodes using the SankeyNode component. Each node can have a title and id.
  • Links: Define the links using the SankeyLink component. Each link requires source, target, and value properties. The source and target can be the index of the nodes array or the node's id

Examples

API

Sankey (opens in a new tab)

PropDescriptionDefault
animatedWhether to animate the enter/update/exit. Set internally by `SankeyNode` and `SankeyLink`.
boolean
true
colorSchemeColor scheme for the nodes. Set internally by `SankeyNode`.
ColorSchemeType
justificationThe node alignment method.
Justification
justify
nodeWidthWidth of the node.
number
15
nodePaddingVertical padding between nodes in the same column.
number
10
labelPositionLabel position.
SankeyLabelPosition
nodeSortSort function for the nodes. If sort is specified, sets the node sort method and returns this Sankey generator. If sort is not specified, returns the current node sort method, which defaults to undefined, indicating that vertical order of nodes within each column will be determined automatically by the layout. If sort is null, the order is fixed by the input. Otherwise, the specified sort function determines the order; the function is passed two nodes, and must return a value less than 0 if the first node should be above the second, and a value greater than 0 if the second node should be above the first, or 0 if the order is not specified. Reference: https://github.com/d3/d3-sankey#sankey_nodeSort
(a: any, b: any) => number
nodes *Nodes that are rendered.
NodeElement[]
links *Links that are rendered.
LinkElement[]
idId of the chart.
string
widthWidth of the chart. If not provided will autosize.
number
heightHeight of the chart. If not provided will autosize.
number
marginsMargins for the chart.
Margins
classNameClassnames for the chart.
string
containerClassNameClassnames for the chart.
string
styleAdditional css styles.
StyleHTMLAttributes<SVGSVGElement>
centerCenter the chart. Used mainly internally.
boolean
centerXCenter chart on X Axis only. Used mainly internally.
boolean
centerYCenter chart on Y Axis only. Used mainly internally.
boolean

SankeyLink (opens in a new tab)

PropDescriptionDefault
colorColor of the link.
string
activeWhether the element is active or not. Set internally by `Sankey`.
boolean
false
animatedWhether to animate the enter/update/exit.
boolean
true
chartIdId of Sankey chart. Set internally by `Sankey`.
string
classNameCSS class to apply.
string
disabledWhether the node is disabled. Set internally by `Sankey`.
boolean
false
gradientWhether to use gradient or not.
boolean
true
opacityOpacity callback for the link.
(active: boolean, disabled: boolean) => number
(active, disabled) => (active ? 0.5 : disabled ? 0.1 : 0.35)
styleCSS styles to apply.
object
tooltipTooltip element.
ReactElement<TooltipProps, FC<TooltipProps>>
( <Tooltip theme={tooltipTheme} followCursor={true} modifiers={[offset(5)]} /> )
widthWidth of the link. Set internally by `Sankey`.
number
0
onClickEvent for when the link is clicked.
(event: MouseEvent<SVGPathElement, MouseEvent>) => void
onMouseEnterEvent for when the link has mouse enter.
(event: MouseEvent<SVGPathElement, MouseEvent>) => void
onMouseLeaveEvent for when the link has mouse leave.
(event: MouseEvent<SVGPathElement, MouseEvent>) => void
sourceLink's source node. For convenience, when initializing a Sankey layout using the default node id accessor, source may be the zero-based index of the corresponding node in the nodes array returned by the nodes accessor of the Sankey layout generator rather than object references. Alternatively, the Sankey layout can be configured with a custom node ID accessor to resolve the source node of the link upon initialization. Once the Sankey generator is invoked to return the Sankey graph object, the numeric index will be replaced with the corresponding source node object.
string | number | SankeyNode<NodeExtra, LinkExtra>
targetLink's target node. For convenience, when initializing a Sankey layout using the default node id accessor, target may be the zero-based index of the corresponding node in the nodes array returned by the nodes accessor of the Sankey layout generator rather than object references. Alternatively, the Sankey layout can be configured with a custom node ID accessor to resolve the target node of the link upon initialization. Once the Sankey generator is invoked to return the Sankey graph object, the numeric index will be replaced with the corresponding target node object.
string | number | SankeyNode<NodeExtra, LinkExtra>
valueLink's numeric value
number
y0Link's vertical starting position (at source node) calculated by Sankey layout generator.
number
y1Link's vertical end position (at target node) calculated by Sankey layout generator.
number
indexLink's zero-based index within the array of links calculated by Sankey layout generator.
number

SankeyNode (opens in a new tab)

PropDescriptionDefault
idID of the node. If not provided, the node's index will be used.
string
titleTitle of the node.
string
colorColor of the node.
string
rgba(255, 255, 255, 0.2)
activeWhether the element is active or not. Set internally by `Sankey`.
boolean
false
animatedWhether to animate the enter/update/exit.
boolean
true
chartWidthWidth of the chart. Set internally by `Sankey`.
number
classNameCSS class to apply.
string
disabledWhether the node is disabled. Set internally by `Sankey`.
boolean
false
labelLabel element.
ReactElement<SankeyLabelProps, FC<Partial<SankeyLabelProps>>>
<SankeyLabel />
labelPositionLabel position. Set internally by `Sankey`.
SankeyLabelPosition
labelPaddingPercentage of total width occupied by labels on either side of the graph inside the container. Set internally by `Sankey`.
number
opacityOpacity callback for the node.
(active: boolean, disabled: boolean) => number
(active, disabled) => (active ? 1 : disabled ? 0.2 : 0.9)
styleCSS styles to apply.
StyleHTMLAttributes<SVGRectElement>
tooltipTooltip element.
ReactElement<TooltipProps, FC<TooltipProps>>
( <Tooltip theme={tooltipTheme} followCursor={true} modifiers={[offset({ mainAxis: 0, crossAxis: 5 })]} /> )
widthWidth of the node. Set internally by `Sankey`.
number
onClickEvent for when the node is clicked.
(event: MouseEvent<SVGRectElement, MouseEvent>) => void
onMouseEnterEvent for when the node has mouse enter.
(event: MouseEvent<SVGRectElement, MouseEvent>) => void
onMouseLeaveEvent for when the node has mouse leave.
(event: MouseEvent<SVGRectElement, MouseEvent>) => void
sourceLinksArray of outgoing links which have this node as their source. This property is calculated internally by the Sankey layout generator.
SankeyLink<NodeExtra, LinkExtra>[]
targetLinksArray of incoming links which have this node as their target. This property is calculated internally by the Sankey layout generator.
SankeyLink<NodeExtra, LinkExtra>[]
valueNode's value calculated by Sankey layout Generator; the sum of link.value for the node’s incoming links.
number
fixedValueNode's fixedValue (user-defined)
number
indexNode’s zero-based index within the array of nodes calculated by Sankey layout generator.
number
depthNode’s zero-based graph depth, derived from the graph topology calculated by Sankey layout generator.
number
heightNode’s zero-based graph height, derived from the graph topology calculated by Sankey layout generator.
number
x0Node's minimum horizontal position (derived from the node.depth) calculated by Sankey layout generator.
number
x1Node’s maximum horizontal position (node.x0 + sankey.nodeWidth) calculated by Sankey layout generator.
number
y0Node's minimum vertical position calculated by Sankey layout generator.
number
y1Node's maximum vertical position (node.y1 - node.y0 is proportional to node.value) calculated by Sankey layout generator.
number