{"name":"d3-sankey","version":"0.1.2","description":"D3 4.0 implementation of the Sankey plugin","keywords":["d3","sankey"],"license":"BSD-3-Clause","main":"build/d3-sankey.js","jsnext:main":"index","homepage":"https://github.com/xaranke/d3-sankey","repository":{"type":"git","url":"git+https://github.com/xaranke/d3-sankey.git"},"scripts":{"pretest":"mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -g d3-arrays:d3_arrays -u d3-sankey -n d3_sankey -o build/d3-sankey.js -- build/bundle.js","test":"faucet `find test -name '*-test.js'`","prepublish":"npm run test && uglifyjs build/d3-sankey.js -c -m -o build/d3-sankey.min.js && rm -f build/d3-sankey.zip && zip -j build/d3-sankey.zip -- LICENSE README.md build/d3-sankey.js build/d3-sankey.min.js"},"devDependencies":{"faucet":"^0.0.1","rollup":"^0.21.1","tape":"^4.2.2","uglify-js":"^2.6.1"},"dependencies":{"d3-arrays":"^0.4.0","d3-interpolate":"^0.2.0"},"gitHead":"63fccc1b0ad0b91fe2334cc19eb1d8eeea0a7c20","bugs":{"url":"https://github.com/xaranke/d3-sankey/issues"},"_id":"d3-sankey@0.1.2","_shasum":"d8392b9164b95eb99f2c153b2c0c89c055d7a6c4","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.0","_npmUser":{"name":"xaranke","email":"kshitij.aranke@gmail.com"},"dist":{"shasum":"d8392b9164b95eb99f2c153b2c0c89c055d7a6c4","tarball":"http://registry-npm.ywwl.com/d3-sankey/download/d3-sankey-0.1.2.tgz","integrity":"sha512-6K/IsvBsQ48tMyyv9QcvgN3I3gwbYb7wHXMxBtFlm8BbPEA8ZjUJQGLmZPuJvvE8UW9/wRgerL/OFby0JyutiQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqx9rYSpjP6WNqQ2zSpH6qx7sU5CWLJSbpBLYMcUeMdwIhAPyUDzsdSO5DoryQYRkAkZIWWmoWLTVg4ong5jX7gG+k"}],"size":6373,"noattachment":false,"key":"/d3-sankey/-/d3-sankey-0.1.2.tgz"},"maintainers":[{"name":"xaranke","email":"kshitij.aranke@gmail.com"}],"directories":{},"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://observablehq.com/@d3/sankey-diagram)\n\nSource: Department of Energy & Climate Change, Tom Counsell.\n\n**For an interactive editor, see [Flow-o-Matic](https://observablehq.com/@mbostock/flow-o-matic).**\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@1\"></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 \"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 \"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 \"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 \"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; this is the sum of *link*.value for the node’s incoming [links](#sankey_links), or *node*.fixedValue if defined\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*.layer - the node’s zero-based column index, corresponding to its horizontal position\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 \"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_linkSort\" href=\"#sankey_linkSort\">#</a> <i>sankey</i>.<b>linkSort</b>([<i>sort</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js \"Source\")\n\nIf *sort* is specified, sets the link sort method and returns this Sankey generator. If *sort* is not specified, returns the current link sort method, which defaults to *undefined*, indicating that vertical order of links within each node 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 links, and must return a value less than 0 if the first link should be above the second, and a value greater than 0 if the second link should be above the first, or 0 if the order is not specified.\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 \"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 \"Source\")\n\nIf *align* is specified, sets the node [alignment method](#alignments) to 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_nodeSort\" href=\"#sankey_nodeSort\">#</a> <i>sankey</i>.<b>nodeSort</b>([<i>sort</i>]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js \"Source\")\n\nIf *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.\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 \"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 \"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 \"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 \"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 \"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 6.\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 \"Source\")\n\n[<img alt=\"left\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/align-left.png\" width=\"480\">](https://observablehq.com/@d3/sankey-diagram?align=left)\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 \"Source\")\n\n[<img alt=\"right\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/align-right.png\" width=\"480\">](https://observablehq.com/@d3/sankey-diagram?align=right)\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 \"Source\")\n\n[<img alt=\"center\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/align-center.png\" width=\"480\">](https://observablehq.com/@d3/sankey-diagram?align=center)\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 \"Source\")\n\n[<img alt=\"justify\" src=\"https://raw.githubusercontent.com/d3/d3-sankey/master/img/energy.png\" width=\"480\">](https://observablehq.com/@d3/sankey-diagram)\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  .join(\"path\")\n    .attr(\"d\", d3.sankeyLinkHorizontal())\n    .attr(\"stroke-width\", function(d) { return d.width; });\n```\n","publish_time":1449159222774,"_cnpm_publish_time":1449159222774,"dist-tags":{"latest":"0.12.3"}}