如何将该点程序中的节点调整为2 x 3表? [英] How can I adjust the nodes in this dot program into a 2 by 3 table?

查看:86
本文介绍了如何将该点程序中的节点调整为2 x 3表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用graphviz绘制图表.

I use graphviz to draw a diagram.

节点的放置不理想.我希望将六个节点大致放置在2 x 3的表格中:

The placement of the nodes are not ideal. I would like the six nodes to be roughly placed in a 2 by 3 table:

file_in   stdin_in     string_in

file_out  stdout_out   variable_out

我尝试将权重添加到某些边缘,但是仍然无法将节点移动到这样的表中.请参阅下面的我的点程序.谢谢.

I have tried to add weights to some edges but still fails to move the nodes into such a table. See my dot program below. Thanks.

digraph G {

/* directly betw inputs */
node [color=black]
string_in -> stdin_in [label="redirection"];
 file_in -> stdin_in [label="redirection"];
 stdin_in -> file_in [label="device file /dev/stdin, or arg -", weight=8];
 stdin_in -> string_in [label="xargs"]; 

/* directly betw outputs */
node [color=red]
edge [color=red]
  stdout_out -> file_out [label="redirection" fontcolor="red"];
  file_out -> stdout_out [label="/dev/stdout or arg -" fontcolor="red"];

/* directly from input to output */
edge [color=blue]
 stdin_in -> stdout_out [label="cat or tee" fontcolor="blue" weight=8];
 stdin_in -> file_out [label = "tee > /dev/null" fontcolor = "blue"]; 
 string_in -> stdout_out [label="echo -n" fontcolor="blue" weight=2];
 file_in -> stdout_out [label="cat" fontcolor="blue"];
 file_in -> file_out [label="none" fontcolor="blue"];
 string_in -> variable_out [label="assignment" fontcolor="blue"];

/* directly from output to input */
edge [color=green]
 stdout_out -> stdin_in [label="pipe" fontcolor="green"];
 stdout_out -> file_in  [label="process substitution"  fontcolor="green"];
 stdout_out -> string_in [label="command substitution"  fontcolor="green"];
 file_out -> file_in [label="none"  fontcolor="green"];
 variable_out -> string_in [label="parameter expansion"  fontcolor="green"];
}

推荐答案

此处的重点是使用rank = same;我已经在您的代码顶部添加了此指令.我还增加了两个等级之间的距离,以便为边缘标签留出更多空间.我还更改了您赋予边缘的权重,以使外观看起来像矩阵.

The key point here is using rank = same; I have added this instruction at the top of your code. I have also increased the distance between the two rank levels so that there is more space for the edge labels. I have also changed the weights you had given to the edges in order to have a matrix like appearance.

我还建议另外两件事:

  • 使用标准的graphviz格式,而不是节点的类似HTML的语法;问题,但我发现它更易于阅读并且更灵活,请参阅(如何在边缘标签中转义`>`?),
  • 当从层次结构中较低的节点到较高的节点创建边时,请勿使用b->a,而应编写a->b[dir="back"];这样可以避免在节点数增加时使graphviz感到困惑
  • rather than the HTML-like syntax for the node, use the standard graphviz format; matter of taste, but I find it easier to read and it is more flexible, see (How shall escape `>` in an edge label?),
  • when creating edges from nodes lower in the hierarchy to higher ones, don't use b->a, rather write a->b[dir="back"]; this avoids graphviz getting confused when the number of nodes increases

我还没有完全编辑文件,因为对于上面提到的两个项目,它并不是绝对必要的-在这里,我已经完成了工作:

I have not completely edited the file, as it is not strictly necessary for the two items just mentioned - here the job I have done:

digraph G {

# layout
ranksep = 2
{ rank = same; file_in stdin_in string_in }
{ rank = same; file_out stdout_out variable_out }

/* directly betw inputs */
node [color=black]
 string_in -> stdin_in [label="redirection"];
 file_in -> stdin_in [label="redirection"];
 stdin_in -> file_in [label="device file /dev/stdin, or arg -"] 
 stdin_in -> string_in [label="xargs"]; 

/* directly betw outputs */
node [color=red]
edge [color=red]
  stdout_out -> file_out [label=<<font color="red">redirection</font>>];
  file_out -> stdout_out [label=<<font color="red">/dev/stdout or arg -</font>>];

/* directly from input to output */
edge [color=blue]
 stdin_in -> stdout_out [label=<<font color="blue">cat or tee</font>> weight = 10];
 # stdin_in -> file_out [label=<<font color="blue">tee /dev/null</font>>]; 
 stdin_in -> file_out[ label = "tee > /dev/null" fontcolor = "blue" ];
 string_in -> stdout_out [label=<<font color="blue">echo -n</font>> ];
 file_in -> stdout_out [label=<<font color="blue">cat</font>> ];
 file_in -> file_out [label = "none" fontcolor = "blue" weight = 10];
 string_in -> variable_out [label = "assignment" fontcolor = "blue" weight = 10 ];

/* directly from output to input */
edge [color=green]
 stdout_out -> stdin_in [label=<<font color="green">pipe</font>>];
 stdout_out -> file_in  [label=<<font color="green">process substitution</font>>];
 stdout_out -> string_in [label=<<font color="green">command substitution</font>>];
 file_in -> file_out [label="none" fontcolor="green" dir = back ];
 variable_out -> string_in [label=<<font color="green">parameter expansion</font>>];
}

这给你

这篇关于如何将该点程序中的节点调整为2 x 3表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆