| 1 | > **Warning** |
| 2 | > |
| 3 | > ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. |
| 4 | > |
| 5 | > ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/sankey.md](../../packages/mermaid/src/docs/syntax/sankey.md). |
| 6 | |
| 7 | # Sankey diagram (v10.3.0+) |
| 8 | |
| 9 | > A sankey diagram is a visualization used to depict a flow from one set of values to another. |
| 10 | |
| 11 | > **Warning** |
| 12 | > This is an experimental diagram. Its syntax are very close to plain CSV, but it is to be extended in the nearest future. |
| 13 | |
| 14 | The things being connected are called nodes and the connections are called links. |
| 15 | |
| 16 | ## Example |
| 17 | |
| 18 | This example taken from [observable](https://observablehq.com/@d3/sankey/2?collection=@d3/d3-sankey). It may be rendered a little bit differently, though, in terms of size and colors. |
| 19 | |
| 20 | ```mermaid-example |
| 21 | --- |
| 22 | config: |
| 23 | sankey: |
| 24 | showValues: false |
| 25 | --- |
| 26 | sankey |
| 27 | |
| 28 | Agricultural 'waste',Bio-conversion,124.729 |
| 29 | Bio-conversion,Liquid,0.597 |
| 30 | Bio-conversion,Losses,26.862 |
| 31 | Bio-conversion,Solid,280.322 |
| 32 | Bio-conversion,Gas,81.144 |
| 33 | Biofuel imports,Liquid,35 |
| 34 | Biomass imports,Solid,35 |
| 35 | Coal imports,Coal,11.606 |
| 36 | Coal reserves,Coal,63.965 |
| 37 | Coal,Solid,75.571 |
| 38 | District heating,Industry,10.639 |
| 39 | District heating,Heating and cooling - commercial,22.505 |
| 40 | District heating,Heating and cooling - homes,46.184 |
| 41 | Electricity grid,Over generation / exports,104.453 |
| 42 | Electricity grid,Heating and cooling - homes,113.726 |
| 43 | Electricity grid,H2 conversion,27.14 |
| 44 | Electricity grid,Industry,342.165 |
| 45 | Electricity grid,Road transport,37.797 |
| 46 | Electricity grid,Agriculture,4.412 |
| 47 | Electricity grid,Heating and cooling - commercial,40.858 |
| 48 | Electricity grid,Losses,56.691 |
| 49 | Electricity grid,Rail transport,7.863 |
| 50 | Electricity grid,Lighting & appliances - commercial,90.008 |
| 51 | Electricity grid,Lighting & appliances - homes,93.494 |
| 52 | Gas imports,Ngas,40.719 |
| 53 | Gas reserves,Ngas,82.233 |
| 54 | Gas,Heating and cooling - commercial,0.129 |
| 55 | Gas,Losses,1.401 |
| 56 | Gas,Thermal generation,151.891 |
| 57 | Gas,Agriculture,2.096 |
| 58 | Gas,Industry,48.58 |
| 59 | Geothermal,Electricity grid,7.013 |
| 60 | H2 conversion,H2,20.897 |
| 61 | H2 conversion,Losses,6.242 |
| 62 | H2,Road transport,20.897 |
| 63 | Hydro,Electricity grid,6.995 |
| 64 | Liquid,Industry,121.066 |
| 65 | Liquid,International shipping,128.69 |
| 66 | Liquid,Road transport,135.835 |
| 67 | Liquid,Domestic aviation,14.458 |
| 68 | Liquid,International aviation,206.267 |
| 69 | Liquid,Agriculture,3.64 |
| 70 | Liquid,National navigation,33.218 |
| 71 | Liquid,Rail transport,4.413 |
| 72 | Marine algae,Bio-conversion,4.375 |
| 73 | Ngas,Gas,122.952 |
| 74 | Nuclear,Thermal generation,839.978 |
| 75 | Oil imports,Oil,504.287 |
| 76 | Oil reserves,Oil,107.703 |
| 77 | Oil,Liquid,611.99 |
| 78 | Other waste,Solid,56.587 |
| 79 | Other waste,Bio-conversion,77.81 |
| 80 | Pumped heat,Heating and cooling - homes,193.026 |
| 81 | Pumped heat,Heating and cooling - commercial,70.672 |
| 82 | Solar PV,Electricity grid,59.901 |
| 83 | Solar Thermal,Heating and cooling - homes,19.263 |
| 84 | Solar,Solar Thermal,19.263 |
| 85 | Solar,Solar PV,59.901 |
| 86 | Solid,Agriculture,0.882 |
| 87 | Solid,Thermal generation,400.12 |
| 88 | Solid,Industry,46.477 |
| 89 | Thermal generation,Electricity grid,525.531 |
| 90 | Thermal generation,Losses,787.129 |
| 91 | Thermal generation,District heating,79.329 |
| 92 | Tidal,Electricity grid,9.452 |
| 93 | UK land based bioenergy,Bio-conversion,182.01 |
| 94 | Wave,Electricity grid,19.013 |
| 95 | Wind,Electricity grid,289.366 |
| 96 | ``` |
| 97 | |
| 98 | ```mermaid |
| 99 | --- |
| 100 | config: |
| 101 | sankey: |
| 102 | showValues: false |
| 103 | --- |
| 104 | sankey |
| 105 | |
| 106 | Agricultural 'waste',Bio-conversion,124.729 |
| 107 | Bio-conversion,Liquid,0.597 |
| 108 | Bio-conversion,Losses,26.862 |
| 109 | Bio-conversion,Solid,280.322 |
| 110 | Bio-conversion,Gas,81.144 |
| 111 | Biofuel imports,Liquid,35 |
| 112 | Biomass imports,Solid,35 |
| 113 | Coal imports,Coal,11.606 |
| 114 | Coal reserves,Coal,63.965 |
| 115 | Coal,Solid,75.571 |
| 116 | District heating,Industry,10.639 |
| 117 | District heating,Heating and cooling - commercial,22.505 |
| 118 | District heating,Heating and cooling - homes,46.184 |
| 119 | Electricity grid,Over generation / exports,104.453 |
| 120 | Electricity grid,Heating and cooling - homes,113.726 |
| 121 | Electricity grid,H2 conversion,27.14 |
| 122 | Electricity grid,Industry,342.165 |
| 123 | Electricity grid,Road transport,37.797 |
| 124 | Electricity grid,Agriculture,4.412 |
| 125 | Electricity grid,Heating and cooling - commercial,40.858 |
| 126 | Electricity grid,Losses,56.691 |
| 127 | Electricity grid,Rail transport,7.863 |
| 128 | Electricity grid,Lighting & appliances - commercial,90.008 |
| 129 | Electricity grid,Lighting & appliances - homes,93.494 |
| 130 | Gas imports,Ngas,40.719 |
| 131 | Gas reserves,Ngas,82.233 |
| 132 | Gas,Heating and cooling - commercial,0.129 |
| 133 | Gas,Losses,1.401 |
| 134 | Gas,Thermal generation,151.891 |
| 135 | Gas,Agriculture,2.096 |
| 136 | Gas,Industry,48.58 |
| 137 | Geothermal,Electricity grid,7.013 |
| 138 | H2 conversion,H2,20.897 |
| 139 | H2 conversion,Losses,6.242 |
| 140 | H2,Road transport,20.897 |
| 141 | Hydro,Electricity grid,6.995 |
| 142 | Liquid,Industry,121.066 |
| 143 | Liquid,International shipping,128.69 |
| 144 | Liquid,Road transport,135.835 |
| 145 | Liquid,Domestic aviation,14.458 |
| 146 | Liquid,International aviation,206.267 |
| 147 | Liquid,Agriculture,3.64 |
| 148 | Liquid,National navigation,33.218 |
| 149 | Liquid,Rail transport,4.413 |
| 150 | Marine algae,Bio-conversion,4.375 |
| 151 | Ngas,Gas,122.952 |
| 152 | Nuclear,Thermal generation,839.978 |
| 153 | Oil imports,Oil,504.287 |
| 154 | Oil reserves,Oil,107.703 |
| 155 | Oil,Liquid,611.99 |
| 156 | Other waste,Solid,56.587 |
| 157 | Other waste,Bio-conversion,77.81 |
| 158 | Pumped heat,Heating and cooling - homes,193.026 |
| 159 | Pumped heat,Heating and cooling - commercial,70.672 |
| 160 | Solar PV,Electricity grid,59.901 |
| 161 | Solar Thermal,Heating and cooling - homes,19.263 |
| 162 | Solar,Solar Thermal,19.263 |
| 163 | Solar,Solar PV,59.901 |
| 164 | Solid,Agriculture,0.882 |
| 165 | Solid,Thermal generation,400.12 |
| 166 | Solid,Industry,46.477 |
| 167 | Thermal generation,Electricity grid,525.531 |
| 168 | Thermal generation,Losses,787.129 |
| 169 | Thermal generation,District heating,79.329 |
| 170 | Tidal,Electricity grid,9.452 |
| 171 | UK land based bioenergy,Bio-conversion,182.01 |
| 172 | Wave,Electricity grid,19.013 |
| 173 | Wind,Electricity grid,289.366 |
| 174 | ``` |
| 175 | |
| 176 | ## Syntax |
| 177 | |
| 178 | The idea behind syntax is that a user types `sankey` keyword first, then pastes raw CSV below and get the result. |
| 179 | |
| 180 | It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180.txt) with subtle **differences**: |
| 181 | |
| 182 | - CSV must contain **3 columns only** |
| 183 | - It is **allowed** to have **empty lines** without comma separators for visual purposes |
| 184 | |
| 185 | ### Basic |
| 186 | |
| 187 | It is implied that 3 columns inside CSV should represent `source`, `target` and `value` accordingly: |
| 188 | |
| 189 | ```mermaid-example |
| 190 | sankey |
| 191 | |
| 192 | %% source,target,value |
| 193 | Electricity grid,Over generation / exports,104.453 |
| 194 | Electricity grid,Heating and cooling - homes,113.726 |
| 195 | Electricity grid,H2 conversion,27.14 |
| 196 | ``` |
| 197 | |
| 198 | ```mermaid |
| 199 | sankey |
| 200 | |
| 201 | %% source,target,value |
| 202 | Electricity grid,Over generation / exports,104.453 |
| 203 | Electricity grid,Heating and cooling - homes,113.726 |
| 204 | Electricity grid,H2 conversion,27.14 |
| 205 | ``` |
| 206 | |
| 207 | ### Empty Lines |
| 208 | |
| 209 | CSV does not support empty lines without comma delimiters by default. But you can add them if needed: |
| 210 | |
| 211 | ```mermaid-example |
| 212 | sankey |
| 213 | |
| 214 | Bio-conversion,Losses,26.862 |
| 215 | |
| 216 | Bio-conversion,Solid,280.322 |
| 217 | |
| 218 | Bio-conversion,Gas,81.144 |
| 219 | ``` |
| 220 | |
| 221 | ```mermaid |
| 222 | sankey |
| 223 | |
| 224 | Bio-conversion,Losses,26.862 |
| 225 | |
| 226 | Bio-conversion,Solid,280.322 |
| 227 | |
| 228 | Bio-conversion,Gas,81.144 |
| 229 | ``` |
| 230 | |
| 231 | ### Commas |
| 232 | |
| 233 | If you need to have a comma, wrap it in double quotes: |
| 234 | |
| 235 | ```mermaid-example |
| 236 | sankey |
| 237 | |
| 238 | Pumped heat,"Heating and cooling, homes",193.026 |
| 239 | Pumped heat,"Heating and cooling, commercial",70.672 |
| 240 | ``` |
| 241 | |
| 242 | ```mermaid |
| 243 | sankey |
| 244 | |
| 245 | Pumped heat,"Heating and cooling, homes",193.026 |
| 246 | Pumped heat,"Heating and cooling, commercial",70.672 |
| 247 | ``` |
| 248 | |
| 249 | ### Double Quotes |
| 250 | |
| 251 | If you need to have double quote, put a pair of them inside quoted string: |
| 252 | |
| 253 | ```mermaid-example |
| 254 | sankey |
| 255 | |
| 256 | Pumped heat,"Heating and cooling, ""homes""",193.026 |
| 257 | Pumped heat,"Heating and cooling, ""commercial""",70.672 |
| 258 | ``` |
| 259 | |
| 260 | ```mermaid |
| 261 | sankey |
| 262 | |
| 263 | Pumped heat,"Heating and cooling, ""homes""",193.026 |
| 264 | Pumped heat,"Heating and cooling, ""commercial""",70.672 |
| 265 | ``` |
| 266 | |
| 267 | ## Configuration |
| 268 | |
| 269 | You can customize link colors, node alignments and diagram dimensions. |
| 270 | |
| 271 | ```html |
| 272 | <script> |
| 273 | const config = { |
| 274 | startOnLoad: true, |
| 275 | securityLevel: 'loose', |
| 276 | sankey: { |
| 277 | width: 800, |
| 278 | height: 400, |
| 279 | linkColor: 'source', |
| 280 | nodeAlignment: 'left', |
| 281 | }, |
| 282 | }; |
| 283 | mermaid.initialize(config); |
| 284 | </script> |
| 285 | ``` |
| 286 | |
| 287 | ### Links Coloring |
| 288 | |
| 289 | You can adjust links' color by setting `linkColor` to one of those: |
| 290 | |
| 291 | - `source` - link will be of a source node color |
| 292 | - `target` - link will be of a target node color |
| 293 | - `gradient` - link color will be smoothly transient between source and target node colors |
| 294 | - hex code of color, like `#a1a1a1` |
| 295 | |
| 296 | ### Node Alignment |
| 297 | |
| 298 | Graph layout can be changed by setting `nodeAlignment` to: |
| 299 | |
| 300 | - `justify` |
| 301 | - `center` |
| 302 | - `left` |
| 303 | - `right` |
| 304 | |
| 305 | <!--- cspell:ignore Ngas bioenergy biofuel ---> |
| 306 | |