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

Order is not uniform across the diagram #62

Open
sildar opened this issue Apr 16, 2021 · 2 comments
Open

Order is not uniform across the diagram #62

sildar opened this issue Apr 16, 2021 · 2 comments

Comments

@sildar
Copy link
Contributor

sildar commented Apr 16, 2021

Hi!

While drawing sankey diagrams, I often want to have coloring depending on type, and keep those colors all the way through the diagram. While this feature exists, it does not seem to be compatible with the order parameter.

Here's a minimal example of what I mean:

links = [{"source": "A", "target": "1", "value": 5, "type": "A"},
         {"source": "B", "target": "1", "value": 10, "type": "B"},
         {"source": "C", "target": "1", "value": 15, "type": "C"},
         {"source": "1", "target": "2", "value": 5, "type": "A"},
         {"source": "1", "target": "2", "value": 10, "type": "B"},
         {"source": "1", "target": "2", "value": 15, "type": "C"}]

w = SankeyWidget(links=links)
w

image

This works well, but if I want to change the ordering of, say, A and B, I can write this:

links = [{"source": "A", "target": "1", "value": 5, "type": "A"},
         {"source": "B", "target": "1", "value": 10, "type": "B"},
         {"source": "C", "target": "1", "value": 15, "type": "C"},
         {"source": "1", "target": "2", "value": 5, "type": "A"},
         {"source": "1", "target": "2", "value": 10, "type": "B"},
         {"source": "1", "target": "2", "value": 15, "type": "C"}]

order = [
         ["B", "A", "C"],
         ["1"],
         ["2"]
]

w = SankeyWidget(links=links, order=order)
w

image

While this works, the ordering is only defined for the first layer, and the next one (between "1" and "2") is not impacted by the order parameter, making the diagram harder to read. I can't find a way to keep the ordering consistent in subsequent layers, am I missing something? I tried changing the ordering of the links structure, thinking first entries get drawn first (ie switching lines 4 and 5), but unfortunately this is not the case.

Is there any solution?

@sildar
Copy link
Contributor Author

sildar commented Apr 22, 2021

Hi,

I found the "align_link_types" parameter but it keeps things messy:

order

I would have expected A to stay in the middle. This leads to chaotic diagrams quickly when there's more data.

@ricklupton
Copy link
Owner

Hi, sorry for the late reply.

This is a limitation of the align_link_types parameter: the link types are ordered alphabetically, not in the order that makes most sense graphically.

You can sometimes work around it by naming your types with a prefix to get them to sort in the right order: 0_B, 1_A, 2_C, say.

More generally this would need substantial changes to the optimisation layout code (but it would be nice if it worked!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants