如何将该点程序中的节点调整为2 x 3表?

时间:2018-11-21 23:34:44

标签: graphviz dot

我使用graphviz绘制图表。

enter image description here

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

file_in   stdin_in     string_in

file_out  stdout_out   variable_out

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

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"];
}

1 个答案:

答案 0 :(得分:1)

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

我还建议两件事:

  • 使用标准的graphviz格式,而不是节点的类似HTML的语法;问题,但我发现它更易于阅读且更灵活,请参阅(How shall escape `>` in an edge label?
  • 在创建从层次结构中较低节点到较高节点的边时,请不要使用b->a,而要写a->b[dir="back"];这样可以避免在节点数增加时使graphviz感到困惑

我还没有完全编辑文件,因为对于上面提到的两项没有严格的要求-这是我已经完成的工作:

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>>];
}

给你

enter image description here