graphviz dot:有两个簇,其间有节点

时间:2015-03-16 08:07:55

标签: graphviz dot

我有以下图表

digraph {
    subgraph cluster_party1 {
        do_some_stuff
        and_some_stuff
        and_other_stuff

        do_some_stuff -> and_some_stuff -> and_other_stuff
    }

    subgraph cluster_party2 {
        do_that
        then_do_that
        and_this

        do_that -> then_do_that -> and_this
    }
}

two clusters

现在我想在这些集群之间添加节点并使用边连接它们:

digraph {
    subgraph cluster_party1 {
        do_some_stuff
        and_some_stuff
        and_other_stuff

        do_some_stuff -> and_some_stuff -> and_other_stuff
    }

    with_this
    and_that
    using_this

    subgraph cluster_party2 {
        do_that
        then_do_that
        and_this

        do_that -> then_do_that -> and_this
    }

    do_some_stuff -> with_this -> do_that
    then_do_that -> and_that -> and_some_stuff
    and_other_stuff -> using_this -> and_this
}

clusters with scattered nodes

但这并不是我预期的结果。我希望它们之间的节点与连接节点的高度相同:让我们尝试对它们进行排名:

digraph {
    subgraph cluster_party1 {
        do_some_stuff
        and_some_stuff
        and_other_stuff

        do_some_stuff -> and_some_stuff -> and_other_stuff
    }

    with_this
    and_that
    using_this

    subgraph cluster_party2 {
        do_that
        then_do_that
        and_this

        do_that -> then_do_that -> and_this
    }

    {rank=same; rankdir=LR; do_some_stuff -> with_this -> do_that}
    {rank=same; then_do_that -> and_that -> and_some_stuff}
    {rank=same; and_other_stuff -> using_this -> and_this}
}

clusters disappeared

嗯,它们处于相同的高度,但是群集消失了,中间行的顺序错误。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

点布局引擎有自己的想法: - )

digraph {

    subgraph cluster_party1 {
        do_some_stuff
        and_some_stuff
        and_other_stuff

        do_some_stuff -> and_some_stuff -> and_other_stuff
    }

    with_this
    and_that
    using_this

    subgraph cluster_party2 {
        do_that
        then_do_that
        and_this

        do_that -> then_do_that -> and_this
    }
    with_this -> and_that -> using_this [style=invis]

    do_some_stuff -> with_this -> do_that [constraint=false]
    then_do_that -> and_that -> and_some_stuff [constraint=false]
    and_other_stuff -> using_this -> and_this [constraint=false]
}

给出

enter image description here

替代解决方案是

digraph { rankdir = LR

    subgraph cluster_party1 {
        do_some_stuff
        and_some_stuff
        and_other_stuff
        { rank=same do_some_stuff -> and_some_stuff -> and_other_stuff }
    }

    with_this
    and_that
    using_this

    subgraph cluster_party2 {
        do_that
        then_do_that
        and_this

        { rank=same do_that -> then_do_that -> and_this }
    }

    do_some_stuff -> with_this -> do_that
    and_some_stuff -> and_that -> then_do_that [dir=back]
    and_other_stuff -> using_this -> and_this

    { rank=same with_this -> and_that -> using_this [style=invis] }
}

并给出

enter image description here