Gallery / Stages, flows and plans /
Sankey
Volume flowing between stages (product to channel to customer).
57.1 KB of code · core 29.5 + 6 blocks 27.6
From crude oil to the customer, million barrels
Of 1,000 million barrels of crude oil, 420 become gasoline; retail stations sell 490, most of it to drivers.
How it is made: One row per flow. transform.sankey lays the flows out: the columns come from the flows, so it needs no scales and no axes. mark.sankey draws them, and every node is named on the chart.
What the report is made of
The composer reads the JSON below and puts into the page the core and only the blocks its chart uses: 6 of the 59, 57.1 KB of code, minified, which is 26% of the 215.9 KB that the core and every block weigh together. The report file is 63.7 KB: that code, the data, the styles and the page around them.
| Block | What it does | Share of the code | KB |
|---|---|---|---|
core.composed-plain A report with plain data: no checks, no decoder. Most reports. | A report with plain data: no checks, no decoder. Most reports. | 29.5 | |
lib.columns Checks the columns a transform reads and writes. Shared by contour, funnel, hexbin, sankey, treemap and waterfall. | Checks the columns a transform reads and writes. Shared by contour, funnel, hexbin, sankey, treemap and waterfall. | 0.6 | |
lib.pointer Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush. | Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush. | 1.7 | |
transform.sankey Lays out a Sankey: the columns and order of the nodes, and where each flow runs. | Lays out a Sankey: the columns and order of the nodes, and where each flow runs. | 4.1 | |
mark.sankey Flows between stages, as ribbons, where transform.sankey puts them. | Flows between stages, as ribbons, where transform.sankey puts them. | 6.6 | |
interaction.tooltip The values under the pointer. | The values under the pointer. | 10.7 | |
renderer.svg Draws into SVG: sharp, selectable, prints well. The default. | Draws into SVG: sharp, selectable, prints well. The default. | 3.9 | |
| Total | The core 29.5 and 6 blocks 27.6 | 57.1 |
The JSON
This is the whole input. data holds the datasets, each chart is a spec that names one.
In a checkout of the repository: node scripts/compose.js skills/blockcharts/recipes/sankey.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
sankey.json
{
"title": "Sankey",
"data": {
"flows": [
{ "from": "Crude oil", "to": "Gasoline", "volume": 420 },
{ "from": "Crude oil", "to": "Diesel", "volume": 310 },
{ "from": "Crude oil", "to": "Jet fuel", "volume": 120 },
{ "from": "Crude oil", "to": "Other products", "volume": 150 },
{ "from": "Gasoline", "to": "Retail stations", "volume": 360 },
{ "from": "Gasoline", "to": "Wholesale", "volume": 60 },
{ "from": "Diesel", "to": "Retail stations", "volume": 130 },
{ "from": "Diesel", "to": "Wholesale", "volume": 180 },
{ "from": "Jet fuel", "to": "Airlines", "volume": 120 },
{ "from": "Other products", "to": "Wholesale", "volume": 90 },
{ "from": "Other products", "to": "Industry", "volume": 60 },
{ "from": "Retail stations", "to": "Drivers", "volume": 400 },
{ "from": "Retail stations", "to": "Fleets", "volume": 90 },
{ "from": "Wholesale", "to": "Fleets", "volume": 210 },
{ "from": "Wholesale", "to": "Industry", "volume": 120 }
]
},
"charts": [
{
"title": "From crude oil to the customer, million barrels",
"note": "Of 1,000 million barrels of crude oil, 420 become gasoline; retail stations sell 490, most of it to drivers.",
"how": "One row per flow. transform.sankey lays the flows out: the columns come from the flows, so it needs no scales and no axes. mark.sankey draws them, and every node is named on the chart.",
"spec": {
"data": "flows",
"size": [720, 400],
"padding": { "top": 8, "right": 8, "bottom": 8, "left": 8 },
"transforms": [{ "type": "sankey", "source": "from", "target": "to", "value": "volume" }],
"marks": [{ "type": "sankey", "source": "from", "target": "to", "value": "volume", "format": "integer" }],
"interaction": [{ "type": "tooltip", "fields": ["from", "to", "volume"], "labels": { "from": "From", "to": "To", "volume": "Million barrels" } }]
}
}
]
}
The report the composer makes from it is one standalone file (63.7 KB): open it from disk, mail it, print it.
In a page of your own
The charts above use the full kit (81.8 KB gzipped), the smallest one that has the blocks this example needs:
lib.columns, lib.pointer, transform.sankey, mark.sankey, interaction.tooltip, renderer.svg.
The HTML below loads it from the jsDelivr CDN, pinned to version 0.0.5; to serve it from your own site, put its file there
(the files of a release) and change the address.
HTML
<script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.5/release/kits/full.js"></script>
<script type="application/json" id="bc-data">
{"flows":[{"from":"Crude oil","to":"Gasoline","volume":420},{"from":"Crude oil","to":"Diesel","volume":310},{"from":"Crude oil","to":"Jet fuel","volume":120},{"from":"Crude oil","to":"Other products","volume":150},{"from":"Gasoline","to":"Retail stations","volume":360},{"from":"Gasoline","to":"Wholesale","volume":60},{"from":"Diesel","to":"Retail stations","volume":130},{"from":"Diesel","to":"Wholesale","volume":180},{"from":"Jet fuel","to":"Airlines","volume":120},{"from":"Other products","to":"Wholesale","volume":90},{"from":"Other products","to":"Industry","volume":60},{"from":"Retail stations","to":"Drivers","volume":400},{"from":"Retail stations","to":"Fleets","volume":90},{"from":"Wholesale","to":"Fleets","volume":210},{"from":"Wholesale","to":"Industry","volume":120}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "flows",
"size": [
720,
400
],
"padding": {
"top": 8,
"right": 8,
"bottom": 8,
"left": 8
},
"transforms": [
{
"type": "sankey",
"source": "from",
"target": "to",
"value": "volume"
}
],
"marks": [
{
"type": "sankey",
"source": "from",
"target": "to",
"value": "volume",
"format": "integer"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"from",
"to",
"volume"
],
"labels": {
"from": "From",
"to": "To",
"volume": "Million barrels"
}
}
],
"alt": "From crude oil to the customer, million barrels"
}
</script>