Graphviz aligning subgraphs horizontally
Asked Answered
K

1

6

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.

Kostival answered 11/5, 2015 at 14:19 Comment(0)
A
5
  • 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

Aglow answered 12/5, 2015 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.