{"_id":"@adam.tajti/d3-sankey","name":"@adam.tajti/d3-sankey","dist-tags":{"latest":"0.7.4"},"versions":{"0.7.4":{"name":"@adam.tajti/d3-sankey","version":"0.7.4","description":"Visualize flow between nodes in a directed acyclic network.","keywords":["d3","d3-module","sankey"],"author":{"name":"Mike Bostock","url":"https://bost.ocks.org/mike/"},"license":"BSD-3-Clause","main":"build/d3-sankey.js","module":"index","jsnext:main":"index","homepage":"https://github.com/plotly/d3-sankey","repository":{"type":"git","url":"git+https://github.com/plotly/d3-sankey.git"},"type":"module","scripts":{"pretest":"rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -g d3-array:d3,d3-collection:d3,d3-shape:d3 -f es -n d3 -o build/d3-sankey.js -- index.js","test":"tape 'test/**/*-test.js' && eslint index.js src","prepublish":"npm run test && uglifyjs -b beautify=false,preamble=\"'$(preamble)'\" build/d3-sankey.js -c -m -o build/d3-sankey.min.js","postpublish":"git push && git push --tags && zip -j build/d3-sankey.zip -- LICENSE README.md build/d3-sankey.js build/d3-sankey.min.js"},"dependencies":{"d3-array":"^3.2.0","d3-collection":"^1.0.7","d3-shape":"^3.1.0"},"devDependencies":{"eslint":"4","package-preamble":"0.1.0","rollup":"0.43","tape":"^5.6.1","tape-async":"^2.3.0","uglify-js":"3"},"gitHead":"3e1cd06519d38ca51ee28a364cf851c210aeb91e","bugs":{"url":"https://github.com/plotly/d3-sankey/issues"},"_id":"@adam.tajti/d3-sankey@0.7.4","_nodeVersion":"14.19.3","_npmVersion":"8.19.2","dist":{"integrity":"sha512-wYzInN482oigD7aWRjxH/lcfhlS/at9CIdJbDqm6CJmVOl5kwRtdUTMGZ7thsAfBukKE/ZCW9Eqcc1icr34p7Q==","shasum":"1d0a3dbde57646dac0ac027a1eb8fce6b33dc579","tarball":"https://registry.npmjs.org/@adam.tajti/d3-sankey/-/d3-sankey-0.7.4.tgz","fileCount":14,"unpackedSize":817143,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDTll55HbbYgII+QZccHMKrkuMj2O4uxibVsCobZwIWhwIhAMDurTusHFDDR8P2ixbmlfmLq7+um140SGriDdzhl0lW"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjaaOTACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoN0hAAl4+ktEHqL2DX5GvM6bb0CcDE0jty0nKrTNehYIZP9FCu50ro\r\nhbknzzJgsSixZdfMbq9PmTp3Pd/vqEEgwQmGbYIX7DRVSvpjuPma/QAXgN0v\r\nsfEyM/biNdRF+koREre9aEdT6McbNFeYI/GNNg40TlxiblZQEqvd2vh/2qZ/\r\nSIybVxAttk5iCkv9KPCp/ahuuchi33pHOgBklIKLPX2X6wysSWpGDOJEq+/X\r\nBz8ckaQSwU34wjTJK7rv4GU14lwuY4zj/PugxEpHS/OGbXRUIay4sc81rr4W\r\nsjWCdH0bDX6wQoYEDD5PTDvDJOdNSu6/x/eszFiBcKIXbWYL2ybR4NnKa2Bq\r\n280yt2EUxNCH3e5gJp8YEjfbGN1HvQS+JfEO89LZUv9K2yQxLY8Z0Cw59FLV\r\niQehaXXBCSk4n0HtaFzYuLRlDJv/EqV7M5i5pAJ/bmCA8M/BJJq1buHCDsv2\r\n+D3Odqrq12jsCFD+6fqK4ZZNp+TUsKjsNbvX5qKujEBDkpvYuD/+DDcXzVqq\r\nPaJoFJ6al+3xn8aRtKKj7ox7yjUfZ9BCuNCzTqjsQxAvGz5hsaf9MpI0x/SX\r\nKGas4SU4t6NLiI4QPJjKZ6P1f0WYEKVR6fvCeHkYI5mEejHIi1SS2ZM0n9+t\r\nMxH2koN3wyaGrL5wk+YBUmnyAQfoHXsx5pg=\r\n=6mr7\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"adam.tajti","email":"adam.tajti@gmail.com"},"directories":{},"maintainers":[{"name":"adam.tajti","email":"adam.tajti@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/d3-sankey_0.7.4_1667867539376_0.7216642910096922"},"_hasShrinkwrap":false}},"time":{"created":"2022-11-08T00:32:19.322Z","0.7.4":"2022-11-08T00:32:19.582Z","modified":"2022-11-08T00:32:19.696Z"},"maintainers":[{"name":"adam.tajti","email":"adam.tajti@gmail.com"}],"description":"Visualize flow between nodes in a directed acyclic network.","homepage":"https://github.com/plotly/d3-sankey","keywords":["d3","d3-module","sankey"],"repository":{"type":"git","url":"git+https://github.com/plotly/d3-sankey.git"},"author":{"name":"Mike Bostock","url":"https://bost.ocks.org/mike/"},"bugs":{"url":"https://github.com/plotly/d3-sankey/issues"},"license":"BSD-3-Clause","readme":"# d3-sankey\n\nSankey diagrams visualize the directed flow between nodes in an acyclic network. For example, this diagram shows a possible scenario of UK energy production and consumption in 2050:\n\n[<img alt=\"Sankey diagram\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/energy.png\" width=\"960\">](https://bl.ocks.org/mbostock/ca9a0bb7ba204d12974bca90acc507c0)\n\nSource: Department of Energy & Climate Change, Tom Counsell.\n\n## Installing\n\nIf you use NPM, `npm install d3-sankey`. Otherwise, download the [latest release](https://github.com/d3/d3-sankey/releases/latest). You can also load directly from [unpkg.com](https://unpkg.com/d3-sankey/). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:\n\n```html\n<script src=\"https://unpkg.com/d3-array@3.2.0\"></script>\n<script src=\"https://unpkg.com/d3-collection@1\"></script>\n<script src=\"https://unpkg.com/d3-path@1\"></script>\n<script src=\"https://unpkg.com/d3-shape@1\"></script>\n<script src=\"https://unpkg.com/d3-sankey@0\"></script>\n<script>\n\nvar sankey = d3.sankey();\n\n</script>\n```\n\n## API Reference\n\n<a href=\"#sankey\" name=\"sankey\">#</a> d3.<b>sankey</b>() [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L52 \"Source\")\n\nConstructs a new Sankey generator with the default settings.\n\n<a href=\"#_sankey\" name=\"_sankey\">#</a> <i>sankey</i>(<i>arguments</i>…) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L62 \"Source\")\n\nComputes the node and link positions for the given *arguments*, returning a *graph* representing the Sankey layout. The returned *graph* has the following properties:\n\n* *graph*.nodes - the array of [nodes](#sankey_nodes)\n* *graph*.links - the array of [links](#sankey_links)\n\n<a href=\"#sankey_update\" name=\"sankey_update\">#</a> <i>sankey</i>.<b>update</b>(<i>graph</i>) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L72 \"Source\")\n\nRecomputes the specified *graph*’s links’ positions, updating the following properties of each *link*:\n\n* *link*.y0 - the link’s vertical starting position (at source node)\n* *link*.y1 - the link’s vertical end position (at target node)\n\nThis method is intended to be called after computing the initial [Sankey layout](#_sankey), for example when the diagram is repositioned interactively.\n\n<a name=\"sankey_nodes\" href=\"#sankey_nodes\">#</a> <i>sankey</i>.<b>nodes</b>([<i>nodes</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L93 \"Source\")\n\nIf *nodes* is specified, sets the Sankey generator’s nodes accessor to the specified function or array and returns this Sankey generator. If *nodes* is not specified, returns the current nodes accessor, which defaults to:\n\n```js\nfunction nodes(graph) {\n  return graph.nodes;\n}\n```\n\nIf *nodes* is specified as a function, the function is invoked when the Sankey layout is [generated](#_sankey), being passed any arguments passed to the Sankey generator. This function must return an array of nodes. If *nodes* is not a function, it must be a constant array of *nodes*.\n\nEach *node* must be an object. The following properties are assigned by the [Sankey generator](#_sankey):\n\n* *node*.sourceLinks - the array of outgoing [links](#sankey_links) which have this node as their source\n* *node*.targetLinks - the array of incoming [links](#sankey_links) which have this node as their target\n* *node*.value - the node’s value; the sum of *link*.value for the node’s incoming [links](#sankey_links)\n* *node*.index - the node’s zero-based index within the array of nodes\n* *node*.depth - the node’s zero-based graph depth, derived from the graph topology\n* *node*.height - the node’s zero-based graph height, derived from the graph topology\n* *node*.x0 - the node’s minimum horizontal position, derived from *node*.depth\n* *node*.x1 - the node’s maximum horizontal position (*node*.x0 + [*sankey*.nodeWidth](#sankey_nodeWidth))\n* *node*.y0 - the node’s minimum vertical position\n* *node*.y1 - the node’s maximum vertical position (*node*.y1 - *node*.y0 is proportional to *node*.value)\n\nSee also [*sankey*.links](#sankey_links).\n\n<a name=\"sankey_links\" href=\"#sankey_links\">#</a> <i>sankey</i>.<b>links</b>([<i>links</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L97 \"Source\")\n\nIf *links* is specified, sets the Sankey generator’s links accessor to the specified function or array and returns this Sankey generator. If *links* is not specified, returns the current links accessor, which defaults to:\n\n```js\nfunction links(graph) {\n  return graph.links;\n}\n```\n\nIf *links* is specified as a function, the function is invoked when the Sankey layout is [generated](#_sankey), being passed any arguments passed to the Sankey generator. This function must return an array of links. If *links* is not a function, it must be a constant array of *links*.\n\nEach *link* must be an object with the following properties:\n\n* *link*.source - the link’s source [node](#sankey_nodes)\n* *link*.target - the link’s target [node](#sankey_nodes)\n* *link*.value - the link’s numeric value\n\nFor convenience, a link’s source and target may be initialized using numeric or string identifiers rather than object references; see [*sankey*.nodeId](#sankey_nodeId). The following properties are assigned to each link by the [Sankey generator](#_sankey):\n\n* *link*.y0 - the link’s vertical starting position (at source node)\n* *link*.y1 - the link’s vertical end position (at target node)\n* *link*.width - the link’s width (proportional to *link*.value)\n* *link*.index - the zero-based index of *link* within the array of links\n\n<a name=\"sankey_nodeId\" href=\"#sankey_nodeId\">#</a> <i>sankey</i>.<b>nodeId</b>([<i>id</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L77 \"Source\")\n\nIf *id* is specified, sets the node id accessor to the specified function and returns this Sankey generator. If *id* is not specified, returns the current node id accessor, which defaults to the numeric *node*.index:\n\n```js\nfunction id(d) {\n  return d.index;\n}\n```\n\nThe default id accessor allows each link’s source and target to be specified as a zero-based index into the [nodes](#sankey_nodes) array. For example:\n\n```js\nvar nodes = [\n  {\"id\": \"Alice\"},\n  {\"id\": \"Bob\"},\n  {\"id\": \"Carol\"}\n];\n\nvar links = [\n  {\"source\": 0, \"target\": 1}, // Alice → Bob\n  {\"source\": 1, \"target\": 2} // Bob → Carol\n];\n```\n\nNow consider a different id accessor that returns a string:\n\n```js\nfunction id(d) {\n  return d.id;\n}\n```\n\nWith this accessor, you can use named sources and targets:\n\n```js\nvar nodes = [\n  {\"id\": \"Alice\"},\n  {\"id\": \"Bob\"},\n  {\"id\": \"Carol\"}\n];\n\nvar links = [\n  {\"source\": \"Alice\", \"target\": \"Bob\"},\n  {\"source\": \"Bob\", \"target\": \"Carol\"}\n];\n```\n\nThis is particularly useful when representing graphs in JSON, as JSON does not allow references. See [this example](https://bl.ocks.org/mbostock/f584aa36df54c451c94a9d0798caed35).\n\n<a name=\"sankey_nodeAlign\" href=\"#sankey_nodeAlign\">#</a> <i>sankey</i>.<b>nodeAlign</b>([<i>align</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L81 \"Source\")\n\nIf *align* is specified, sets the node [alignment method](#alignments) the specified function and returns this Sankey generator. If *align* is not specified, returns the current node alignment method, which defaults to [d3.sankeyJustify](#sankeyJustify). The specified function is evaluated for each input *node* in order, being passed the current *node* and the total depth *n* of the graph (one plus the maximum *node*.depth), and must return an integer between 0 and *n* - 1 that indicates the desired horizontal position of the node in the generated Sankey diagram.\n\n<a name=\"sankey_nodeWidth\" href=\"#sankey_nodeWidth\">#</a> <i>sankey</i>.<b>nodeWidth</b>([<i>width</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L85 \"Source\")\n\nIf *width* is specified, sets the node width to the specified number and returns this Sankey generator. If *width* is not specified, returns the current node width, which defaults to 24.\n\n<a name=\"sankey_nodePadding\" href=\"#sankey_nodePadding\">#</a> <i>sankey</i>.<b>nodePadding</b>([<i>padding</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L89 \"Source\")\n\nIf *padding* is specified, sets the vertical separation between nodes at each column to the specified number and returns this Sankey generator. If *padding* is not specified, returns the current node padding, which defaults to 8.\n\n<a name=\"sankey_extent\" href=\"#sankey_extent\">#</a> <i>sankey</i>.<b>extent</b>([<i>extent</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L105 \"Source\")\n\nIf *extent* is specified, sets the extent of the Sankey layout to the specified bounds and returns the layout. The *extent* bounds are specified as an array \\[\\[<i>x0</i>, <i>y0</i>\\], \\[<i>x1</i>, <i>y1</i>\\]\\], where *x0* is the left side of the extent, *y0* is the top, *x1* is the right and *y1* is the bottom. If *extent* is not specified, returns the current extent which defaults to [[0, 0], [1, 1]].\n\n<a name=\"sankey_size\" href=\"#sankey_size\">#</a> <i>sankey</i>.<b>size</b>([<i>size</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L101 \"Source\")\n\nAn alias for [*sankey*.extent](#sankey_extent) where the minimum *x* and *y* of the extent are ⟨0,0⟩. Equivalent to:\n\n```js\nsankey.extent([[0, 0], size]);\n```\n\n<a name=\"sankey_iterations\" href=\"#sankey_iterations\">#</a> <i>sankey</i>.<b>iterations</b>([<i>iterations</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L109 \"Source\")\n\nIf *iterations* is specified, sets the number of relaxation iterations when [generating the layout](#_sankey) and returns this Sankey generator. If *iterations* is not specified, returns the current number of relaxation iterations, which defaults to 32.\n\n### Alignments\n\nSee [*sankey*.nodeAlign](#sankey_nodeAlign).\n\n<a name=\"sankeyLeft\" href=\"#sankeyLeft\">#</a> d3.<b>sankeyLeft</b>(<i>node</i>, <i>n</i>) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L7 \"Source\")\n\n<img alt=\"left\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/align-left.png\" width=\"480\">\n\nReturns *node*.depth.\n\n<a name=\"sankeyRight\" href=\"#sankeyRight\">#</a> d3.<b>sankeyRight</b>(<i>node</i>, <i>n</i>) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L11 \"Source\")\n\n<img alt=\"right\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/align-right.png\" width=\"480\">\n\nReturns *n* - 1 - *node*.height.\n\n<a name=\"sankeyCenter\" href=\"#sankeyCenter\">#</a> d3.<b>sankeyCenter</b>(<i>node</i>, <i>n</i>) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L19 \"Source\")\n\n<img alt=\"center\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/align-center.png\" width=\"480\">\n\nLike [d3.sankeyLeft](#sankeyLeft), except that nodes without any incoming links are moved as right as possible.\n\n<a name=\"sankeyJustify\" href=\"#sankeyJustify\">#</a> d3.<b>sankeyJustify</b>(<i>node</i>, <i>n</i>) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L15 \"Source\")\n\n<img alt=\"justify\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/energy.png\" width=\"480\">\n\nLike [d3.sankeyLeft](#sankeyLeft), except that nodes without any outgoing links are moved to the far right.\n\n### Links\n\n<a name=\"sankeyLinkHorizontal\" href=\"#sankeyLinkHorizontal\">#</a> d3.<b>sankeyLinkHorizontal</b>() [<>](https://github.com/d3/d3-sankey/blob/master/src/sankeyLinkHorizontal.js \"Source\")\n\nReturns a [horizontal link shape](https://github.com/d3/d3-shape/blob/master/README.md#linkHorizontal) suitable for a Sankey diagram. The [source accessor](https://github.com/d3/d3-shape/blob/master/README.md#link_source) is defined as:\n\n```js\nfunction source(d) {\n  return [d.source.x1, d.y0];\n}\n```\n\nThe [target accessor](https://github.com/d3/d3-shape/blob/master/README.md#link_target) is defined as:\n\n```js\nfunction target(d) {\n  return [d.target.x0, d.y1];\n}\n```\n\nFor example, to render the links of a Sankey diagram in SVG, you might say:\n\n```js\nsvg.append(\"g\")\n    .attr(\"fill\", \"none\")\n    .attr(\"stroke\", \"#000\")\n    .attr(\"stroke-opacity\", 0.2)\n  .selectAll(\"path\")\n  .data(graph.links)\n  .enter().append(\"path\")\n    .attr(\"d\", d3.sankeyLinkHorizontal())\n    .attr(\"stroke-width\", function(d) { return d.width; });\n```\n","readmeFilename":"README.md"}