2016-09-06 51 views
4

我有几个相关的子图我想在GraphViz中绘制在一起。当我画一些简单的节点,它看起来很漂亮:集群挤压GraphViz中的节点

enter image description here

来源:

digraph { 
    rankdir=LR; 

    A1 -> A21; 
    A1 -> A22; 
    A1 -> A23; 
    A1 -> A24; 

    B1 -> B21; 
    B1 -> B22; 
    B1 -> B23; 
    B1 -> B24; 

    A21 -> A31; 
    A22 -> A31; 
    A23 -> A31; 

    A23 -> A32; 

    B21 -> B31; 

    B21 -> B32; 
    B22 -> B32; 

    B21 -> B33; 
    B23 -> B33; 
} 

如跨越几个子图都与同级别的节点,我想他们组给它一个标签。 我尝试使用集群来做到这一点,但它“挤压”的节点:

enter image description here

来源:

digraph { 
    rankdir=LR; 

    subgraph cluster_level1 { 
    label = "Level 1"; 
    style=filled; 
    color=lightgrey; 

    A1; 
    B1; 
    } 

    subgraph cluster_level2 { 
    label = "Level 2"; 
    style=filled; 
    color=lightgrey; 

    A21; 
    A22; 
    A23; 
    A24; 

    B21; 
    B22; 
    B23; 
    B24; 
    } 

    subgraph cluster_level3 { 
    label = "Level 3"; 
    style=filled; 
    color=lightgrey; 

    A31; 
    A32; 

    B31; 
    B32; 
    B33; 
    } 

    A1 -> A21; 
    A1 -> A22; 
    A1 -> A23; 
    A1 -> A24; 

    B1 -> B21; 
    B1 -> B22; 
    B1 -> B23; 
    B1 -> B24; 

    A21 -> A31; 
    A22 -> A31; 
    A23 -> A31; 

    A23 -> A32; 

    B21 -> B31; 

    B21 -> B32; 
    B22 -> B32; 

    B21 -> B33; 
    B23 -> B33; 
} 

只有两个子图,这是不好的,但仍然不可怕。但是,如果我添加更多的子图,则会变得更加丑陋和丑陋。

有没有办法用一些阴影和标签对节点进行分组,同时使用GraphViz保持原始节点布局?

+0

每当我有点问题,我发现最好的办法是在这里发布; http://www.graphviz.org/forum –

回答

3

这可能不是一个很好的答案,因为这意味着大量的试验和错误的,但至少你得到你想要的东西(我猜)与无形的节点:

digraph { 
    rankdir=LR; 

    subgraph cluster_level1 { 
    label = "Level 1"; 
    style=filled; 
    color=lightgrey; 
    A01[ style = invis ]; 
    A1; 
    A02[ style = invis ]; 
    A03[ style = invis ]; 
    A06[ style = invis ]; 
    A05[ style = invis ]; 
    B1; 
    A04[ style = invis ]; 
    } 

    subgraph cluster_level2 { 
    label = "Level 2"; 
    style=filled; 
    color=lightgrey; 

    A21; 
    A22; 
    A23; 
    A24; 

    B21; 
    B22; 
    B23; 
    B24; 
    } 

    subgraph cluster_level3 { 
    label = "Level 3"; 
    style=filled; 
    color=lightgrey; 

    A07[ style = invis ]; 
    A31; 
    A32; 
    A08[ style = invis ];    

    B31; 
    B32; 
    B33; 
    A01[ style = invis ]; 
    A09[ style = invis ]; 
    } 

    A1 -> A21; 
    A1 -> A22; 
    A1 -> A23; 
    A1 -> A24; 

    B1 -> B21; 
    B1 -> B22; 
    B1 -> B23; 
    B1 -> B24; 

    A21 -> A31; 
    A22 -> A31; 
    A23 -> A31; 

    A23 -> A32; 

    B21 -> B31; 

    B21 -> B32; 
    B22 -> B32; 

    B21 -> B33; 
    B23 -> B33; 
} 

产生

enter image description here

+0

我希望有一个更明智的方式来做到这一点,但这是迄今为止最好的方式。谢谢 :) –