我正在尝试在 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 太棒了!用于可视化和编辑状态机的绝佳工具。