gpt4 book ai didi

Graphviz:禁止水平边缘,始终显示垂直方向

转载 作者:行者123 更新时间:2023-12-03 09:21:16 24 4
gpt4 key购买 nike

我有一个有向无环图,我正在尝试使用 Graphviz 的 dot 对其进行可视化。默认情况下,它是从上到下排列的。

通常,所有有向边的头部都低于尾部。但在某些情况下,它们被绘制为水平直线部分,即头部和尾部处于同一水平。就我而言,这发生在我定义子图簇之后。

他们是否有办法禁止这种情况并强制它始终定位节点以使箭头指向“向下”?

示例来源:

digraph {
rankdir=TB;
subgraph cluster_1 { "8"; "7"; "9"; "11"; "10" }
subgraph cluster_2 { "3"; "4"; "5"; }

"1" -> "3";
"2" -> "5";
"3" -> "6";
"3" -> "5";
"2" -> "8";
"2" -> "4";
"2" -> "3";
"2" -> "6";
"2" -> "7";
"1" -> "8";
"7" -> "8";
"4" -> "6";
"6" -> "10";
"3" -> "11";
"7" -> "10";
"7" -> "6";
"1" -> "2";
"6" -> "5";
"7" -> "9";
"7" -> "5";
"4" -> "5";
"6" -> "8";
"3" -> "4";
"10" -> "11";
"4" -> "11";
"3" -> "8";
"8" -> "9";
"6" -> "9";
"9" -> "10";
"3" -> "10";
"3" -> "7";
}

最佳答案

我知道这是一个老问题,但我将提供这个答案以供将来引用:

您可以使用 newrank = true; 根据 graphviz.org website 执行以下操作:

The original ranking algorithm in dot is recursive on clusters. This can produce fewer ranks and a more compact layout, but sometimes at the cost of a head node being place on a higher rank than the tail node. It also assumes that a node is not constrained in separate, incompatible subgraphs. For example, a node cannot be in a cluster and also be constrained by rank=same with a node not in the cluster.

If newrank=true, the ranking algorithm does a single global ranking, ignoring clusters. This allows nodes to be subject to multiple constraints. Rank constraints will usually take precedence over edge constraints.

因此您的来源仅更改如下:

  digraph {
rankdir=TB;
newrank = true;
...

这个例子的结果会更好:

enter image description here

关于Graphviz:禁止水平边缘,始终显示垂直方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30330584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com