1

是否可以强制从节点的四个基本边界中点绘制边缘线?即节点边界上的十二点、三点、六点和九点位置,类似于 Visio 或 PowerPoint 中的连接器。

所需输出的草图

4

1 回答 1

0

我给 MSAGL 的主要作者 Lev Nachmanson 发了电子邮件,他很友好地回复了我。他确认,截至 2022 年 1 月,MSAGL 目前没有此类功能。

编辑 1: MSAGL 的FloatingPort对象似乎适合手动定位边缘线的端点:Edge对象具有SourcePortTargetPort属性。我还没有找到任何关于如何实际使用这些的文档或教程。任何指针表示赞赏。

编辑2:可以通过计算布局一次,然后布局后,强制EdgeRouter重新路由foreach循环中的所有边缘来完成。

我从使用 MSAGLhttps://github.com/microsoft/automatic-graph-layout/issues/250的 Routing only edge 以及大量的试验和错误中获得了大量灵感。

private void Button1_Click(object sender, EventArgs e)
{
    //gViewer1.Invalidate();
    gViewer1.CalculateLayout(_visgraph);
    
    Microsoft.Msagl.Routing.InteractiveEdgeRouter edgeRouter = new Microsoft.Msagl.Routing.InteractiveEdgeRouter(_visgraph.GeometryGraph.Nodes.Select(n => n.BoundaryCurve), 3, 0.65 * 3, 0);
    edgeRouter.Run();

    Microsoft.Msagl.Core.Geometry.SmoothedPolyline ignore;
    foreach (var edge in _visgraph.GeometryGraph.Edges)
    {
        Microsoft.Msagl.Core.Layout.FloatingPort p1 = 
            new Microsoft.Msagl.Core.Layout.FloatingPort(edge.Source.BoundaryCurve
                                                        , new Microsoft.Msagl.Core.Geometry.Point(edge.Source.BoundingBox.Right
                                                                                                 ,edge.Source.BoundingBox.Center.Y));
        Microsoft.Msagl.Core.Layout.FloatingPort p2 = 
            new Microsoft.Msagl.Core.Layout.FloatingPort(edge.Target.BoundaryCurve
                                                        , new Microsoft.Msagl.Core.Geometry.Point(edge.Target.BoundingBox.Left
                                                                                                 ,edge.Target.BoundingBox.Center.Y));

        edge.SourcePort = p1;
        edge.TargetPort = p2;
        edge.Curve = edgeRouter.RouteSplineFromPortToPortWhenTheWholeGraphIsReady(edge.SourcePort, edge.TargetPort, true, out ignore);

        Microsoft.Msagl.Core.Layout.Arrowheads.TrimSplineAndCalculateArrowheads(edge
                                                                               ,edge.Curve
                                                                               ,true
                                                                               ,true);
    }
}

在此处输入图像描述

于 2022-01-26T20:02:06.917 回答