graphviz与其他节点具有相同排名的群集

时间:2013-01-27 23:34:55

标签: graphviz dot

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

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失败了......

1 个答案:

答案 0 :(得分:0)

一些想法

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

这是一个适合我的版本:

    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"
}