microsoft / automatic-graph-layout

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

InteractiveEdgeRouter does not appear to be respecting BoundaryCurves of square nodes #260

Open SMTStuck opened 3 years ago

SMTStuck commented 3 years ago

This code is adapted from the EdgeRoutingSample DemoRoutingFromPortToPort and DrawEdgeWithPort methods. However, I notice that the nodes within that particular example are ellipses which appear to make the difference.

The nodes are simple squares, but it seems that the inner InteractiveEdgeRouter is not respecting the boundary curves of the square nodes. The boundary curves passed into the InteractiveEdgeRouter are however correct:

private void DoLayout(GeometryGraph geometryGraph)
{
    IEnumerable<GeometryGraph> subGraphs = GraphConnectedComponents.CreateComponents(geometryGraph.Nodes, geometryGraph.Edges);

    SugiyamaLayoutSettings layoutSettings = new SugiyamaLayoutSettings();
    layoutSettings.EdgeRoutingSettings.EdgeRoutingMode = Microsoft.Msagl.Core.Routing.EdgeRoutingMode.Rectilinear;
    layoutSettings.NodeSeparation = 120;
    layoutSettings.LayerSeparation = 120;
    layoutSettings.Transformation = PlaneTransformation.Rotation(Math.PI);

    foreach (GeometryGraph subgraph in subGraphs)
    {
        LayeredLayout layout = new LayeredLayout(subgraph, layoutSettings);
        subgraph.Margins = layoutSettings.NodeSeparation + 200;
        layout.Run();
    }

    InteractiveEdgeRouter portRouter = new InteractiveEdgeRouter(geometryGraph.Nodes.Select(n => n.BoundaryCurve), 0, 0, 0);
    portRouter.Run();
    foreach (Edge tEdge in geometryGraph.Edges)
    {
        FloatingPort port1 = new FloatingPort(null, new Microsoft.Msagl.Core.Geometry.Point(tEdge.Source.BoundingBox.Center.X, tEdge.Source.BoundingBox.Bottom - 10));
        FloatingPort port2 = new FloatingPort(null, new Microsoft.Msagl.Core.Geometry.Point(tEdge.Target.BoundingBox.Center.X, tEdge.Target.BoundingBox.Top + 10));
        ICurve spline = portRouter.RouteSplineFromPortToPortWhenTheWholeGraphIsReady(port1, port2, false, out _);

        Arrowheads.TrimSplineAndCalculateArrowheads(tEdge.EdgeGeometry,
            tEdge.Source.BoundaryCurve,
            tEdge.Target.BoundaryCurve,
            spline, true, false);

        DrawSpline(tEdge, spline);
    }

}

NodeBoundaries

I am aware that the ports appear backwards - i.e. exit at the top and entry at the bottom. This is a deliberate setup to test MSAGL.

levnach commented 3 years ago

Can you try to move the ports closer to their node bounding boxes and see if the trimming happens?