microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.36k stars 307 forks source link

order of sibling nodes #360

Open nanofrog opened 1 year ago

nanofrog commented 1 year ago

I test WpfApplicationSample with codes below, the first edge will always on the left, and 2nd edge is on the right. I knew the order of sibling nodes may be changed during layout. but my sample code is so simple. so how can I keep the edge from left to right with the order in codes?

                Graph graph = new Graph();
                graph.AddEdge("11111", "0");
                graph.AddEdge("11111", "22222222222222222222222222");

                graph.Attr.LayerDirection = LayerDirection.TB;

                graphViewer.Graph = graph;

msagl_1 msagl_2

levnach commented 1 year ago

In general, it is difficult to guarantee that one edge is to the left of another, but with the nodes it is possible. Here is your code with my changes working for me. Graph graph = new Graph(); var rightEdge = graph.AddEdge("11111", "0"); var leftEdge = graph.AddEdge("11111", "22222222222222222222222222"); graph.LayerConstraints.AddLeftRightConstraint(leftEdge.TargetNode, rightEdge.TargetNode);

image
nanofrog commented 1 year ago

In general, it is difficult to guarantee that one edge is to the left of another, but with the nodes it is possible. Here is your code with my changes working for me. Graph graph = new Graph(); var rightEdge = graph.AddEdge("11111", "0"); var leftEdge = graph.AddEdge("11111", "22222222222222222222222222"); graph.LayerConstraints.AddLeftRightConstraint(leftEdge.TargetNode, rightEdge.TargetNode); image

Year, I knew the algorithm may switch nodes in same rank to decrease crossing edges. but my demo is so simple, there's no need to do any switch. In another issue, somebody mentioned that it may relate to the DFS processing of nodes' out edges. if a stack is used in DFS, left edge will be pushed first, and pop up at last. then it will be arranged at right. Is this a possible reason?

levnach commented 1 year ago

The edge drawing algorithm of the tool follows https://ieeexplore.ieee.org/abstract/document/221135/ with some modifications.