【问题标题】:graphviz dot: have two clusters with nodes in betweengraphviz dot:有两个集群,中间有节点
【发布时间】:2015-03-16 08:07:54
【问题描述】:

我有以下图表

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

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

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
}

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

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

嗯,它们的高度相同,但簇消失了,中间行的顺序错误。我该如何解决?

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

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

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

    给予

    替代解决方案是

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

    并给予

    【讨论】:

    • style=invisdir=back 其实真的很有用,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 2016-03-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多