【问题标题】:Graphviz nested subgraph orientationGraphviz 嵌套子图方向
【发布时间】:2021-11-22 18:02:23
【问题描述】:

我最近看到了下面的图片。我知道它是用 graphviz/dot 创建的,但源代码不可用(迷失了时间)。

期望的输出:

我一直在尝试找到一种方法来对源代码进行逆向工程,但是嵌套子图的水平顺序一直给我带来困难。在代码中,一个最基本的、大部分工作的示例看起来像这样

digraph G {
    A
    B
    subgraph cluster_0 {
        edge [style=invis]
        subgraph cluster_0_0 {
            D -> E -> F
        }
        C -> D -> E -> F -> G
    }

    A -> C
    A -> B
    A -> G
    B -> { D E F }
}

但是,这给了我这个输出:

newrank=true 添加到外部子图中可以得到我正在寻找的水平方向:

digraph G {
    A
    B
    subgraph cluster_0 {
        newrank=true
        edge [style=invis]
        subgraph cluster_0_0 {
            D -> E -> F
        }
        C -> D -> E -> F -> G
    }

    A -> C
    A -> B
    A -> G
    B -> { D E F }
}

但这会以错误的顺序设置节点:

【问题讨论】:

    标签: graphviz dot subgraph


    【解决方案1】:

    我希望有更好的解决方案,但这里有一个(其余的节点标签应该很明显):

    digraph G {
       newrank=true
       splines=false  // A->C edge gets wacky without this
       
       node [shape=Mrecord]
       // Mrecords produce this Warning:
       //   flat edge between adjacent nodes one of which has a record shape - replace records with HTML-like labels
       // but Mrecords still seem to work, so maybe ignore warning ??
    
       // hoped that ordering or weight or group attributes would
       // position C and G as desired, but nope
       // instead, clusters and constraint attribute worked, why?
    
        A [group=T label="{Measure|4/4}"]
        B [group=T]
        A -> B
        {
          rank=same C F E D G   // declare right-to-left ??
        }
        subgraph clusterCDEFG {
            graph [style=rounded]
        // within a rank, layout tends to be right-to-left
        // so, declare right-to-left ??
        // why do these clusters help position C & G ???    
           subgraph clusterG {  peripheries=0
           G 
            }
            subgraph clusterDEF {
          // declare right-to-left
          F
              E [group=T]
          D 
          edge [style=invis]
           //   D -> E -> F
            }
        // why do these clusters help position C & G ???
            subgraph clusterC { peripheries=0
           C
            }
        }
    
        A -> C  [constraint=false]  // why does this impact position within rank ??
        A -> G  [constraint=false]  // why does this impact position within rank ??
        B -> { F E D } // declare right-to-left ??
        edge [style=invis]
    //    C -> D  // Mrecord shape has problems
    //    F -> G  // Mrecord shape has problems
    }
    

    捐赠:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-20
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      相关资源
      最近更新 更多