Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameterize the sorting algorithm in resolveCollisions() #45

Closed
damil opened this issue Sep 17, 2017 · 4 comments
Closed

parameterize the sorting algorithm in resolveCollisions() #45

damil opened this issue Sep 17, 2017 · 4 comments

Comments

@damil
Copy link

damil commented Sep 17, 2017

I'm new to d3-sankey and d3.js in general, thanks for this software, it's just amazingly powerful.
One feature is missing in sankey : the ability to customize the sorting algorithm used in resolveCollisions().
I'm building a diagram where I need vertical nodes to be sorted by name instead of "ascendingBreadth". I modified the source code by putting my own sorting function and it works like a charm; but it would be much better if the sorting function could be passed as a parameter to sankey().

@jonvitale
Copy link

@damil , could you provide me an example of where and how you did this? I need to sort alphabetically (A higher than B, higher than C, etc.).

@damil
Copy link
Author

damil commented Oct 13, 2017

In function resolveCollisions(), like this :

    function resolveCollisions() {
      nodesByDepth.forEach(function(nodes) {
        var node,
            dy,
            y = y0,
            n = nodes.length,
            i;

        // Push any overlapping nodes down.
        // ORIG : nodes.sort(ascendingBreadth);
        // MODIFIED LINE BELOW :
        nodes.sort(function(a, b){return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;});

@tjallingt
Copy link

tjallingt commented Jul 2, 2018

I just ran into a situation where disabling/altering the sorting would be super useful.

EDIT: seems like this pull would fix this: #53

@mbostock
Copy link
Member

mbostock commented Sep 1, 2019

You can now use sankey.nodeSort(null) to disable automatic reordering of nodes within the columns and preserve the input order.

@mbostock mbostock closed this as completed Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants