2011-04-21 43 views
4

enter image description here的graphviz:如何防止集羣從overrinding排名= source語句

下面的代碼產生上圖:

digraph G { 


//---graph config 

    fontname=Helvetica 

    rankdir = RL 
    splines = polyline 
    compound = true 
    //concentrate = true 

    labeljust = c 
    labelloc = t 

    ranksep=0.5 
    nodesep=0.5 

    //size="10,10" 
    ratio=compress 

    edge [ 
     minlen=1 
     arrowsize=0.75 
     labeldistance=5  

     fontname=Helvetica 
     fontsize=12 
     fontcolor=black  

     labelfontsize=12 
     labelfontcolor=red 
     labelfontname=Helvetica 


     ] 


    node [ 
     fontname=Helvetica 
     fontsize=12 
     fontcolor=black 

     regular=true 
     shape=diamond 
     // width=0.25 
     // height=0.25 
     ] 



// --- # nodes 

{// records 
node [shape=record, width=1] 


b10 [label=" { R-7 | 5 } | B/10 "] 
b20 [label=" { R-6 | 10 } | B/20 "] 
b30 [label=" { R-5 | 10 } | B/30 "] 
d10 [label=" { R-10 | 15 } | D/10 "] 
d20 [label=" { R-9 | 10 } | D/20 "] 
d30 [label=" { R-8 | 10 } | D/30 "] 
a20 [label=" { R-2 | 5 } | A/20 "] 
a30 [label=" { R-1 | 10 } | A/30 "] 

} 

{// circles 
node [shape=circle] 
e [label="E"] 
c [label="C"] 
} 

{// box 
node [shape=box] 
a [label="A"] 
} 


//--- # edges 

{ 
edge [weight = 1000] 

//straight 
c -> b10 -> b20 -> b30 
e -> d10 -> d20 -> d30 
a20 -> a30 -> a 

//combination 
{b30 d30} -> a20 
} 


//--- # Clusters 

// subgraph cluster_1{ 
// label="a " 
// e d10 d20 
// } 

// subgraph cluster_2{ 
// label="b " 
// c b10 b20 b30 
// } 

// subgraph cluster_3{ 
// label="c " 
// a30 a20 
// } 



// --- # bugfixes 

{// c before e 
edge [style=invis] 
c -> e 


{rank=source e c} // force same rank before other nodes 
} 



} 

這是完全一樣的漂亮,乾淨,我希望它是。 但是,我希望能夠對結構的某些部分進行標記和評論,並且我認爲集羣應該是正確的方法。

如果您取消註釋你得到下面的代碼和相應的圖形代碼的集羣部分:

digraph G { 


//---graph config 

    fontname=Helvetica 

    rankdir = RL 
    splines = polyline 
    compound = true 
    //concentrate = true 

    labeljust = c 
    labelloc = t 

    ranksep=0.5 
    nodesep=0.5 

    //size="10,10" 
    ratio=compress 

    edge [ 
     minlen=1 
     arrowsize=0.75 
     labeldistance=5  

     fontname=Helvetica 
     fontsize=12 
     fontcolor=black  

     labelfontsize=12 
     labelfontcolor=red 
     labelfontname=Helvetica 


     ] 


    node [ 
     fontname=Helvetica 
     fontsize=12 
     fontcolor=black 

     regular=true 
     shape=diamond 
     // width=0.25 
     // height=0.25 
     ] 



// --- # nodes 

{// records 
node [shape=record, width=1] 


b10 [label=" { R-7 | 5 } | B/10 "] 
b20 [label=" { R-6 | 10 } | B/20 "] 
b30 [label=" { R-5 | 10 } | B/30 "] 
d10 [label=" { R-10 | 15 } | D/10 "] 
d20 [label=" { R-9 | 10 } | D/20 "] 
d30 [label=" { R-8 | 10 } | D/30 "] 
a20 [label=" { R-2 | 5 } | A/20 "] 
a30 [label=" { R-1 | 10 } | A/30 "] 

} 

{// circles 
node [shape=circle] 
e [label="E"] 
c [label="C"] 
} 

{// box 
node [shape=box] 
a [label="A"] 
} 


//--- # edges 

{ 
edge [weight = 1000] 

//straight 
c -> b10 -> b20 -> b30 
e -> d10 -> d20 -> d30 
a20 -> a30 -> a 

//combination 
{b30 d30} -> a20 
} 


//--- # Clusters 

subgraph cluster_1{ 
label="a " 
e d10 d20 
} 

subgraph cluster_2{ 
label="b " 
c b10 b20 b30 
} 

subgraph cluster_3{ 
label="c " 
a30 a20 
} 



// --- # bugfixes 

{// c before e 
edge [style=invis] 
c -> e 


{rank=source e c} // force same rank before other nodes 
} 



} 

enter image description here

你可以從錯誤修正部分在我想要的代碼的末尾看到節點C和E肯定會出現在所有其他節點「上方」的同一等級上。

Furhtermore,我想記錄的上部和下部序列與第一個例子中的直線相連。我介紹的邊緣的重量不起作用。

有沒有人知道如何解決這個問題,以及如何使graphviz產生一個很好的乾淨的圖,如只有3個擁抱框和相應的標籤添加示例#1?

回答

2

我試圖只修改需要什麼:

  • 添加不含標籤和style=invis(對於D30)其他羣集
  • 改變了節點的順序爲具有簇上面的b集羣
  • 邊緣weigth刪除
  • 錯誤修正部分去掉
  • 一些換行符刪除

這就是我得到一個最新的Graphviz版本(2.29):

enter image description here

並不完美,但拉近了許多。

digraph G { 
//---graph config 

    fontname=Helvetica 

    rankdir = RL 
    splines = polyline 
    compound = true 
    //concentrate = true 

    labeljust = c 
    labelloc = t 

    ranksep=0.5 
    nodesep=0.5 

    //size="10,10" 
    ratio=compress 

    edge [ 
     minlen=1 
     arrowsize=0.75 
     labeldistance=5  

     fontname=Helvetica 
     fontsize=12 
     fontcolor=black  

     labelfontsize=12 
     labelfontcolor=red 
     labelfontname=Helvetica 
     ] 

    node [ 
     fontname=Helvetica 
     fontsize=12 
     fontcolor=black 

     regular=true 
     shape=diamond 
     // width=0.25 
     // height=0.25 
     ] 

// --- # nodes 

{// records 
node [shape=record, width=1] 

d10 [label=" { R-10 | 15 } | D/10 "] 
d20 [label=" { R-9 | 10 } | D/20 "] 
d30 [label=" { R-8 | 10 } | D/30 "] 
b10 [label=" { R-7 | 5 } | B/10 "] 
b20 [label=" { R-6 | 10 } | B/20 "] 
b30 [label=" { R-5 | 10 } | B/30 "] 
a20 [label=" { R-2 | 5 } | A/20 "] 
a30 [label=" { R-1 | 10 } | A/30 "] 
} 

{// circles 
node [shape=circle] 
e [label="E"] 
c [label="C"] 
} 

{// box 
node [shape=box] 
a [label="A"] 
} 

//--- # edges 

{ 

//straight 
c -> b10 -> b20 -> b30 
e -> d10 -> d20 -> d30 
a20 -> a30 -> a 

//combination 
{b30 d30} -> a20} 

//--- # Clusters 


subgraph cluster_1{ 
label="a " 
e d10 d20 
} 

subgraph cluster_2{ 
label="b " 
c b10 b20 b30 
} 

subgraph cluster_3{ 
label="c " 
a30 a20 
} 

subgraph cluster_4{ 
label="" 
style=invis 
d30 
} 

} 
+0

這正是我正在尋找的解決方案。適合我!謝謝!我會仔細看看你的修復。大! – user522315 2011-05-19 09:27:43

+0

是否有某個規則告訴我爲什麼要在其他人之前定義D節點,儘管我希望它們出現在圖的底部?還是你只是在定義之前洗牌? – user522315 2011-05-19 18:53:10

+0

通常,除了佈局需要優化之外,相同級別上的節點按照它們定義的順序出現。使用'digraph {a; b - > {c; d;}; e;}'來玩:移除e,a放在左邊;刪除一個,e被放置正確;切換順序爲c和d,並切換位置。當您更改rankdir時,所有內容都會隨着rankdir而改變。更復雜的圖形通常無法預測,然後在使用某些選項或形狀(記錄)時存在一個或另一個錯誤和限制。所以它不是簡單地在節點周圍洗牌,但我總是需要視覺確認來確保;-) – marapet 2011-05-19 19:37:01