3

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

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 编译失败...

4

1 回答 1

1

几个想法

  • 我认为子图需要有一个以“集群”开头的名称才能获得任何样式。实际上,如果没有集群前缀,它们可能根本不会做任何事情,这可能是您许多问题的根源。
  • 您不需要重复 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"
}
于 2013-01-28T16:48:42.430 回答