强制GraphViz将子图一个对齐

时间:2017-03-04 14:11:20

标签: graphviz subgraph

我有一个图表,其中有3个子图放在一起,我希望它们一个堆叠在一起(我不希望子图内容的方向改变)。 / p>

简单的例子:



digraph G {
rankdir=TB;
    subgraph cluster_lkg{
        subgraph cluster_sentence_1{
            "A1","A2","A3"
            "A1" -> "A2"
            "A1" -> "A3"
        }
        subgraph cluster_concepts_1{
            "B1","B2","B3"
            "B1" -> "B2"
            "B1" -> "B3"
        }
    }
    subgraph cluster_fkgs{
            "C1","C2","C3"
            "C1" -> "C2"
            "C1" -> "C3"
    }

}




1 个答案:

答案 0 :(得分:0)

您需要连接群集​​(或者更确切地说,群集中的节点)才能使rankdir = TB生效。您可以使用隐形边缘来完成此操作:

digraph G 
{
    rankdir=TB;    
    subgraph cluster_lkg
    {
        subgraph cluster_sentence_1
        {
            "A1","A2","A3"
            "A1" -> "A2"
            "A1" -> "A3"
        }
        subgraph cluster_concepts_1{
            "B1","B2","B3"
            "B1" -> "B2"
            "B1" -> "B3"
        }
        //A1 -> B1;
    }
    subgraph cluster_fkgs
    {
            "C1","C2","C3"
            "C1" -> "C2"
            "C1" -> "C3"
    }
    edge[ style = invis ];
    { A2 A3 } -> B1;
    { B2 B3 } -> C1;
}

产生

enter image description here

节点C1未对齐 - 我想这来自嵌套群集,但我没有反对它的配方。希望它无论如何都有帮助。