Archived

Documentation for Layer Cake v10, before Svelte 5 runes. Current docs at layercake.graphics

Menu

Sankey

A Sankey diagram using d3-sankey. The data is an object with nodes and links arrays, which is what the layout takes. The component exposes the layout's options as props, along with accessor functions for the colors.

<script>
  import { LayerCake, Svg } from 'layercake';

  import Sankey from './_components/Sankey.svelte';

  // An object with `nodes` and `links` arrays, the shape d3-sankey takes
  import data from './_data/sankey-data.js';
</script>

<div class="chart-container">
  <LayerCake {data}>
    <Svg>
      <Sankey getNodeFill={() => '#00bbff'} getLinkStroke={() => '#00bbff35'} />
    </Svg>
  </LayerCake>
</div>

<style>
  /* Give the wrapper a width and height. LayerCake fills it. */
  .chart-container {
    width: 100%;
    height: 250px;
  }
</style>