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 of sibling nodes #360

Open
nanofrog opened this issue Nov 3, 2023 · 3 comments
Open

order of sibling nodes #360

nanofrog opened this issue Nov 3, 2023 · 3 comments

Comments

@nanofrog
Copy link

nanofrog commented Nov 3, 2023

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
Copy link
Contributor

levnach commented Nov 3, 2023

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
Copy link
Author

nanofrog commented Nov 6, 2023

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
Copy link
Contributor

levnach commented Nov 6, 2023

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

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

No branches or pull requests

2 participants