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

发布于 2025-01-28 03:08:59 字数 490 浏览 3 评论 0原文

我想与在儿童节点的“中心”中对齐的父节点的图表。

对于下面的树,我将获得以下图像。

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
}

我想与node h对齐node d,节点e在j和k之间对齐,并且与l对齐。在下一个等级处,我想在e中间对齐。 d,c与F对准。在顶部(最左)等级,我想在B和C之间进行对齐。

是否有办法在不指定节点位置的情况下实现这一目标?

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
}

image of graph

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.

Is there a way to make this happen without specifying positions of nodes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-小熊_ 2025-02-04 03:08:59

我无法找到一种方法来获得我想要的一切,但是我靠近了很多。

秘密:

  1. 使用组强制水平边缘(在TD Rankdir中为垂直),如 graphviz点的节点的垂直对齐
  2. 在需要的地方添加不可见的边缘

,请注意,我无法将E带到我想要的位置,但是我在那里得到了F,D,B和C。我可以根据我已经知道的亲子关系来编程以编程为单位。

虽然这不是一个完美的解决方案,但对我的用法比输入坐标更好。

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]
}

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
  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. 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]
}

image of graph

淡紫姑娘! 2025-02-04 03:08:59

可能不是。即使您包含了隐形节点(样式= Invis),您仍然会与DOT算法进行战斗。明确指定X/y坐标会容易得多。

Probably not. Even if you included invisible nodes (style=invis), you would still be fighting the dot algorithm. It would be much easier to explicitly specify the X/Y coordinates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文