microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.34k stars 301 forks source link

Control port entry/exit direction in RectilinearEdgeRouter? #333

Open andrzejolszak opened 1 year ago

andrzejolszak commented 1 year ago

Hello,

I have a graph of nodes containing 'input' and 'output' ports, and I'd like to use the RectilinearEdgeRouter to route the edges. I have a basic version of this working

var rectRouter = new RectilinearEdgeRouter(this, 10, 3, true, true);
rectRouter.RouteToCenterOfObstacles = false;
rectRouter.Run();

However, I would like to ensure that edges always connect to inputs/top-ports by going 'up' and to outputs/bottom-ports by going 'down'. Or perhaps in other words, I would like to minimize, or ideally completely prevent edges overlapping with nodes... You can see an example of how it looks like without this constraint below. I browsed through the code and directions seem to be handled explicitly, so I believe this should be tweakable, I just don't know how to do it...

image

andrzejolszak commented 1 year ago

After some digging, I can see that I can get this somewhat working by pre-declaring waypoints:

            foreach(Edge e in this.Edges)
            {
                e.EdgeGeometry.Waypoints = new []
                {
                    e.EdgeGeometry.SourcePort.Location + new Microsoft.Msagl.Core.Geometry.Point(0, 5),
                    e.EdgeGeometry.TargetPort.Location + new Microsoft.Msagl.Core.Geometry.Point(0, -5)
                };
            }

However, this probably puts additional strain on the routing algorithm, and indeed it seems that the algorithm sometimes cannot fulfill the constraints.

So if there is any other/better way, I will be glad to hear about it!

levnach commented 1 year ago

Sorry, I do not know any good approach here.