7

を使用してグラフを作成しましたdot -Tsvg

これは私が作成したドット言語ファイルです:

digraph genealogy {
    size = "7,7";
    node [fontsize = "10", shape = "box", style="filled", fillcolor="aquamarine"];
    p1 [ fillcolor="aquamarine", label="node" ];
    p2 [ fillcolor="aquamarine", label="node" ];
    p3 [ fillcolor="aquamarine", label="node" ];
    p4 [ fillcolor="aquamarine", label="node" ];
    p5 [ fillcolor="aquamarine", label="node" ];
    p6 [ fillcolor="aquamarine", label="node" ];
    p7 [ fillcolor="aquamarine", label="node" ];
    p8 [ fillcolor="aquamarine", label="node" ];
    p9 [ fillcolor="aquamarine", label="node" ];
    p11 [ fillcolor="aquamarine", label="node" ];
    p12 [ fillcolor="aquamarine", label="node" ];
    p13 [ fillcolor="aquamarine", label="node" ];
    p16 [ fillcolor="aquamarine", label="node" ];
    p17 [ fillcolor="aquamarine", label="node" ];
    b1 [ shape = "point", style="filled", fillcolor="white" ];
    p3 -> b1 [arrowhead = "none", color="red"];
    b2 [ shape = "point", style="filled", fillcolor="white" ];
    p2 -> b2 [arrowhead = "none", color="red"];
    p3 -> b2 [arrowhead = "none", color="red"];
    b3 [ shape = "point", style="filled", fillcolor="white" ];
    p4 -> b3 [arrowhead = "none", color="red"];
    p5 -> b3 [arrowhead = "none", color="red"];
    b4 [ shape = "point", style="filled", fillcolor="white" ];
    p6 -> b4 [arrowhead = "none", color="red"];
    p11 -> b4 [arrowhead = "none", color="red"];
    b2 -> p1 [arrowhead = "onormal", color="red"];
    b3 -> p2 [arrowhead = "onormal", color="red"];
    b3 -> p6 [arrowhead = "onormal", color="red"];
    b3 -> p7 [arrowhead = "onormal", color="red"];
    b4 -> p8 [arrowhead = "onormal", color="red"];
    b4 -> p9 [arrowhead = "onormal", color="red"];
    b1 -> p12 [arrowhead = "onormal", color="red"];
    b1 -> p13 [arrowhead = "onormal", color="red"];
    b1 -> p16 [arrowhead = "onormal", color="red"];
    p4 -> p5 [dir="none", arrowhead = "none",  color="blue"];
    p7 -> p17 [dir="none", arrowhead = "none",  color="blue"];
}

結果は次のとおりです。

青い線で接続されたノードを強制的に並べて(水平に)し、互いに下や別のクレイジーな位置に配置しないようにします。

これは可能ですか?

4

2 に答える 2

7

ランク属性を利用できます。rank="same"またはrank="source"を設定するとhelpfuiになる場合があります。これにより、2つのノードが同じランクまたは最低ランクに配置されます。可能性の1つは次のとおりです。

digraph genealogy {
    size = "7,7";
    node [fontsize = "10", shape = "box", style="filled", fillcolor="aquamarine"];

    subgraph _1 {
     rank="same";
     p4 [ fillcolor="aquamarine", label="node" ];
     p5 [ fillcolor="aquamarine", label="node" ];
     p4 -> p5 [dir="none", arrowhead = "none",  color="blue"];
}
    subgraph _2 {   
    rank="source";  
    p7 [ fillcolor="aquamarine", label="node" ];
    p17 [ fillcolor="aquamarine", label="node" ];
    p7 -> p17 [dir="none", arrowhead = "none",  color="blue"];
}

p1 [ fillcolor="aquamarine", label="node" ];
p2 [ fillcolor="aquamarine", label="node" ];
p3 [ fillcolor="aquamarine", label="node" ];
p6 [ fillcolor="aquamarine", label="node" ];
p8 [ fillcolor="aquamarine", label="node" ];
p9 [ fillcolor="aquamarine", label="node" ];
p11 [ fillcolor="aquamarine", label="node" ];
p12 [ fillcolor="aquamarine", label="node" ];
p13 [ fillcolor="aquamarine", label="node" ];
p16 [ fillcolor="aquamarine", label="node" ];
b1 [ shape = "point", style="filled", fillcolor="white" ];
p3 -> b1 [arrowhead = "none", color="red"];
b2 [ shape = "point", style="filled", fillcolor="white" ];
p2 -> b2 [arrowhead = "none", color="red"];
p3 -> b2 [arrowhead = "none", color="red"];
b3 [ shape = "point", style="filled", fillcolor="white" ];
p4 -> b3 [arrowhead = "none", color="red"];
p5 -> b3 [arrowhead = "none", color="red"];
b4 [ shape = "point", style="filled", fillcolor="white" ];
p6 -> b4 [arrowhead = "none", color="red"];
p11 -> b4 [arrowhead = "none", color="red"];
b2 -> p1 [arrowhead = "onormal", color="red"];
b3 -> p2 [arrowhead = "onormal", color="red"];
b3 -> p6 [arrowhead = "onormal", color="red"];
b3 -> p7 [arrowhead = "onormal", color="red"];
b4 -> p8 [arrowhead = "onormal", color="red"];
b4 -> p9 [arrowhead = "onormal", color="red"];
b1 -> p12 [arrowhead = "onormal", color="red"];
b1 -> p13 [arrowhead = "onormal", color="red"];
b1 -> p16 [arrowhead = "onormal", color="red"];

}

出力はこちら

于 2012-10-25T12:14:42.233 に答える
0

他の答えを短くするために:オプション付きのサブグラフグラフ内に並べて配置したいノードを配置しrank="same"ます。

前:

digraph G {
A, B
    //subgraph {
    //  rank="same"
        C, D
    //}
A -> B -> C -> D
}

前

後:

digraph G {
A, B
    subgraph {
        rank="same"
        C, D
    }
A -> B -> C -> D
}

後

于 2021-10-06T15:14:59.543 に答える