简体   繁体   English

带有 dot/graphviz 的框图布局

[英]Block diagram layout with dot/graphviz

I'd like to implement the following mockup with dot:我想用点实现以下模型:

将在 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 |点 -Gsplines=none test.gv | neato -n -Gsplines=ortho -Tpng -otest.png neato -n -Gsplines=ortho -Tpng -otest.png

That gets me close, but there are a few things I'd like to know.这让我很接近,但有一些事情我想知道。

  1. How can I get blocks to the left and right of Foo, not just the right?如何在 Foo 的左侧和右侧获得块,而不仅仅是在右侧? I haven't been able to figure that out yet.我还没有弄清楚。

  2. Is it possible to put the edge labels consistently above or under the edge?是否可以将边缘标签始终放在边缘上方或下方?

  3. 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:根据接受的答案,我现在正在执行以下操作,这正是我所需要的,再次通过点管道连接到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"];
}

Does this get you started?这会让你开始吗?

digraph G {
    graph [rankdir = LR];

    node[shape=record];
    Bar[label="{ \"Bar\"|{<p1>pin 1|<p2>     2|<p3>     3|<p4>     4|<p5>     5} }"];
    Foo[label="{ {<data0>data0|<data1>data1|<data2>data2|<data3>data3|<data4>data4}|\"Foo\" |{<out0>out0|<out1>out1|<out2>out2|<GND>gnd|<ex0>ex0|<hi>hi|<lo>lo} }"];

    Bew[label="{ {<clk>clk|<syn>syn|<mux0>mux0|<mux1>mux1|<signal>signal}|\"Bew\" |{<out0>out0|<out1>out1|<out2>out2} }"];
    Bar:p1 -> Foo:data0;
    Bar:p2 -> Foo:data1;
    Bar:p3 -> Foo:data2;
    Bar:p4 -> Foo:data3;
    Bar:p5 -> Foo:data4;

    Foo:out0 -> Bew:mux0;
    Foo:out1 -> Bew:mux1;
    Bew:clk -> Foo:ex0;

    Gate[label="{ {<a>a|<b>b}|OR|{<ab>a\|b} }"];

    Foo:hi -> Gate:a;
    Foo:lo -> Gate:b;
    Gate:ab -> Bew:signal;
}

在此处输入图片说明

Note that I used nonbreaking spaces as a cheeky way to get the alignment (I think, I did Ck Space Space in vim, leading to Hex 00a0 char)请注意,我使用不间断空格作为获得对齐的一种厚脸皮的方式(我认为,我在 vim 中做了Ck Space Space ,导致 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您还可以在标签定义中使用 HTML,因此您可以使用字体、颜色并创建“间隔”: http : //www.graphviz.org/doc/info/shapes.html#html

I suppose aligning labels would be easier with HTML nodes.我认为使用 HTML 节点对齐标签会更容易。

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

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