Aligning Top Edge of Clusters in dot LR

Hi there,
I’m trying to align the top edge of clusters in a LR dot graph. I’ve tried numerous combinations of hidden nodes, clusters and edges but so far have not achieved my goal. I’ve also tried ordering=in | out, compound=true, newrank=true, outputorder=nodesfirst, pack=true, packmode=“graph”, packmode=“array” & sortv,

The best I’ve managed to get is the following (ZZ, 00, 10, 20, 30 and their respective clusters will be invisible, cluster_n will be invisible).

Graphviz 20.10.21

As per the following. Please note that I won’t be able to control the order of edges between A[A-n], B[A-n]; C[A-n] and D[A-n]:
strict digraph J
{
rankdir=LR;
splines=curved;
ZZ [group=dummy];
subgraph “cluster_0”
{
rankdir=TB;
subgraph “cluster_00”
{
00 [group=dummy];
}
subgraph “cluster_01”
{
AA;
AB;
AC;
AD;
}
}
subgraph “cluster_1”
{
rankdir=TB;
subgraph “cluster_10”
{
10 [group=dummy];
}
subgraph “cluster_11”
{
BA;
BB;
BC;
BD;
BE;
BF;
BG;
BH;
}
}
subgraph “cluster_2”
{
rankdir=TB;
subgraph “cluster_20”
{
20 [group=dummy];
}
subgraph “cluster_21”
{
CA;
CB;
CC;
CD;
CE;
CF;
CG;
}
}
subgraph “cluster_3”
{
rankdir=TB;
subgraph “cluster_30”
{
30 [group=dummy];
}
subgraph “cluster_31”
{
DA;
DB;
DC;
DD;
}
}
00->ZZ [weight=2];
10->ZZ [weight=2];
20->ZZ [weight=2];
30->ZZ [weight=2];
00->10 [weight=6];
10->20 [weight=6];
20->30 [weight=6];
AA->BA;
AA->BB;
AA->BC;
AA->CE;
AB->BD;
AB->BE;
AB->CC;
AC->BG;
AC->BH;
AC->CA;
AC->CB;
AC->DB;
BA->CD;
BB->CD;
BC->CD;
BF->CG;
AD->CF;
BH->DC;
BD->DD;
BE->DD;
CD->DA;
CG->DA;
}

Kind regards and thanks in advance.

James.

  • Do you also want to “order of edges between A[A-n], B[A-n]; C[A-n] and D[A-n]”?
  • Also, only one rankdir per entire graph. As I remember, the last rankdir wins

[ when providing source code, please us the “preformatted text” or do this ``` stuff ```]
Most of the changes are just reformatting. constraint=false does all the heavy lifting (more than I expected).

strict digraph J
{
  rankdir=LR;  // sorry, rankdir applies to entire graph
  splines=curved;
  ZZ [group=dummy];
  subgraph cluster_0 {
    rankdir=TB;  // sorry, rankdir applies to entire graph
    subgraph cluster_00{
      00 [group=dummy];
    }
    subgraph cluster_01{
      AA;
      AB;
      AC;
      AD;
    }
  }
  subgraph cluster_1{
    rankdir=TB;  // sorry, rankdir applies to entire graph
    subgraph cluster_10{
      10 [group=dummy];
    }
    subgraph cluster_11{
      BA;
      BB;
      BC;
      BD;
      BE;
      BF;
      BG;
      BH;
    }
  }
  subgraph cluster_2{
    rankdir=TB;  // sorry, rankdir applies to entire graph
    subgraph cluster_20{
      20 [group=dummy];
    }
    subgraph cluster_21{
      CA;
      CB;
      CC;
      CD;
      CE;
      CF;
      CG;
    }
  }
  subgraph cluster_3{
    rankdir=TB;  // sorry, rankdir applies to entire graph
    subgraph cluster_30{
      30 [group=dummy];
    }
    subgraph cluster_31{
      DA;
      DB;
      DC;
      DD;
    }
  }

00->10->20->30->ZZ

// allign the clusters AND order the nodes within the clusters (surprised me)
edge [constraint=false] 
00->ZZ 
10->ZZ 
20->ZZ 
30->ZZ 

AA->BA;
AA->BB;
AA->BC;
AA->CE;
AB->BD;
AB->BE;
AB->CC;
AC->BG;
AC->BH;
AC->CA;
AC->CB;
AC->DB;
BA->CD;
BB->CD;
BC->CD;
BF->CG;
AD->CF;
BH->DC;
BD->DD;
BE->DD;
CD->DA;
CG->DA;
}

Giving:

Many thanks for your quick and comprehensive responses to my question - much appreciated. Of course you are right with “rankdir” - I suspect I was trying just about everything and forgot to remove it before uploading.
I guess I have a choice to make regarding the use of “constraint” - either have the top edges of the clusters aligned or allow graphviz to reorder A[A-n], etc to minimise path lengths and crossing between them.
Again, thanks for your time and consideration of my issue.
James.