2017-05-31 46 views
2

我有一張以樹爲骨架的圖。所以我有,例如一個節點A與孩子B,C和D.假設圖形是自上而下繪製,A將在一個級別,然後B,C和D.我想強制graphviz按照B,C,D順序排列。這可能嗎?如果是這樣,怎麼樣?如何在graphviz的點中控制級別節點順序?

如果只有A,B,C和D,我可以通過在輸入點文件中按順序放置B,C和D來獲得此效果。但是,如果B,C和/或D中有其他邊緣,有時這些訂單會被加擾。這是我想避免的。

回答

0

這可以通過如圖所示的「不可見」邊緣來實現。請注意描述它是如何工作的評論。

digraph test{ 

// make invisible ranks 
rank1 [style=invisible]; 
rank2 [style=invisible]; 

// make "invisible" (white) link between them 
rank1 -> rank2 [color=white]; 

// declare nodes all out of desired order 
A -> D; 
A -> B; 
A -> C; 
A -> E; 

// even these new connection don't mess up the order 
B -> F -> G; 
C -> F -> G; 

{ 
rank = same; 
// Here you enforce the desired order with "invisible" edges and arrowheads 
rank2 -> B -> C -> D -> E [ style=invis ]; 
rankdir = LR; 
} 
} 

enter image description here