GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Allow fixing the vertical order of Sankey links, nodes by adamreeve · Pull Request #7873 · plotly/plotly.js

Conversation

@adamreeve

@adamreeve adamreeve commented Jun 28, 2026 •
edited by camdecoster
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #4373

Follow up to #7830

This exposes the nodeSort method added to d3-sankey, to allow disabling the default ordering algorithm and enforcing that the vertical order should match the order of nodes in the input data.

Note that the nodeSort method in d3-sankey can be a method that compared two nodes (see the docs), but for many users I think just providing a way to pass null instead of the default undefined is sufficient. But maybe this could be future-proofed somehow to support using a comparison method in future? Although I'm not sure how feasible it is to make that work in plotly.

The nodeSort option is not supported by d3-sankey-circular, so is not used for circular Sankey diagrams (see #7689 (comment) for more context).

EDIT (by @camdecoster): I added the corresponding sort option for links as well. Everything that @adamreeve said above is true for this attribute (linkSort) as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
adamreeve added 3 commits June 28, 2026 21:27
@adamreeve
Plumb in Sankey nodeSort
f6625b3
@adamreeve
Regenerate schema
3a9a834
@adamreeve
Add test mocks for sankey sort options
599fa94
@adamreeve
adamreeve force-pushed the sankey-order branch from 23564a7 to 153182a Compare June 29, 2026 01:19
@adamreeve
Only call nodeSort for non-circular Sankey
9dd5fa9
@adamreeve
adamreeve force-pushed the sankey-order branch from 153182a to 9dd5fa9 Compare June 29, 2026 01:30
@adamreeve
Add draftlog entry
ff49808
@adamreeve
adamreeve marked this pull request as ready for review June 29, 2026 02:16
camdecoster
camdecoster requested changes Jul 13, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems great. I've requested a few small changes. What do you think of adding support for link sort?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/traces/sankey/render.js Outdated
right: d3Sankey.sankeyRight,
center: d3Sankey.sankeyCenter
}[trace.node.align];
var input_sort = trace.node.sort === 'input';

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var input_sort = trace.node.sort === 'input';
const inputNodeSort = trace.node.sort === 'input';

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/traces/sankey/render.js Outdated
Comment on lines +52 to +55
if(circular && input_sort) {
Lib.error('Circular Sankey diagrams do not support the "input" node.sort mode; falling back to the default sort.');
}

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(circular && input_sort) {
Lib.error('Circular Sankey diagrams do not support the "input" node.sort mode; falling back to the default sort.');
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/traces/sankey/render.js
// d3-sankey-circular does not support the nodeSort method
if(!circular) {
sankey.nodeSort(input_sort ? null : undefined);
}

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
if (inputNodeSort) {
if (circular) {
Lib.warn('Circular Sankey diagrams do not support the "input" node.sort mode; falling back to the default sort.');
} else {
// Passing null keeps nodes in their input order
sankey.nodeSort(null);
}
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/traces/sankey/attributes.js Outdated
Comment on lines +178 to +180
'If the value is `auto` (the default), the vertical order of nodes will be determined automatically',
'by the layout.',
'If the value is `input`, the vertical order is kept the same as the order in the input node array'

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'If the value is `auto` (the default), the vertical order of nodes will be determined automatically',
'by the layout.',
'If the value is `input`, the vertical order is kept the same as the order in the input node array'
'For `auto` (the default), the vertical order of nodes will be determined automatically by the layout.',
'For `input`, the vertical order of nodes is kept the same as the order in the input array.'

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/image/mocks/sankey_auto_sort.json Outdated

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mock can be deleted since all of the other sankey mocks use the auto sort.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/image/mocks/sankey_input_sort.json Outdated
}
],
"layout": {
"title": { "text": "Sankey with fixed vertical node ordering" },

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": { "text": "Sankey with fixed vertical node ordering" },
"title": { "text": "Sankey with vertical node ordering matching the input array" },

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/jasmine/tests/sankey_test.js Outdated
Comment on lines +505 to +508
var errors = [];
spyOn(Lib, 'error').and.callFake(function (msg) {
errors.push(msg);
});

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var errors = [];
spyOn(Lib, 'error').and.callFake(function (msg) {
errors.push(msg);
});
var warnings = [];
spyOn(Lib, 'warn').and.callFake(function (msg) {
warnings.push(msg);
});

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/jasmine/tests/sankey_test.js Outdated
expect(d3SelectAll('.sankey .node-rect').size()).toBeGreaterThan(0);

// An error is logged about the fallback
expect(errors.length).toBe(1);

@camdecoster camdecoster Jul 10, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(errors.length).toBe(1);
expect(warnings.length).toBe(1);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster

camdecoster commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

FYI, we're tying to get an RC of v4.0 out this week, so I'm going to jump in and make some changes. I'd rather let you finish things up, but schedules, right? Your work has been very helpful and appreciated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

camdecoster added 4 commits July 20, 2026 11:59
@camdecoster
Address PR feedback
8b66e13
@camdecoster
Add link sort attribute
0885901
@camdecoster
Update draftlog
87f1387
@camdecoster
Update schema and types
3e126db
camdecoster
camdecoster approved these changes Jul 20, 2026
View reviewed changes
@camdecoster camdecoster added this to the v4.0.0 milestone Jul 20, 2026
@camdecoster camdecoster changed the title feat: allow fixing the vertical order of Sankey nodes feat: Allow fixing the vertical order of Sankey links, nodes Jul 20, 2026
@camdecoster
camdecoster merged commit ccb2569 into plotly:v4.0 Jul 20, 2026
164 of 165 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@adamreeve

adamreeve commented Jul 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

OK thanks @camdecoster! Your changes all make sense to me but I've just been quite busy with work stuff lately. I'm not familiar with the link sort feature but am happy to take a look into that. I see you added the link sort here too, thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adamreeve
adamreeve deleted the sankey-order branch July 20, 2026 21:28
@camdecoster camdecoster mentioned this pull request Jul 22, 2026
Add directions attribute for Sankey diagrams #7870
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v4.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@adamreeve @camdecoster
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.