2014-04-26 273 views
3

我已經減少我的問題,以下面的簡單的例子:Graphviz的邊緣不可辨/邊緣標籤覆蓋

digraph { 
subgraph {rank=same; 0 -> 1 -> 2;} 
0 -> 2 [label="A"]; 
2 -> 0 [label="B"]; 
} 

產生

enter image description here

雖然在保持0,1和2相同的等級(最初的例子是在更大的圖的背景下),我需要A和B的邊緣可以辨別。即邊緣與標籤和標籤清晰地匹配以便可讀。

一個解決方案我想象的是使用由

0:ne -> 2:nw [label="A"]; 
2:sw -> 0:se [label="B"]; 

指定的邊緣連接端口,但是這會產生

enter image description here

其他的想法?我正在生成具有相同問題的較大圖表,因此最佳解決方案不會是完全特定的手動放置邊緣/標籤。

編輯:較大生成圖的一個(仍簡化)示例如下。

digraph { 
size = "6,8.5"; 
ratio = "fill"; 
node [shape = circle]; 
node [fontsize = 24]; 
edge [fontsize = 24]; 
{graph [rank=same]; edge[color=invis];1;} 
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;} 
0 -> 0 [label="6: 0.1764"]; 
0 -> 4 [label="4: 0.1304"]; 
0 -> 3 [label="5: 0.1551"]; 
0 -> 2 [label="7: 0.1489"]; 
0 -> 1 [label="Z: 0.3893"]; 
4 -> 0 [label="6: 0.1237"]; 
4 -> 3 [label="5: 0.05201"]; 
4 -> 2 [label="7: 0.15 "]; 
4 -> 1 [label="Z: 0.4585"]; 
3 -> 0 [label="6: 0.1658"]; 
3 -> 4 [label="4: 0.13 "]; 
3 -> 3 [label="5: 0.1038"]; 
3 -> 2 [label="7: 0.1616"]; 
3 -> 1 [label="Z: 0.4388"]; 
2 -> 0 [label="6: 0.1661"]; 
2 -> 4 [label="4: 0.1295"]; 
2 -> 3 [label="5: 0.2078"]; 
2 -> 2 [label="7: 0.1406"]; 
2 -> 1 [label="Z: 0.356 "]; 
1 -> 0 [label="6: 0.1103"]; 
1 -> 4 [label="4: 0.2591"]; 
1 -> 3 [label="5: 0.1382"]; 
1 -> 2 [label="7: 0.08581"]; 
1 -> 1 [label="Z: 0.1906"]; 
} 

這產生:

enter image description here

其顯示在上述簡單的示例相同的邊緣/標籤的重疊問題。

其他說明:

  • 當存在在同一等級的子圖一雙向連接一對節點的中間節點存在此問題。這可能是發現錯誤的條件的一個子集。
  • 這個問題也存在於無向圖中。

回答

0

來自ssteveemden的答案非常有用,並且已被提升。 (謝謝你們兩位!)

我將來自兩者的輸入並在其更復雜的版本中回答此問題。我仍然不認爲解決方案是完美的,但這是迄今爲止我可以創造的最好的解決方案。未來的答案可以改進(見下面的內容似乎仍然缺乏),並且以可自動化的方式處理較大的圖形版本(請參見問題)將被接受來代替此答案。

首先,在總結到目前爲止最好的解決方案:轉標籤到xlabels爲邊緣的一些(例如所有雙向邊的一半,隨機選擇的),隨機顏色邊緣和相應的標籤(通過fontcolor)。

在具體的,這裏是此解決方案,其中邊緣是隨機的紅色,綠色或黑色的一個實例:

digraph { 
size = "6,10.5"; 
ratio = "fill"; 
node [shape = circle]; 
node [fontsize = 24]; 
edge [fontsize = 24]; 
{graph [rank=same]; edge[color=invis];1;} 
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;} 
0 -> 0 [label="6: 0.1764"]; 
0 -> 4 [xlabel="4: 0.1304" color=blue fontcolor=blue]; 
0 -> 3 [xlabel="5: 0.1551" color=green fontcolor=green]; 
0 -> 2 [label="7: 0.1489" color=red fontcolor=red]; 
0 -> 1 [label="Z: 0.3893"]; 
4 -> 0 [xlabel="6: 0.1237" color=green fontcolor=green]; 
4 -> 3 [xlabel="5: 0.05201 " color=green fontcolor=green]; 
4 -> 2 [xlabel="7: 0.15" color=blue fontcolor=blue]; 
4 -> 1 [label="Z: 0.4585" color=red fontcolor=red]; 
3 -> 0 [xlabel="6: 0.1658"]; 
3 -> 4 [xlabel="4: 0.13" color=red fontcolor=red]; 
3 -> 3 [label="5: 0.1038" color=blue fontcolor=blue]; 
3 -> 2 [xlabel="7: 0.1616"]; 
3 -> 1 [label="Z: 0.4388"]; 
2 -> 0 [label="6: 0.1661" color=blue fontcolor=blue]; 
2 -> 4 [xlabel="4: 0.1295" color=red fontcolor=red]; 
2 -> 3 [label="5: 0.2078" color=green fontcolor=green]; 
2 -> 2 [label="7: 0.1406"]; 
2 -> 1 [label="Z: 0.356 "]; 
1 -> 0 [label="6: 0.1103" color=red fontcolor=red]; 
1 -> 4 [label="4: 0.2591" color=blue fontcolor=blue]; 
1 -> 3 [label="5: 0.1382" color=green fontcolor=green]; 
1 -> 2 [label="7: 0.08581 "]; 
1 -> 1 [label="Z: 0.1906"]; 
} 

這產生: enter image description here

這仍然是不能完全令人滿意的,因爲:

  1. 雖然現在更容易將標籤追溯到其邊緣,但使用xlabel時,某些標籤會出現在奇怪的位置。 (例如在2 - > 4標籤上方)
  2. 隨機選擇哪些標籤變爲xlables看起來是任意的。也沒有辦法(我知道),以保證這總是會解決。

其他的事情我想:

  • 使每一個標籤的xlabel。結果:一切都被壓縮,標籤彼此重疊並模糊。
  • 對所有雙向邊使用xlabel。結果:與上面相同的問題。
  • 使用不帶顏色的xlabels。結果:很難追蹤哪個標籤屬於什麼。
  • 使用ssteve的dir="both" + colorlist solution。隨機顏色邊緣。並且在3和11之間隨機設置labeldistance來標識頭部和尾部標籤,以避免節點處的標籤重疊。結果:這很難自動化,並且仍然導致邊緣標籤重疊和難以追溯到它們對應邊緣的標籤。 (見下文)

下面是上述「我嘗試過的其他事情」解決方案列表中最後一項的示例。

size = "6,8.5"; 
ratio = "fill"; 
node [shape = circle]; 
node [fontsize = 24]; 
edge [fontsize = 24]; 
{graph [rank=same]; edge[color=invis];1;} 
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;} 
0 -> 0 [label="6: 0.1764"]; 
0 -> 4 [dir="both", color="yellow:blue", labeldistance="5", headlabel=<<font color="yellow">4: 0.1304</font>>, taillabel=<<font color="blue">6: 0.1237</font>>]; 
0 -> 3 [dir="both", color="blue:black", labeldistance="8", headlabel=<<font color="blue">5: 0.1551</font>>, taillabel=<<font color="black">6: 0.1658</font>>]; 
0 -> 1 [label="Z: 0.3893"]; 
4 -> 1 [label="Z: 0.4585"]; 
3 -> 4 [dir="both", color="green:red", labeldistance="5", headlabel=<<font color="green">4: 0.13</font>>, taillabel=<<font color="red">5: 0.05201</font>>]; 
3 -> 3 [label="5: 0.1038"]; 
3 -> 1 [label="Z: 0.4388"]; 
2 -> 0 [dir="both", color="yellow:blue", labeldistance="11", headlabel=<<font color="yellow">6: 0.1661</font>>, taillabel=<<font color="blue">7: 0.1489</font>>]; 
2 -> 4 [dir="both", color="black:red", labeldistance="5", headlabel=<<font color="black">4: 0.1295</font>>, taillabel=<<font color="red">7: 0.15</font>>]; 
2 -> 3 [dir="both", color="blue:green", labeldistance="8", headlabel=<<font color="blue">5: 0.2078</font>>, taillabel=<<font color="green">7: 0.1616</font>>]; 
2 -> 2 [label="7: 0.1406"]; 
2 -> 1 [label="Z: 0.356 "]; 
1 -> 0 [label="6: 0.1103"]; 
1 -> 4 [label="4: 0.2591"]; 
1 -> 3 [label="5: 0.1382"]; 
1 -> 2 [label="7: 0.08581 "]; 
1 -> 1 [label="Z: 0.1906"]; 
} 

這將產生:

enter image description here

其他的想法/改進徵求...

1

您可以通過dir="both"colorList獲得部分路徑。

digraph { 
    subgraph {rank=same; 0 -> 1 -> 2;} 
    0 -> 2 [dir="both", color="black:gray", labeldistance="2", headlabel="A", taillabel="B"]; 
} 

結果在此:

using dir="both"

我不得不用labelDistance保持了 「A」 的標籤從箭頭的頂部被吸引。不幸的是,我無法弄清楚如何爲頭標和尾標分別更改字體顏色,以便更清楚地知道哪個標籤適用於哪個箭頭。

2

第一個例子顯然是一個bug;邊緣標籤應該放置在不同的位置,然後將邊緣分開。 (通常,我們知道平面邊緣代碼中存在漏洞,特別是處理標籤。)一個解決辦法是把部分或全部的邊緣標籤的外觀標籤:

digraph { 
subgraph {rank=same; 0 -> 1 -> 2;} 
0 -> 2 [xlabel="A"]; 
2 -> 0 [xlabel="B"]; 
} 

關於改變在前面的回答中提到標籤的字體顏色的問題,這可以通過使用類似HTML的標籤來完成:

0 -> 2 [dir="both", color="black:gray", labeldistance="2", 
    headlabel=<<font color="red">A</font>>, taillabel="B"]; 

這可以用於任何文本,而不是通常的雙引號字符串。