Skip to Content

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Β 

NameTypeDefault
animatedboolean

Whether to animate the enter/update/exit. Set internally by SankeyNode and SankeyLink.

true
colorSchemeColorSchemeType

Color scheme for the nodes. Set internally by SankeyNode.

justificationJustification

The node alignment method.

'justify'
nodeWidthnumber

Width of the node.

15
nodePaddingnumber

Vertical padding between nodes in the same column.

10
labelPositionSankeyLabelPosition

Label position.

'inside'
nodeSort(a: any, b: any) => number

Sort 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Β 

nodesNodeElement[]

Nodes that are rendered.

idstring

Id of the chart.

widthnumber

Width of the chart. If not provided will autosize.

heightnumber

Height of the chart. If not provided will autosize.

marginsMargins

Margins for the chart.

classNamestring

Classnames for the chart.

containerClassNamestring

Classnames for the chart.

styleStyleHTMLAttributes<SVGSVGElement>

Additional css styles.

centerboolean

Center the chart. Used mainly internally.

centerXboolean

Center chart on X Axis only. Used mainly internally.

centerYboolean

Center chart on Y Axis only. Used mainly internally.

NameTypeDefault
colorstring

Color of the link.

activeboolean

Whether the element is active or not. Set internally by Sankey.

false
animatedboolean

Whether to animate the enter/update/exit.

true
chartIdstring

Id of Sankey chart. Set internally by Sankey.

classNamestring

CSS class to apply.

disabledboolean

Whether the node is disabled. Set internally by Sankey.

false
gradientboolean

Whether to use gradient or not.

true
opacity(active: boolean, disabled: boolean) => number

Opacity callback for the link.

styleobject

CSS styles to apply.

tooltipReactElement<TooltipProps, FC<TooltipProps>> | null

Tooltip element.

`<Tooltip followCursor modifiers={[offset(5)]} />`
widthnumber

Width of the link. Set internally by Sankey.

0
onClick(event: MouseEvent<SVGPathElement, MouseEvent>) => void

Event for when the link is clicked.

onMouseEnter(event: MouseEvent<SVGPathElement, MouseEvent>) => void

Event for when the link has mouse enter.

onMouseLeave(event: MouseEvent<SVGPathElement, MouseEvent>) => void

Event for when the link has mouse leave.

SankeyNodeΒ 

NameTypeDefault
idstring

ID of the node. If not provided, the node’s index will be used.

titlestring

Title of the node.

colorstring

Color of the node.

DEFAULT_COLOR
activeboolean

Whether the element is active or not. Set internally by Sankey.

false
animatedboolean

Whether to animate the enter/update/exit.

true
chartWidthnumber

Width of the chart. Set internally by Sankey.

classNamestring

CSS class to apply.

disabledboolean

Whether the node is disabled. Set internally by Sankey.

false
labelReactElement<SankeyLabelProps, FC<Partial<SankeyLabelProps>>>

Label element.

`<SankeyLabel />`
labelPositionSankeyLabelPosition

Label position. Set internally by Sankey.

labelPaddingnumber

Percentage of total width occupied by labels on either side of the graph inside the container. Set internally by Sankey.

opacity(active: boolean, disabled: boolean) => number

Opacity callback for the node.

styleStyleHTMLAttributes<SVGRectElement>

CSS styles to apply.

tooltipReactElement<TooltipProps, FC<TooltipProps>> | null

Tooltip element.

`<Tooltip followCursor modifiers={[offset(5)]} />`
widthnumber

Width of the node. Set internally by Sankey.

onClick(event: MouseEvent<SVGRectElement, MouseEvent>) => void

Event for when the node is clicked.

onMouseEnter(event: MouseEvent<SVGRectElement, MouseEvent>) => void

Event for when the node has mouse enter.

onMouseLeave(event: MouseEvent<SVGRectElement, MouseEvent>) => void

Event for when the node has mouse leave.

Last updated on