2016-11-12 187 views
0

下面的graphviz代碼生成梯形圖,但flow3是曲線。這隻發生在邊緣穿過垂直線時。我怎樣才能使flow3平直和水平?我試着用splines屬性試驗沒有成功。如何改變代碼以強制通過其他對象的直線?如何使GraphViz梯形圖流向直線

enter image description here

digraph ladder { ranksep=".1"; nodesep=".1"; 

# Define the defaults 
    node [shape=point fontsize=10] 
    edge [dir=none fontsize=10] 

# Column labels 
    a [shape=none] 
    b [shape=none] 
    c [shape=none] 
    d [shape=none] 

# Draw the 4 column headings, no line 
    { rank=same; edge[style=invis] a -> b -> c -> d } 

# Draw the columns 
    a -> a1 [style=invis] 
    b -> b1 [style=invis] 
    c -> c1 [style=invis] 
    d -> d1 [style=invis] 
    a1 -> a2 -> a3 -> a4 [weight=1000 label=" "] 
    b1 -> b2 -> b3 -> b4 [weight=1000 label=" "] 
    c1 -> c2 -> c3 -> c4 [weight=1000 label=" "] 
    d1 -> d2 -> d3 -> d4 [weight=1000 label=" "] 

# Now each step in the ladder 
    { rank=same; a1 -> b1 [dir=forward label="Flow1"] } 
    { rank=same; b2 -> c2 [dir=forward label="Flow2"] } 
    { rank=same; b3 -> d3 [dir=forward label="Flow3"] } 
    { rank=same; c4 -> d4 [dir=back label="Flow4"] } 
} 

編輯每評論更新。

運行GraphViz版本2.38.0。

樣條線屬性稍微改變了結果。只有第一行代碼被改變,這樣的:

digraph ladder { ranksep=".1"; nodesep=".1"; splines=false; 

有了這個結果時花鍵被禁用:

enter image description here

+1

什麼GraphViz的版本是您使用?你還可以添加「樣條」屬性的實驗嗎?從文檔中,我假設你必須將它設置爲「false」的圖形。 – Insac

+0

感謝評論Insac。我相應地更新了這個問題。 – Steve

+0

我可以建議你向Graphwiz團隊發佈問題嗎?有一個關於「迂迴路線」的相關問題(我的回答中的鏈接),但它們指的是邊緣的標籤會影響其他邊緣(在這種情況下,受影響的邊緣是帶有標籤的邊緣) – Insac

回答

1

這裏是另外一個可能的解決方案。也是一個黑客。它涉及將彎曲流分成多個較小的直線流。

更改此:

{ rank=same; b3 -> d3 [dir=forward label="Flow3"] } 

這樣:

{ 
    rank=same; 
    b3 -> c3 [dir=none] 
    c3 -> d3 [dir=forward label="Flow3"] 
    } 

也做了一些其他不相關的改進,使節點不可見,垂直邊緣點綴。因此,完整的代碼是這樣的:

digraph ladder { ranksep=".1"; nodesep=".1"; 

# Define the defaults 
    node [shape=point fontsize=10] 
    edge [dir=none fontsize=10] 

# Column labels 
    a [shape=none] 
    b [shape=none] 
    c [shape=none] 
    d [shape=none] 

# Draw the 4 column headings, no line 
    { rank=same; edge[style=invis] a -> b -> c -> d } 

# Draw the columns 
    node [style=invis] 
    a -> a1 [style=invis] 
    b -> b1 [style=invis] 
    c -> c1 [style=invis] 
    d -> d1 [style=invis] 
    a1 -> a2 -> a3 -> a4 [style=dotted weight=1000 label=" "] 
    b1 -> b2 -> b3 -> b4 [style=dotted weight=1000 label=" "] 
    c1 -> c2 -> c3 -> c4 [style=dotted weight=1000 label=" "] 
    d1 -> d2 -> d3 -> d4 [style=dotted weight=1000 label=" "] 

# Now each step in the ladder 
    { rank=same; a1 -> b1 [dir=forward label="Flow1"] } 
    { rank=same; b2 -> c2 [dir=forward label="Flow2"] } 
    { 
    rank=same; 
    b3 -> c3 [dir=none] 
    c3 -> d3 [dir=forward label="Flow3"] 
    } 
    { rank=same; c4 -> d4 [dir=back label="Flow4"] } 
} 

,所得梯形圖是這樣的:

enter image description here

1

好吧,這個問題似乎是邊緣b3 -> d3試圖避免它自己的標籤(可能與此issue有關)。

所以這是一個可怕的黑客來解決這一問題:

digraph ladder { ranksep=".1"; nodesep=".1"; splines="line"; 

# Define the defaults 
    node [shape=point fontsize=10] 
    edge [dir=none fontsize=10] 

# Column labels 
    a [shape=none] 
    b [shape=none] 
    c [shape=none] 
    d [shape=none] 

# Draw the 4 column headings, no line 
    { rank=same; edge[style=invis] a -> b -> c -> d } 

# Draw the columns 
    a -> a1 [style=invis] 
    b -> b1 [style=invis] 
    c -> c1 [style=invis] 
    d -> d1 [style=invis] 

    a1 -> a2 -> a3 -> a4 [weight=1000 label=" "] 
    b1 -> b2 -> b3 -> b4 [weight=1000 label=" "] 
    c1 -> c2 -> c3 -> c4 [weight=1000 label=" "] 
    d1 -> d2 -> d3 -> d4 [weight=1000 label=" "] 

    # inserted a label for the node that "pretends" to be the edge label 
    c3 [xlabel="Flow3"] 

# Now each step in the ladder 
    { rank=same; a1 -> b1 [dir=forward label="Flow1"] } 
    { rank=same; b2 -> c2 [dir=forward label="Flow2"] } 
    { rank=same; b3 -> d3 [dir=forward ] } #removed the label 
    { rank=same; c4 -> d4 [dir=back label="Flow4"] } 
} 

的變化是:

  1. 加入spline=line指令
  2. 刪除從邊緣 「FLOW3」 標籤(即修改將邊緣轉回到直線)
  3. c3節點添加了「Flow3」標籤

這就是最後的結果:

enter image description here

+0

謝謝你insac。我發現了另一個解決方案,我將作爲答案發布。 – Steve