【问题标题】:Space around disconnected nodes in MSAGL (WinForms)MSAGL(WinForms)中断开节点周围的空间
【发布时间】:2021-07-04 10:35:12
【问题描述】:

我正在尝试在 MSAGL (WinForms) 版本 1.1.3 中强制实现未连接节点之间的最小距离。用户从头开始创建图表。这涉及创建节点,并在节点之间拖动以创建边。但是所有没有任何边缘的节点都会粘在其他节点上,就像聚苯乙烯球粘在羊毛套头衫上一样。

我希望所有节点,无论有无边缘,都具有最小间距。对此可能有一个简单的答案,到目前为止我还没有想到。在 GitHub、here 和 Google 上搜索了相关资料后,我尝试了但没有成功:

LayoutAlgorithmSettings.NodeSeparation = 200; //works well between nodes that have edges between
LayoutAlgorithmSettings.ClusterMargin = 200;
LayoutAlgorithmSettings.PackingMethod = Microsoft.Msagl.Core.Layout.PackingMethod.Columns;
LayoutAlgorithmSettings.PackingAspectRatio = 2;
LayoutAlgorithmSettings.EdgeRoutingSettings.Padding = 100;

这是图形生成代码(省略了一些声明和其他细节)。我正在使用 MDS 布局:

Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");

graph.LayoutAlgorithmSettings = new Microsoft.Msagl.Layout.MDS.MdsLayoutSettings();
            
//add steps
foreach (Step step in config.Steps)
{
    Node node = new Node(step.Name);
    node.UserData = step;
    UpdateNodeColour(node);
    graph.AddNode(node);
}
                
//add transitions (edges)
foreach(Transition t in config.Transitions)
    graph.AddEdge(t.FromStep.Name, t.Name, t.ToStep.Name);

gViewer.Graph = graph;

顺便说一句 - MSAGL 太棒了!用于可视化和编辑状态机的绝佳工具。

【问题讨论】:

    标签: c# winforms msagl


    【解决方案1】:

    我有同样的重叠问题。我用下面的方法解决了这个问题。

    填充图表后,使用GeometryGraph 通过Microsoft.Msagl.Core.Layout.GraphConnectedComponents.CreateComponents() 添加节点分隔:

    if (graph.NodeCount > 1)
    {
        GeometryGraph geomGraph = graph.GeometryGraph;
        IEnumerable< GeometryGraph> geomGraphComponents =
            GraphConnectedComponents.CreateComponents(geomGraph.Nodes, geomGraph.Edges);
    
        SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();
        foreach (GeometryGraph subgraph in geomGraphComponents)
        {
            LayeredLayout layout = new LayeredLayout(subgraph, settings);
            subgraph.Margins = settings.NodeSeparation / 2;
            layout.Run();
        }
        
        MdsGraphLayout.PackGraphs(geomGraphComponents, settings);
        geomGraph.UpdateBoundingBox();
    }
    

    参见 LayeredLayout.Run 示例中的示例 #1:

    https://csharp.hotexamples.com/examples/Microsoft.Msagl.Layout.Layered/LayeredLayout/Run/php-layeredlayout-run-method-examples.html

    注意:从源示例中不要设置 'gViewer1.NeedToCalculateLayout = false;'如果您打算刷新图表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      相关资源
      最近更新 更多