2013-05-18 107 views
3
加入子圖的節點

我給輸入以下以點:垂直對齊的Graphviz的

digraph G { 
    subgraph cluster1 { 
    fontsize = 20; 
    label = "Group 1"; 
    A -> B -> C -> D; 
    style = "dashed"; 
    } 

    subgraph { 
    O [shape=box]; 
    } 

    subgraph cluster2 { 
    fontsize = 20; 
    label = "Group 2"; 
    Z -> Y -> X -> W [dir=back]; 
    style = "dashed"; 
    } 

    D -> O [constraint=false]; 
    W -> O [constraint=false, dir=back]; 
} 

它產生:

picture with node O aligned with A and Z

我該如何調整節點O使其具有與DW相同?也就是說,看起來像一個圖:添加

A Z 
| | 
B Y 
| | 
C X 
| | 
D-O-W 

{ rank=same; D; O; W; } 

產生錯誤

Warning: D was already in a rankset, ignored in cluster G 
Warning: W was already in a rankset, ignored in cluster G 

我想我可以通過增加無形的節點和邊緣的本事子圖O,但我想知道我是否錯過了一些Dot魔法。

回答

12

你可以使用的方法有rankdir=LR和使用constraint=false的邊緣集羣內:

digraph G { 
    rankdir=LR; 

    subgraph cluster1 { 
    fontsize = 20; 
    label = "Group 1"; 
    rank=same; 
    A -> B -> C -> D [constraint=false]; 
    style = "dashed"; 
    } 

    subgraph cluster2 { 
    fontsize = 20; 
    label = "Group 2"; 
    rank=same; 
    Z -> Y -> X -> W [dir=back, constraint=false]; 
    style = "dashed"; 
    } 

    O [shape=box]; 
    D -> O -> W; 
} 

這不是魔術點:-),但它成功完成了:

graphviz output with rankdir LR

用隱形節點進行黑客攻擊也起作用:

digraph G { 
    subgraph cluster1 { 
    fontsize = 20; 
    label = "Group 1"; 
    A -> B -> C -> D; 
    style = "dashed"; 
    } 

    subgraph { 
    O1[style=invis]; 
    O2[style=invis]; 
    O3[style=invis]; 
    O [shape=box]; 

    O1 -> O2 -> O3 -> O [style=invis]; 
    } 

    subgraph cluster2 { 
    fontsize = 20; 
    label = "Group 2"; 
    Z -> Y -> X -> W [dir=back]; 
    style = "dashed"; 
    } 

    edge[constraint=false]; 
    D -> O -> W; 
} 

結果幾乎是相同的:

graphviz output with invisible nodes

+0

感謝您的提示和翔實的答覆!我原本用無形的節點入侵它,但已經轉向了第一種解決方案。感覺更優雅,完美的作品。 – shadowmatter