Graphviz - 盒子定位问题

时间:2011-06-24 09:27:43

标签: graphviz

我的结构有两个主链,子图中有侧节点。每件事看起来都不错但是当我关闭两个链时,子图中的所有方框都跳到右侧。 在我的代码结束时,您可以删除“我” - >“J”,然后您可以看到我的意思。 我不是母语为英语的人,对我的英语很抱歉,我是一个graphviz新手。

digraph G {
    size ="6,6";
    node [color=black fontsize=12, shape=box, fontname=Helvetica];

subgraph {
    rank = same;
    "b"->"B"[arrowhead=none];
    }

subgraph {
    rank=same;
    "c"->"C"[arrowhead=none];
    }

subgraph {
        rank=same;
        "e"->"E" [arrowhead=none];
    }

subgraph {
    rank = same;
    "f"->"F"[arrowhead=none];
}

subgraph {
    rank = same;
    "g"->"G"[arrowhead=none];
}

"0" -> "A" -> "B" -> "C"->"D" -> "E" -> "F" -> "G" -> "H"->"I";
"0" -> "K"->"L"->"M"->"N"->"O" ->"P"->"1";

subgraph {
    rank = same;
    "L"->"l"[arrowhead=none];
}

subgraph {
    rank=same;
    "M"->"m"[arrowhead=none];
}

subgraph {
    rank=same;
    "N"->"n" [arrowhead=none];
}

subgraph {
    rank = same;
    "O"->"o"[arrowhead=none];
}

subgraph {
    rank = same;
    "P"->"p"[arrowhead=none];
}

"1"->"J";
"I"->"J";
}

enter image description here


并删除了"I"->"J";

enter image description here

1 个答案:

答案 0 :(得分:5)

我就是这样做的:为每个主链及其侧节点创建一个集群:

digraph G {
    size ="6,6";
    node [color=black fontsize=12, shape=box, fontname=Helvetica];

    subgraph[style=invis];

    subgraph cluster0 {
        A -> B -> C -> D -> E -> F -> G -> H -> I;
        edge[arrowhead=none];
        {rank = same; b->B;}
        {rank = same; c->C;}
        {rank = same; e->E;}
        {rank = same; f->F;}
        {rank = same; g->G;}
    }

    subgraph cluster1 {
        K -> L -> M -> N -> O -> P -> 1 -> J;
        edge[arrowhead=none];
        {rank = same; L->l;}
        {rank = same; M->m;}
        {rank = same; N->n;}
        {rank = same; O->o;}
        {rank = same; P->p;}
    }
    0 -> A;
    0 -> K;
    I -> J;
}

导致:

graphviz output