ipysankeywidget icon indicating copy to clipboard operation
ipysankeywidget copied to clipboard

Order is not uniform across the diagram

Open sildar opened this issue 3 years ago • 2 comments

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 avatar Apr 16 '21 14:04 sildar

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.

sildar avatar Apr 22 '21 08:04 sildar

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

ricklupton avatar Feb 27 '23 15:02 ricklupton