2012-09-17 97 views
11

我想繪製一個圓形拓撲圖。Graphviz:如何安排節點與圓形佈局

這裏就是我期待看到: enter image description here

這裏是我的GV文件:

digraph g1 { 
    layout="circo"; 
    node [shape = doublecircle]; N4 N6; 
    node [shape = circle]; 
    N0 -> N1 [ label = "{1,0}"]; 
    N1 -> N2 [ label = "{1,0}"]; 
    N2 -> N3 [ label = "{1,0}"]; 
    N3 -> N4 [ label = "{1,0}"]; 
    N4 -> N5 [ label = "{1,0}"]; 
    N5 -> N6 [ label = "{1,0}"]; 
    N6 -> N0 [ label = "{1,0}"]; 

    N0 -> N4 [ label = "{1,0}"]; 
    N1 -> N5 [ label = "{1,0}"]; 
    N2 -> N6 [ label = "{1,0}"]; 
    N3 -> N0 [ label = "{1,0}"]; 
    N4 -> N1 [ label = "{1,0}"]; 
    N5 -> N2 [ label = "{1,0}"]; 
    N6 -> N3 [ label = "{1,0}"];  
} 

,這裏是對上面的圖形輸出圖像: enter image description here

如何我可以在graphviz中安排節點,使其看起來像1

回答

10

如果目標是要有一個尊重節點順序的圖,那不是那麼簡單。你可以calculate the position of the nodes with an external script and render it with neato

或者你可以先佈局,其中僅確定節點的正確順序的邊緣節點:

digraph g1 { 
    node [shape = doublecircle]; N4 N6; 
    node [shape = circle]; 
    edge[label="{1,0}"]; 
    N0 -> N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N0; 
} 

有:

circo graph.gv > tempgraph.gv 

然後將剩餘的邊緣添加到tempgraph.gv - 只是複製 - 關閉前關閉以下內容}

N0 -> N4 [ label = "{1,0}"]; 
N1 -> N5 [ label = "{1,0}"]; 
N2 -> N6 [ label = "{1,0}"]; 
N3 -> N0 [ label = "{1,0}"]; 
N4 -> N1 [ label = "{1,0}"]; 
N5 -> N2 [ label = "{1,0}"]; 
N6 -> N3 [ label = "{1,0}"]; 

並與neato-n選項使它:

neato -n tempgraph.gv -Tpng -O 

您可能要微調標籤的位置:

circo layout

+0

非常感謝!這正是我試圖達到的目標。 – Filipp

+0

感謝'circo'命令是我想要的,但我現在只嘗試'dot'和'neato',現在我明白了爲什麼我無法獲得圓形佈局! –