控制graphviz(dot2tex)中节点的布局?

发布于 2024-11-24 21:01:23 字数 456 浏览 0 评论 0原文

我是 graphviz 新手,只是想知道如何确定图中的相对节点位置。例如,如果我想绘制一个简单的三角形“abc”,节点“a”位于顶部,节点“b”和“c”位于底部同一水平,我应该如何告诉 graphviz 布局根据需要节点?

我尝试了以下操作:

graph G
{
   node [shape="circle"];
   edge [lblstyle="auto"];

   {rank=min; "a"}
   a -- b [label = "-"];
   a -- c [label = "-"];
   {rank=same; "b" "c"}
   b -- c [label = "+"];
}

但输出将节点“a”和“b”定位在顶部同一级别,节点“c”位于底部。

此外,是否可以在同一个图中并排绘制两个这样的三角形(之间有适当的空间)?如果有,是如何实施的?

多谢。

I am new to graphviz and am just wondering how to determine the relative node positioning in a graph. For example, if I want to draw a simple triangle 'abc', with node 'a' being at the top and nodes 'b' and 'c' on the same level at the bottom, how should I tell graphviz to lay out the nodes as desired?

I tried the following:

graph G
{
   node [shape="circle"];
   edge [lblstyle="auto"];

   {rank=min; "a"}
   a -- b [label = "-"];
   a -- c [label = "-"];
   {rank=same; "b" "c"}
   b -- c [label = "+"];
}

but the output positions nodes 'a' and 'b' on the same level at the top, with node 'c' at the bottom.

In addition, is it possible to draw two such triangles side-by-side (with a nice appropriate space in between) in the same graph? if so, how is it implemented?

Thanks a lot.

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

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

发布评论

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

评论(1

北方的巷 2024-12-01 21:01:23

但是输出将节点“a”和“b”放置在同一级别上
顶部,节点“c”位于底部。

实际上,我得到了 a 在顶部,位于 b 和 c 上方的中心(见图)。

您的标记稍微简化了(什么是 lblstyle ?),在用点渲染时似乎达到了您想要的效果:

graph G
{
   node[shape=circle];

   a -- b [label = "-"];
   a -- c [label = "-"];
   {rank=same; b -- c [label="+"];}
}

“graphviz

您使用什么版本的 graphviz?

并且并排有两个三角形:

graph G
{
   node[shape=circle];
   edge[label="-"];


   a -- b;
   a -- c;
   {rank=same; b -- c [label="+"];}

   d -- e;
   d -- f;
   {rank=same; e -- f [label="+"];}
}

但是,如果事情变得更加复杂,则可能很难让 graphviz 完全按照人们想要的方式布局所有内容。这实际上是 graphviz 的优势 - 应用布局算法以避免用户干预。

but the output positions nodes 'a' and 'b' on the same level at the
top, with node 'c' at the bottom.

I actually get a on top, centered above b and c (see image).

Your markup, slightly simplified (what's lblstyle ?), seems to achieve what you want when rendered with dot:

graph G
{
   node[shape=circle];

   a -- b [label = "-"];
   a -- c [label = "-"];
   {rank=same; b -- c [label="+"];}
}

graphviz triangle FTW

What version of graphviz do you use?

And to have two triangles side by side:

graph G
{
   node[shape=circle];
   edge[label="-"];


   a -- b;
   a -- c;
   {rank=same; b -- c [label="+"];}

   d -- e;
   d -- f;
   {rank=same; e -- f [label="+"];}
}

However, if things get more complex, it may be difficult to have graphviz layout everything exactly as one would like. That's actually the strength of graphviz - applying layout algorithms in order to not have a user intervene.

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