I am trying to draw a family tree using the DOT language. I use auxiliary nodes to make the tree look neat, but in some cases, for an unknown reason, one of the nodes is placed in an illogical place at all. In the example below, the location of node J should be next to I, but as you can see, it goes to the far right of the drawing.
我正试着用DOT语言画一张家谱。我使用辅助节点来使树看起来整洁,但在某些情况下,由于未知的原因,其中一个节点被放置在根本不符合逻辑的位置。在下面的示例中,节点J的位置应该在I旁边,但如您所见,它位于图形的最右侧。
Here's my code:
以下是我的代码:
digraph FamilyTree {
edge [dir=none, penwidth=2];
rankdir=TB;
"A" [shape=BOX, ];
"B" [shape=BOX,];
"C" [shape=BOX, ];
"D" [shape=BOX,];
"E" [shape=BOX, ];
"F" [shape=BOX, ];
"c1" [shape=point, label="",width=0.01, height=0.01];
"c1" -> "F" [arrowhead=none];
"G" [shape=BOX, ];
"c2" [shape=point, label="",width=0.01, height=0.01];
"c2" -> "G" ;
"H" [shape=BOX, ];
"I" [shape=BOX, ];
"c3" [shape=point, label="",width=0.01, height=0.01];
"c3" -> "I" ;
"J" [shape=BOX, ];
"c4" [shape=point, label="",width=0.01, height=0.01];
"c4" -> "J" ;
"K" [shape=BOX,];
"c5" [shape=point, label="",width=0.01, height=0.01];
"c5" -> "K" ;
"L" [shape=BOX, ];
"c6" [shape=point, label="",width=0.01, height=0.01];
"c6" -> "L" ;
"M" [shape=BOX, ];
"c7" [shape=point, label="",width=0.01, height=0.01];
"c7" -> "M" ;
"Couple_5780_1" [shape=point, color=gray, label=""];
"Couple_5355_1" [shape=point, color=gray, label=""];
"Couple_8222_1" [shape=point, color=gray, label=""];
"Couple_8222_2" [shape=point, color=gray, label=""];
"Couple_8222_3" [shape=point, color=gray, label=""];
{ rank=same; "A" -> "Couple_5780_1" -> "B" }
{ rank=same; "C" -> "Couple_5355_1" -> "D" }
{ rank=same;"E"->"Couple_8222_1"->"F"->"Couple_8222_2"->"G"->"Couple_8222_3"->"H"}
"c3" -> "c4" [arrowhead=none,constraint=false];
{ rank=same; "c3"; "c4"; }
"c6" -> "c7" [arrowhead=none,constraint=false];
{ rank=same; "c6"; "c7"; }
"Couple_5780_1" -> "c1" ;
"Couple_5355_1" -> "c2";
"Couple_8222_1" -> "c3" ;
"Couple_8222_2" -> "c5";
"Couple_8222_3" -> "c6" ;
}
更多回答
优秀答案推荐
The Graphviz algorithms are complex and sometimes wacky.
Being unable to get dot to keep a desired node sequence is a known issue (https://gitlab.com/graphviz/graphviz/-/issues/1569) with no guaranteed solution, but below is your desired result.
It adds groups (https://www.graphviz.org/docs/attrs/group/) to (try to) force vertical alignment and adds "J" and "c4" to one of the groups to coerce the desired position.
Graphviz的算法很复杂,有时甚至很古怪。无法让点保持所需的节点序列是一个已知问题,(https://gitlab.com/graphviz/graphviz/-/issues/1569)没有保证的解决方案,但下面是您想要的结果。它添加组(https://www.graphviz.org/docs/attrs/group/))以(尝试)强制垂直对齐,并将“J”和“c4”添加到组之一以强制所需位置。
digraph FamilyTree {
edge [dir=none, penwidth=2];
rankdir=TB;
"A" [shape=BOX, ];
"B" [shape=BOX,];
"C" [shape=BOX, ];
"D" [shape=BOX,];
"E" [shape=BOX, ];
"F" [shape=BOX, group=F1];
"c1" [shape=point, label="",width=0.01, height=0.01 group=F1 ];
"c1" -> "F" [arrowhead=none];
"G" [shape=BOX, group=G1];
"c2" [shape=point, label="",width=0.01, height=0.01 group=G1];
"c2" -> "G" ;
"H" [shape=BOX, ];
"I" [shape=BOX, group=I1];
"c3" [shape=point, label="",width=0.01, height=0.01 group=I1];
"c3" -> "I" ;
"J" [shape=BOX, group=F1];
"c4" [shape=point, label="",width=0.01, height=0.01 group=F1];
"c4" -> "J" ;
"K" [shape=BOX,];
"c5" [shape=point, label="",width=0.01, height=0.01];
"c5" -> "K" ;
"L" [shape=BOX, ];
"c6" [shape=point, label="",width=0.01, height=0.01];
"c6" -> "L" ;
"M" [shape=BOX, ];
"c7" [shape=point, label="",width=0.01, height=0.01];
"c7" -> "M" ;
"Couple_5780_1" [shape=point, color=gray, label="" group=F1];
"Couple_5355_1" [shape=point, color=gray, label="" group=G1];
"Couple_8222_1" [shape=point, color=gray, label="" group=I1];
"Couple_8222_2" [shape=point, color=gray, label=""];
"Couple_8222_3" [shape=point, color=gray, label=""];
{ rank=same; "A" -> "Couple_5780_1" -> "B" }
{ rank=same; "C" -> "Couple_5355_1" -> "D" }
{ rank=same;"E"->"Couple_8222_1"->"F"->"Couple_8222_2"->"G"->"Couple_8222_3"->"H"}
"c3" -> "c4" [arrowhead=none, constraint=false]
{ rank=same; "c3"; "c4"; }
"c6" -> "c7" [arrowhead=none,constraint=false];
{ rank=same; "c6"; "c7"; }
"Couple_5780_1" -> "c1" ;
"Couple_5355_1" -> "c2";
"Couple_8222_1" -> "c3" ;
"Couple_8222_2" -> "c5";
"Couple_8222_3" -> "c6" ;
F->c4 [style=invis] // for F1 group
}
Giving:
给予:
更多回答
我是一名优秀的程序员,十分优秀!