Skip to content

Commit

Permalink
Fix sankey.linkSort when non-null.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Sep 2, 2019
1 parent fe20872 commit 7817fbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ For convenience, a link’s source and target may be initialized using numeric o
* *link*.width - the link’s width (proportional to *link*.value)
* *link*.index - the zero-based index of *link* within the array of links

<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")

If *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.

<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")

If *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:
Expand Down
6 changes: 6 additions & 0 deletions src/sankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ export default function Sankey() {
source.sourceLinks.push(link);
target.targetLinks.push(link);
}
if (linkSort != null) {
for (const {sourceLinks, targetLinks} of nodes) {
sourceLinks.sort(linkSort);
targetLinks.sort(linkSort);
}
}
}

function computeNodeValues({nodes}) {
Expand Down

0 comments on commit 7817fbb

Please sign in to comment.