diff --git a/README.md b/README.md
index 24dda12..6f2f08a 100644
--- a/README.md
+++ b/README.md
@@ -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
+# sankey.linkSort([sort]) [<>](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.
+
# sankey.nodeId([id]) [<>](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:
diff --git a/src/sankey.js b/src/sankey.js
index ae7cae4..56ad642 100644
--- a/src/sankey.js
+++ b/src/sankey.js
@@ -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}) {