带 dot/graphviz 的框图布局
我想用点实现以下模型:
到目前为止我已经有了这么多:
digraph G {
graph [rankdir = LR, splines=ortho]
unit [shape=box, width = 2, height = 10];
more_different_unit [shape=box, height=4];
other_unit [shape=box, height=4];
unit -> other_unit [label = "foo"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
}
我这样编译:
dot -Gsplines=none test.gv | neato -n -Gsplines=ortho -Tpng -otest.png
这让我很接近,但有一些事情我想知道。
如何获得 Foo 左侧和右侧的块,而不仅仅是右侧?我还没有弄清楚这一点。
是否可以将边缘标签始终放置在边缘上方或下方?
如何将右侧节点向左对齐,左侧节点向右对齐?一种可能是使它们具有相同的宽度,这样就可以了。
谢谢!!
更新:
根据已接受的答案,我现在正在执行以下操作,这正是我所需要的,再次通过点管道传输到neato生成,如上所述:
digraph G {
graph [rankdir = LR, splines=ortho];
node[shape=record];
Bar[label="Bar", height=2];
Foo[label="Foo", height=4];
Bew[label="Bew", height=2];
Gate[label="Gate", height=2];
Bar -> Foo [label="Bar2Foo"];
Bar -> Foo [label="Bar2Foo"];
Bar -> Foo [label="Bar2Foo"];
Foo -> Bew [label="Foo2Bew"];
Foo -> Bew [label="Foo2Bew"];
Bew -> Foo [label="Bew2Foo"];
Foo -> Gate [label="Foo2Gate"];
Foo -> Gate [label="Foo2Gate"];
}
I'd like to implement the following mockup with dot:
So far I've got this much:
digraph G {
graph [rankdir = LR, splines=ortho]
unit [shape=box, width = 2, height = 10];
more_different_unit [shape=box, height=4];
other_unit [shape=box, height=4];
unit -> other_unit [label = "foo"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> other_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
unit -> more_different_unit [label = "bar"];
}
I compile it like so:
dot -Gsplines=none test.gv | neato -n -Gsplines=ortho -Tpng -otest.png
That gets me close, but there are a few things I'd like to know.
How can I get blocks to the left and right of Foo, not just the right? I haven't been able to figure that out yet.
Is it possible to put the edge labels consistently above or under the edge?
How can I align the right-hand nodes left, and the left-hand nodes right? One possibility would be to make them the same width, which would be okay.
Thanks!!
UPDATE:
Based on the accepted answer, I am now doing the following which is precisely what I needed, again generated through dot piped to neato, as mentioned above:
digraph G {
graph [rankdir = LR, splines=ortho];
node[shape=record];
Bar[label="Bar", height=2];
Foo[label="Foo", height=4];
Bew[label="Bew", height=2];
Gate[label="Gate", height=2];
Bar -> Foo [label="Bar2Foo"];
Bar -> Foo [label="Bar2Foo"];
Bar -> Foo [label="Bar2Foo"];
Foo -> Bew [label="Foo2Bew"];
Foo -> Bew [label="Foo2Bew"];
Bew -> Foo [label="Bew2Foo"];
Foo -> Gate [label="Foo2Gate"];
Foo -> Gate [label="Foo2Gate"];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这能让你开始吗?
请注意,我使用不间断空格作为一种厚颜无耻的方式来获得对齐(我想,我做了 Ck空格空格在vim中,通向十六进制
00a0
字符)您还可以在标签定义中使用 HTML,这样您就可以使用字体、颜色并创建“间隔符”:http://www.graphviz.org/doc/info/shapes.html#html
我想使用 HTML 节点对齐标签会更容易。
Does this get you started?
Note that I used nonbreaking spaces as a cheeky way to get the alignment (I think, I did C-kSpaceSpace in vim, leading to Hex
00a0
char)You can also employ HTML inside the label definitions, so you can use fonts, colors and create 'spacers': http://www.graphviz.org/doc/info/shapes.html#html
I suppose aligning labels would be easier with HTML nodes.