2016-09-06 83 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

我希望有一個更明智的方式來做到這一點,但這是迄今爲止最好的方式。謝謝 :) –