发布
社区首页 >问答首页 >Graphviz嵌套子图方向

Graphviz嵌套子图方向
EN

Stack Overflow用户
提问于 2021-10-01 00:05:28
回答 1查看 86关注 0票数 0

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

所需输出:

我一直在试图找到一种反向工程源代码的方法,但嵌套子图的水平排序一直给我带来了困难。在代码中,一个简单的最小的、主要工作的示例如下所示

代码语言:javascript
代码运行次数:0
复制
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添加到外部子图中可以得到我正在寻找的水平方向:

代码语言:javascript
代码运行次数:0
复制
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 }
}

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

EN

回答 1

Stack Overflow用户

发布于 2021-10-01 17:14:27

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

代码语言:javascript
代码运行次数:0
复制
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
}

给予:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69399948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档