2014-11-23 61 views
6

我得到了这个点图,并希望节点A和D,B和E以及C和F对齐。下面是相关的点代码:Graphviz节点的点垂直对齐

digraph{ 

A 
B 
C 
D 
E 
F 

{rank = same; B; C} 
{rank = same; E; F} 

A -> B [label="2", weight=2] 
A -> C [label="0", style=dashed, weight=2] 
B -> C [label="0", style=dashed, weight=2] 
B -> D [label="2", style=dashed, weight=2] 
C -> D [label="0", weight=2] 
D -> E [label="1", style=dashed, weight=2] 
D -> F [label="0", weight=2] 
E -> F [label="0", weight=2] 
F -> A 
} 

正如你可以看到我已经尝试过的权重应用到边缘,但没有制定出

enter image description here

回答

16

有可能使用group节点的属性,建议用同一条直线排列同一组节点之间的边缘。

声明节点与组属性:

A [group=g1] 
{rank = same; B[group=g2]; C[group=g3]} 
D [group=g1] 
{rank = same; E[group=g2]; F[group=g3]} 

然后确保所有的节点都具有它们之间的(看不见的)边缘:

edge[style=invis]; 
A -> D 
B -> E 
C -> F 

一切融合在一起:

digraph G { 
    A [group=g1] 
    {rank = same; B[group=g2]; C[group=g3]} 
    D [group=g1] 
    {rank = same; E[group=g2]; F[group=g3]} 

    A -> B [label="2", weight=2] 
    A -> C [label="0", style=dashed, weight=2] 
    B -> C [label="0", style=dashed, weight=2] 
    B -> D [label="2", style=dashed, weight=2] 
    C -> D [label="0", weight=2] 
    D -> E [label="1", style=dashed, weight=2] 
    D -> F [label="0", weight=2] 
    E -> F [label="0", weight=2] 
    F -> A 

    edge[style=invis]; 
    A -> D 
    B -> E 
    C -> F 
}