graphviz点: have two clusters with nodes in between

标签 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

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

最佳答案

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

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

关于graphviz点: have two clusters with nodes in between,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29072110/

相关文章:

json - json的自动可视化

java - 从 RDF 文件生成 .DOT 文件

Graphviz/Dot - 如何用独特的颜色标记树中的所有叶子?

graphViz:如何为节点分配多种颜色

networkx - 将 networkx 图移植到 graphviz,无需 pygraphviz

graphviz - 等级属性让我感到困惑

graphviz - 优化Graphviz中的标签位置

javascript - 从 SVG 对象检索信息

graphviz - 对 DOT 中的边进行分组 (Graphviz)

html - graphviz html表节点居中而不是相同的等级