2013-05-18 110 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