简体   繁体   English

Graphviz 点对齐来自不同等级的节点

[英]Graphviz dot align nodes from different ranks

I'd like to make a graph with parent nodes aligned at the "center" of the children nodes.我想制作一个图,父节点在子节点的“中心”对齐。

For the tree below I get the following image.对于下面的树,我得到以下图像。

graph {
rankdir = "LR"
splines = line
A -- B
A -- C
B -- D
B -- E
C -- F
D -- G
D -- H
D -- I
E -- J
E -- K
F -- L
}

图形图像

I would like to have node D aligned with node H, node E aligned halfway between J and K, and F aligned with L. At the next rank, I'd like to have B aligned halfway between E and D, and C aligned with F. At the top (leftmost) rank, I'd like to have A aligned halfway between B and C.我想让节点 D 与节点 H 对齐,节点 E 在 J 和 K 之间对齐,F 与 L 对齐。在下一个等级,我想让 B 在 E 和 D 之间对齐,C 与F. 在顶部(最左边)排名,我想让 A 在 B 和 C 之间对齐。

Is there a way to make this happen without specifying positions of nodes?有没有办法在不指定节点位置的情况下实现这一点?

Probably not.可能不是。 Even if you included invisible nodes (style=invis), you would still be fighting the dot algorithm.即使你包含了不可见的节点(style=invis),你仍然会与点算法作斗争。 It would be much easier to explicitly specify the X/Y coordinates.明确指定 X/Y 坐标会容易得多。

I couldn't figure out a way to get everything I want, but I got a lot closer.我想不出办法得到我想要的一切,但我离得更近了。

The secrets:秘诀:

  1. Use groups to force horizontal edges (would be vertical in TD rankdir) as shown in Graphviz Dot vertical alignment of nodes使用组来强制水平边缘(在 TD rankdir 中将是垂直的),如Graphviz Dot 节点的垂直对齐所示
  2. Add invisible edges where needed在需要的地方添加不可见的边缘

Note that I couldn't get E where I wanted it, but I got F, D, B, and C there.请注意,我无法在我想要的地方获得 E,但我在那里获得了 F、D、B 和 C。 And I can make this file programmatically based on the parent-child relationships that I already know.我可以根据我已经知道的父子关系以编程方式制作这个文件。

While this is not a perfect solution, it's better for my usage than entering coordinates.虽然这不是一个完美的解决方案,但它比输入坐标更适合我的使用。

graph {
rankdir = "LR"
splines = line
//packmode="clust"
A
B [group=g3]
C [group=g2]
D [group=g1]
E
F [group=g2]
G
H [group=g1]
I [group=g3]
J
K
L [group=g2]
A -- {B ; C;} 
B -- D
B -- E
C -- F
D  -- {G; H; I;} 
E -- {J; K;} 
F [group=g2]
G
H [group=g1]
I [group=g3]
J
K
L [group=g2]
A -- {B ; C;} 
B -- D //[weight=10]
B -- E
C -- F
D  -- {G; H /*[group=g1]*/; I;} 
E -- {J; K;} 
F -- L
B -- I [style=invis]
}

图形图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM