Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphViz - alignment of subgraph

I'd like to draw a diagram like this. desired

But the only diagram I can draw is: current

The code I used :

graph [rankdir = LR]

node [shape=box]

x1;x2;x3;y1;y2;y3;y4;y5;y6;y7;y8;

node [shape=oval]

ind60;dem60;dem65

{x1,x2,x3} -> ind60[arrowhead=none arrowtail=normal dir=both]

{y1,y2,y3,y4} -> dem60[arrowhead=none arrowtail=normal dir=both]

dem65 -> {y5,y6,y7,y8}

ind60->dem60  dem60->dem65  ind60->dem65

How can I draw the desired plot?

like image 396
Keon-Woong Moon Avatar asked Apr 25 '17 00:04

Keon-Woong Moon


1 Answers

A first step in what you want to achieve, using rank=same, invisible edges, groups, and constraint=false:

digraph {

node [shape=box]
{
    rank=same;
    y1;y2;y3;y4;
}

dem60[shape=oval];
{y1;y2;y3;y4} -> dem60 [dir=back];

{
    rank=same;
    x2 [group=left];
    ind60[shape=oval];
    dem65[shape=oval];
    y6 [group=right];

    x2 -> ind60 [dir=back];
    ind60 -> dem65
    dem65 -> y6;
}

// Invisible edges to order vertically node groups
edge[style=invis];
x1[group=left];
x3[group=left];
x1 -> x2 -> x3;
node[group=right];
y5 -> y6 -> y7 -> y8;

node[group=""]
edge[style=solid]
ind60->dem60
dem60->dem65

edge[constraint=false];
ind60 -> x1;
ind60 -> x3;
dem65 -> y5;
dem65 -> y7;
dem65 -> y8;
}
  • group enforces vertical alignement of nodes (of the same group).
  • rank=same makes nodes stay on the same rank.
  • Invisible edges enforce rank order within a vertical group.
  • constraint=false removes constraint calculation for some edges.
  • dir=back reverses displayed edge direction.
like image 82
marapet Avatar answered Nov 11 '22 00:11

marapet