0

I recently came across the image below. I know it was created with graphviz/dot, but the source code is not available (lost to time).

Desired Output:

Desired Output

I have been trying to find a way to reverse engineer the source code, but the horizontal ordering of the nested subgraphs has been giving me difficulty. A bare minimum mostly-working example looks like this in code

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

However, that gives me this output:

bare minimum example, vertical

Adding newrank=true to the outer subgraph gives me the horizontal orientation I'm looking for:

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

But this sets the nodes in the wrong order:

horizontal but out of order

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

0

I hope there is a better solution, but here is one (the rest of the node labels should be evident):

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
}

Giving:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11