gpt4 book ai didi

与其他节点具有相同等级的 graphviz 集群

转载 作者:行者123 更新时间:2023-12-04 18:10:31 26 4
gpt4 key购买 nike

我正在尝试创建一个图表,我明确指定了许多节点的等级并指定了集群。以下代码生成我想要的图形类型:

digraph {
rankdir=LR
subgraph cluster0 {
"MATH 208"
"MATH 211"
graph [rankdir=LR, style="rounded,filled", color=gray]
}
subgraph year1 {
subgraph {
"MATH 100"
"MATH 110"
graph [rankdir=LR, rank=same]
}
subgraph {
"MATH 101"
"MATH 211"
"MATH 208"
graph [rankdir=LR, rank=same]
}
graph [rankdir=LR]
}
subgraph year2 {
subgraph {
"MATH 205"
"PHIL 203"
graph [rankdir=LR, rank=same]
}
graph [rankdir=LR]
}
subgraph year3 {
subgraph {
"MATH 311"
"MATH 312"
"MATH 375"
graph [rankdir=LR, rank=same]
}
graph [rankdir=LR]
}
subgraph year4 {
subgraph {
"MATH 447"
"MATH 412"
graph [rankdir=LR, rank=same]
}
graph [rankdir=LR]
}
"MATH 100" -> "MATH 101"
"MATH 100" -> "MATH 208"
"MATH 101" -> "MATH 205"
"MATH 110" -> "MATH 311"
"MATH 211" -> "MATH 311"
"MATH 110" -> "MATH 312"
"MATH 211" -> "MATH 312"
"PHIL 203" -> "MATH 375"
"MATH 110" -> "MATH 447"
"MATH 211" -> "MATH 447"
"MATH 311" -> "MATH 412"
"MATH 312" -> "MATH 412"
}

这会生成一个正确的图形,其中“MATH 211”与“MATH 101”处于同一等级,但是 graphviz 会发出警告

Warning: MATH 208 was already in a rankset, ignored in cluster pruned
Warning: MATH 211 was already in a rankset, ignored in cluster pruned

如果我从 year1 子图中删除“MATH 211”和“MATH 208”,graphviz 不再提示,但生成的图不再具有与“MATH 101”相同级别的集群(为什么会...) :

有什么方法可以重新排列/重新排序我的点文件以生成第一个图形但没有任何警告?或者指定某个集群应该与另一个节点位于同一级别?

我应该注意到这个图在 graphviz 2.26 上成功编译,但在 graphviz 2.28 上失败...

最佳答案

几个想法

  • 我认为子图需要有一个以“cluster”开头的名称为了获得任何造型。实际上,如果没有集群前缀,他们可能根本不会做任何事情这可能是您许多问题的根源。
  • 您不需要重复 rankdir=LR。在顶部指定一次就足够了。
  • 如果子图中没有节点相互依赖,则他们很有可能已经处于同一等级,而 rank=same 不应该需要。

这是一个适合我的版本:

    digraph {
rankdir=LR
subgraph cluster0 {
"MATH 208"
"MATH 211"
graph [style="rounded,filled", color=gray]
}
subgraph clusteryear1 {
subgraph cluster100{
"MATH 100"
"MATH 110"
graph [rank=same]
}
subgraph cluster101{
"MATH 101"
"MATH 211"
"MATH 208"
graph [rank=same]
}
}
subgraph clusteryear2 {
subgraph cluster205{
"MATH 205"
"PHIL 203"
graph [rank=same]
}
}
subgraph clusteryear3 {
subgraph cluster311{
"MATH 311"
"MATH 312"
"MATH 375"
graph [rank=same]
}
}
subgraph clusteryear4 {
subgraph cluster447 {
"MATH 447"
"MATH 412"
graph [rank=same]
}
}
"MATH 100" -> "MATH 101"
"MATH 100" -> "MATH 208"
"MATH 101" -> "MATH 205"
"MATH 110" -> "MATH 311"
"MATH 211" -> "MATH 311"
"MATH 110" -> "MATH 312"
"MATH 211" -> "MATH 312"
"PHIL 203" -> "MATH 375"
"MATH 110" -> "MATH 447"
"MATH 211" -> "MATH 447"
"MATH 311" -> "MATH 412"
"MATH 312" -> "MATH 412"
}

关于与其他节点具有相同等级的 graphviz 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14553562/

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