Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz aligning subgraphs horizontally

I have the following code:

    digraph G {
        bgcolor=antiquewhite;
        compound=true;
        { 
            rankdir=LR ; 
            rank=same g0 p1 p2 p3 h1; 
        }
        subgraph cluster0 {
            style=filled;
            color=khaki;
            g0 [label="G",shape=circle,style="filled", color="red", fillcolor="lightpink"]
            label = "Cluster 0";
            g0 -> p1;
        }
        subgraph cluster1 {
            style=filled;
            color=khaki;
            p1 [label="S2",shape=box,style="filled", color="blue", fillcolor="skyblue"];
            p2 [label="S3",shape=box,style="filled", color="blue", fillcolor="skyblue"];
            p3 [label="S3",shape=box,style="filled", color="blue", fillcolor="skyblue"];
            label = "Cluster 1";
            p1 -> p2 -> p3 [arrowhead=none] ;
        }
        subgraph cluster2 {
            style=filled;
            color=khaki;
            h1 [label="h1",shape=box,style="invis"];
            label = "Cluster 2";
            p3 -> h1; 
        }
    }

Everything works perfect except the subgraphs don't show up. As soon as rank is defined outside the clusters the subgraphs disappear.

enter image description here

If defined inside a cluster body, same rank between clusters is lost.

like image 650
user1491229 Avatar asked Sep 27 '22 23:09

user1491229


1 Answers

  • rankdir is only applicable at graph level
  • a node may belong to one cluster only

.

digraph G {
    rankdir=LR ; 
    bgcolor=antiquewhite;
    compound=true;
    subgraph cluster0 {
        style=filled;
        color=khaki;
        g0 [label="G",shape=circle,style="filled", color="red", fillcolor="lightpink"]
        label = "Cluster 0";
    }
    subgraph cluster1 {
        style=filled;
        color=khaki;
        p1 [label="S2",shape=box,style="filled", color="blue", fillcolor="skyblue"];
        p2 [label="S3",shape=box,style="filled", color="blue", fillcolor="skyblue"];
        p3 [label="S3",shape=box,style="filled", color="blue", fillcolor="skyblue"];
        label = "Cluster 1";
        p1 -> p2 -> p3 [arrowhead=none] ;
    }
    subgraph cluster2 {
        style=filled;
        color=khaki;
        h1 [label="h1",shape=box,style="invis"];
        label = "Cluster 2";
    }
    g0 -> p1;
    p3 -> h1; 
}

gives

enter image description here

like image 92
stefan Avatar answered Oct 13 '22 01:10

stefan