Graphviz:禁止水平边缘,始终显示垂直方向
Graphviz: forbid horizontal edges, always show vertical orientation
我有一个有向无环图,我正尝试使用 Graphviz 的 dot
对其进行可视化。默认情况下,它的布局是 top-to-bottom.
通常,所有有向边的头都低于尾巴。但在某些情况下,它们被绘制为水平直线部分,即头部和尾部处于同一水平。在我的例子中,这是在我定义子图集群之后发生的。
他们有办法禁止这种情况并强制它总是 定位节点以便箭头指向"downwards"吗?
示例来源:
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";
}
该行为是由固定内部节点等级的集群引起的。 'Force' 从外部边缘水平拉动节点,但对排名没有影响。
您必须避免集群或插入不可见的节点和边。
显示排名修复的最小示例
digraph {
subgraph cluster_1 {
1
3
}
1 -> 2
2 -> 3
}
我知道这是一个老问题,但我会提供这个答案以供将来参考:
您可以使用 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;
...
这个例子的结果会更好:
我有一个有向无环图,我正尝试使用 Graphviz 的 dot
对其进行可视化。默认情况下,它的布局是 top-to-bottom.
通常,所有有向边的头都低于尾巴。但在某些情况下,它们被绘制为水平直线部分,即头部和尾部处于同一水平。在我的例子中,这是在我定义子图集群之后发生的。
他们有办法禁止这种情况并强制它总是 定位节点以便箭头指向"downwards"吗?
示例来源:
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";
}
该行为是由固定内部节点等级的集群引起的。 'Force' 从外部边缘水平拉动节点,但对排名没有影响。
您必须避免集群或插入不可见的节点和边。
显示排名修复的最小示例
digraph {
subgraph cluster_1 {
1
3
}
1 -> 2
2 -> 3
}
我知道这是一个老问题,但我会提供这个答案以供将来参考:
您可以使用 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;
...
这个例子的结果会更好: