Graphviz水平对齐子图

时间:2015-05-11 14:19:18

标签: alignment graphviz rank subgraph

我有以下代码:

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

除了子图不显示外,一切都很完美。一旦在集群外定义了等级,子图就会消失。

enter image description here

如果在集群体内定义,则集群之间的相同排名将丢失。

1 个答案:

答案 0 :(得分:1)

  • rankdir仅适用于图表级
  • 节点可能只属于一个群集

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

给出

enter image description here