Tree 制作graphviz树时,父母都是以孩子为中心的
我有以下graphviz代码:Tree 制作graphviz树时,父母都是以孩子为中心的,tree,drawing,graphviz,Tree,Drawing,Graphviz,我有以下graphviz代码: graph { node[width = 0.6, height = 0.6, fixedsize=true, shape=circle]; a[label="22"]; b[label="22"]; c[label="34"]; d[label="22"]; e[label="99"]; f[label="34"]; g[label="40"]; h[label="37"]; i[l
graph {
node[width = 0.6, height = 0.6, fixedsize=true, shape=circle];
a[label="22"];
b[label="22"];
c[label="34"];
d[label="22"];
e[label="99"];
f[label="34"];
g[label="40"];
h[label="37"];
i[label="22"];
j[label="99"];
k[label="135"];
l[label="129"];
m[label="40"];
edge[penwidth=3.0];
a -- b;
b -- d;
c -- f;
d -- i;
e -- j;
g -- m;
edge[penwidth=1.0];
a -- c;
b -- e;
c -- g;
d -- h;
e -- k;
g -- l;
}
这意味着要绘制一个二叉树,其中一些边高亮显示。然而,这棵树看起来不太对劲——尤其是在树的下面,父母和孩子的安排是这样的:
parent
child child
parent
child child
而我希望它看起来更像这样:
parent
child child
parent
child child
(即,让父母集中在孩子上方,而不是坐在其中一个孩子的上方)。这可能吗?如果可能,我会怎么做?我确实玩了很多,我认为没有完美的解决方案。有一些方法
具有附加不可见边和节点的经典方法。这适用于小图形,但在大图形上会变得非常难看。为了确保这是可行的,您必须用不可见的节点填充整个网格。否则,dot引擎将否决您
我所期望的是这种方法
digraph {
edge [weight=1]
0->L
0->R
edge [weight=10]
L->LL
L->LR
R->RL
R->RR
edge [weight=100]
LL->LLL
LL->LLR
LR->LRL
LR->LRR
RL->RLL
RL->RLR
RR->RRL
RR->RRR
}
不幸的是,事实并非如此。点布局引擎似乎不尝试最小化边缘长度,但仅将水平部分(即子节点之间的任何父位置)视为理想
我试过的另一个是
digraph {
splines=line
style=dotted
edge [weight=1]
subgraph cluster_0 {
subgraph cluster_L {
subgraph cluster_LL {
LLL
LLM [style=dotted]
LLR
LL->LLL
LL->LLM [style=dotted weight=100]
LL->LLR
}
LM [style=dotted]
subgraph cluster_LR {
LRL
LRM [style=dotted]
LRR
LR->LRL
LR->LRM [style=dotted weight=100]
LR->LRR
}
L->LL
L->LM [style=dotted weight=100]
L->LR
}
M [style=dotted]
subgraph cluster_R {
subgraph cluster_RL {
RLL
RLM [style=dotted]
RLR
RL->RLL
RL->RLM [style=dotted weight=100]
RL->RLR
}
RM [style=dotted]
R->RL
R->RM [style=dotted weight=100]
R->RR
}
0->L
0->M [style=dotted weight=100]
0->R
}
}
给
这似乎是可行的,水平顺序取决于外观。但是集群在许多其他构造中表现不好,您必须尝试它是否适合您
如果省略簇,布局将在水平方向上更加紧凑。垂直边仍由不可见的中间节点阻止
digraph {
splines=line
style=dotted
edge [weight=1]
LLL
LLM [style=dotted]
LLR
LL->LLL
LL->LLM [style=dotted weight=100]
LL->LLR
LM [style=dotted]
LRL
LRM [style=dotted]
LRR
LR->LRL
LR->LRM [style=dotted weight=100]
LR->LRR
L->LL
L->LM [style=dotted weight=100]
L->LR
M [style=dotted]
RLL
RLM [style=dotted]
RLR
RL->RLL
RL->RLM [style=dotted weight=100]
RL->RLR
RM [style=dotted]
R->RL
R->RM [style=dotted weight=100]
R->RR
0->L
0->M [style=dotted weight=100]
0->R
}
给
最后还有一件事,ERG为树布局编写的gvpr脚本。您可以在marapets中找到答案的详细信息。按照中的说明,很好地布局二叉树,我得到以下输出: 想不出更好更快的方法