microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.35k stars 302 forks source link

Enforcing neighborship does not properly affect downstream nodes (Sugiyama) #283

Open treshels opened 3 years ago

treshels commented 3 years ago

I was trying to lay out several nodes/edges (DAG) by using the SugiyamaLayout, with the added requirement for certain nodes of the same layer to be positioned next to each other like this:

var settings = new Microsoft.Msagl.Layout.Layered.SugiyamaLayoutSettings();
settings.AddSameLayerNeighbors(mynodes);
Microsoft.Msagl.Miscellaneous.LayoutHelpers.CalculateLayout(fullGraph, settings, null);

While this does lead to the mentioned nodes being placed next to each other, it has almost no effect on the downstream nodes of the respective branches - i.e. the children of my nodes are placed the same way independently of whether I try to enforce the neighborship or not. Therefore the overall graph contains a lot of crossing lines if I try to enforce any neighborships - see screenshots:

Graph in its "natural" order: image

Graph with the bottommost layer enforcing certain neighborships (excluding the root node): image

I may have misunderstood the feature or its use, but this seems like a bug to me. If there is a better way to achieve what I want to do, please let me know. If you could just leave a few pointers of where this could be fixed in the codebase, I might even be able to invest some time into that.

PS: Please ignore the diagonal edges; my algorithm is built for drawing the graphs in a horizontal manner, but for the screenshots I wanted to simplify the code and settings as much as possible.

levnach commented 3 years ago

It looks like a bug. The relevant code is here https://github.com/microsoft/automatic-graph-layout/blob/master/GraphLayout/MSAGL/Layout/Layered/Ordering/ConstrainedOrdering.cs

treshels commented 3 years ago

Thank you very much for the link. I will see if I get some time to look into this; although it is unrealistic in the short term. Maybe/hopefully somebody else will be faster than me.