2014-11-23 84 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 
}