更好的点状框图节点布局

发布于 2024-12-13 22:26:05 字数 2338 浏览 7 评论 0原文

在上一个问题(带点/Graphviz的框图布局)之后,我有进一步的问题。编译如下:

dot -Gsplines=none test.gv | neato -n -Gsplines=ortho -Tpng -otest.png

digraph G {
    graph [rankdir = LR];

    node[shape=record, style=filled];

bar[label="Bar", height=1.3636363636363635];
tea[label="Tea", height=1.3636363636363635];
brew[label="Brew", height=3.6363636363636362];
bar1[label="Bar1", height=2.2727272727272725];
baz[label="Baz", height=1];
foo[label="Foo", height=5.0];
darjeeling[label="Darjeeling", height=3.1818181818181817];
example[label="Example", height=17.727272727272727];

bar -> example [label="bar_clk"];
bar -> example [label="bar_bar"];
example -> tea [label="bli1"];
example -> tea [label="blo2"];
example -> tea [label="blo3"];
example -> brew [label="bli"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
bar1 -> example [label="bar1_foo"];
bar1 -> example [label="bar1_bar"];
bar1 -> example [label="bar1_baz"];
bar1 -> example [label="bar1_baz1"];
bar1 -> example [label="bar1_bar2"];
baz -> example [label="baz_foo"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> bar [label="blu"];
example -> baz [label="ble"];
darjeeling -> example [label="darjeeling_bli1"];
darjeeling -> example [label="darjeeling_blo2"];
darjeeling -> example [label="darjeeling_blo3"];
darjeeling -> example [label="darjeeling_bli1"];
darjeeling -> example [label="darjeeling_blo2"];
example -> darjeeling [label="bla"];
darjeeling -> example [label="darjeeling_blo3"];
}

我的问题是如何将 Baz 和 Darjeeling 节点移动到左侧以降低中间节点的高度。我不知道是什么决定了这一点。我知道这是一个有向图,所以该图的一般“流程”是从左到右,我只是想要更多的控制。

这些图表将自动生成,因此最好解释如何按照我的意愿布局以及为什么,而不是使其适用于这个特定示例的代码片段。

After a previous question (Block diagram layout with dot/Graphviz) I have further questions. The following is compiled like so:

dot -Gsplines=none test.gv | neato -n -Gsplines=ortho -Tpng -otest.png

digraph G {
    graph [rankdir = LR];

    node[shape=record, style=filled];

bar[label="Bar", height=1.3636363636363635];
tea[label="Tea", height=1.3636363636363635];
brew[label="Brew", height=3.6363636363636362];
bar1[label="Bar1", height=2.2727272727272725];
baz[label="Baz", height=1];
foo[label="Foo", height=5.0];
darjeeling[label="Darjeeling", height=3.1818181818181817];
example[label="Example", height=17.727272727272727];

bar -> example [label="bar_clk"];
bar -> example [label="bar_bar"];
example -> tea [label="bli1"];
example -> tea [label="blo2"];
example -> tea [label="blo3"];
example -> brew [label="bli"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
example -> brew [label="blo"];
bar1 -> example [label="bar1_foo"];
bar1 -> example [label="bar1_bar"];
bar1 -> example [label="bar1_baz"];
bar1 -> example [label="bar1_baz1"];
bar1 -> example [label="bar1_bar2"];
baz -> example [label="baz_foo"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> foo [label="bla"];
example -> bar [label="blu"];
example -> baz [label="ble"];
darjeeling -> example [label="darjeeling_bli1"];
darjeeling -> example [label="darjeeling_blo2"];
darjeeling -> example [label="darjeeling_blo3"];
darjeeling -> example [label="darjeeling_bli1"];
darjeeling -> example [label="darjeeling_blo2"];
example -> darjeeling [label="bla"];
darjeeling -> example [label="darjeeling_blo3"];
}

My question is how I could take the, say, Baz and Darjeeling nodes and move them to the left side to decrease the height of the middle node. I don't know what determines this. I understand this is a directional graph, so the general "flow" of the diagram is left to right, I'd just like more control.

These diagrams will be generated automatically, so an explanation on how to lay it out as I wish and why, as opposed to a code snippet that makes it work for this particular example, is preferred.

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

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

发布评论

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

评论(1

疯到世界奔溃 2024-12-20 22:26:05

有几点:

我如何将 Baz 和 Darjeeling 节点移动到左侧

通过为从 ExampleBaz< 的边缘设置 constraint=false /em> 和 大吉岭,或者通过使用 rank=min 将出现在示例左侧的所有节点分组到子图中。

您可能会说这不是一个合适的解决方案(至少不是带有 constraint=false 的解决方案),因为

这些图表将自动生成

,我完全理解(去过很多次) - 但同时,你希望

降低中间节点的高度

,因此图形仍然不是完全自动生成的(如何计算示例所需的高度?)。

我不知道是什么决定了这个

我也不完全确定 - Baz 也可能在左边。

令人惊讶的是,在某些情况下,节点的出现顺序会改变布局。例如,如果您向上移动大吉岭节点的定义,它将出现在左侧(并且Bar将出现在右侧)。


编辑:这是代码片段...

第三种可能性是按顺序(从上到下/从左到右)定义所有边,并装饰这些边使用dir=back返回。

如果将这 3 行更改

example -> bar [label="blu"];
example -> baz [label="ble"];
example -> darjeeling [label="bla"];

bar -> example [label="blu", dir=back];
baz -> example [label="ble", dir=back];
darjeeling -> example [label="bla", dir=back];

example -> bar [label="blu", constraint=false];
example -> baz [label="ble", constraint=false];
example -> darjeeling [label="bla", constraint=false];

(并更改 example 的高度),

您将得到

graphviz 结果

A couple of points:

how I could take the, say, Baz and Darjeeling nodes and move them to the left side

By setting constraint=false for the edges going from Example to Baz and Darjeeling, or by grouping all the nodes to appear left of Example in a subgraph with rank=min.

You may say that this is not a suitable solution (at least not the one with constraint=false) because

These diagrams will be generated automatically

and I completely understand (been there many times) - but at the same time, you wish

to decrease the height of the middle node

which is set manually, so the graph still is not fully auto-generated (how do you calculate the height needed for Example?).

I don't know what determines this

I'm not completely sure neither - Baz could might as well be on the left.

Surprisingly, the order of appearance of the nodes changes the layout in some cases. For example, if you move up the definition of the Darjeeling node, it will appear on the left side (and Bar gets to be at the right side).


Edit: Here comes the code snippet...

A third possibility is to define all edges in the right order (top-down/left-right) and decorate the edges going back with dir=back.

If you change these 3 lines

example -> bar [label="blu"];
example -> baz [label="ble"];
example -> darjeeling [label="bla"];

into

bar -> example [label="blu", dir=back];
baz -> example [label="ble", dir=back];
darjeeling -> example [label="bla", dir=back];

or into

example -> bar [label="blu", constraint=false];
example -> baz [label="ble", constraint=false];
example -> darjeeling [label="bla", constraint=false];

(and change the height of example)

You'll get

graphviz result

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