Graphviz 如何将此dot程序中的节点调整为2 x 3表格?

Graphviz 如何将此dot程序中的节点调整为2 x 3表格?,graphviz,dot,Graphviz,Dot,我用graphviz画一个图表 节点的位置不理想。我希望将六个节点大致放在一个2×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 [labe

我用graphviz画一个图表

节点的位置不理想。我希望将六个节点大致放在一个2×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"];
}

这里的关键点是使用
rank=same
;我已在代码顶部添加了此指令。我还增加了两个级别之间的距离,以便为边缘标签留出更多空间。我还更改了您为边指定的权重,以获得类似矩阵的外观

我还要推荐两件事:

  • 使用标准的graphviz格式,而不是类似于HTML的节点语法;品味问题,但我发现它更容易阅读,也更灵活,请参见()
  • 从层次结构中较低的节点到较高的节点创建边时,不要使用
    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>>];
}
有向图G{
#布局
ranksep=2
{rank=same;文件\u在标准中\u在字符串中\u在}
{rank=相同;文件\u out标准输出\u out变量\u out}
/*直接输入*/
节点[颜色=黑色]
字符串在->标准输入在[label=“redirection”]中;
[label=“redirection”]中的文件->标准输入;
stdin\u in->file\u in[label=“device file/dev/stdin,或arg-”]
标准输入->字符串输入[label=“xargs”];
/*直接输出*/
节点[颜色=红色]
边缘[颜色=红色]
标准输出->文件输出[标签=];
文件输出->标准输出[标签=];
/*直接从输入到输出*/
边缘[颜色=蓝色]
标准输入->标准输出[标签=重量=10];
#标准输入->文件输出[标签=];
标准输入->文件输出[label=“tee>/dev/null”fontcolor=“blue”];
字符串输入->标准输出[标签=];
文件输入->标准输出[标签=];
文件输入->文件输出[label=“none”fontcolor=“blue”weight=10];
字符串输入->变量输出[label=“assignment”fontcolor=“blue”weight=10];
/*直接从输出到输入*/
边缘[颜色=绿色]
标准输出->标准输入[标签=];
标准输出->文件输入[标签=];
标准输出->字符串输入[标签=];
文件输入->文件输出[label=“none”fontcolor=“green”dir=back];
变量输出->字符串输入[标签=];
}
这给了你


非常感谢!:)如果我可以问,(1)使用
rank
来确保具有相同秩的节点始终位于同一行是否正确?(2) 是否没有类似的方法来确保节点始终位于同一列中,唯一的方法是调整边权重?(3) “当从层次结构中较低的节点创建边到较高的节点时,不要使用b->a,而是写入a->b[dir=“back”];这避免了当节点数量增加时图形变得混乱。”。这是什么样的困惑?感谢你的提问:(1)原则上是的,
graphviz
需要将你所拥有的东西放在同一层次上-(2)有其他方式,但取决于上下文-(3)
b->a
告诉
graphviz
b
a
之上,这可能与你想要的相反;在大多数情况下,上下文会纠正这一点,但我曾经遇到过这样的情况:错误方向的一条边完全弄乱了图形;作为“良好实践”,保持层次顺序和箭头方向分开。为了确保节点始终位于同一列中,“有其他方法,但取决于上下文”。如果我可以问一下,还有哪些常用的方法?难道没有像rank这样的方法可以强制执行吗?对不起,这真的不那么容易。只需检查几个项目:确保按正确的顺序声明节点-
graphviz
在声明节点时绘制它们。通常,看不见的边缘有助于维持秩序。可以是最后的手段。但是“没有适合所有人的尺码”,谢谢。为了以防万一,作为备份计划,我还试图找到一种方法,手动调整最初由GraphViz在Inkscape或类似软件中创建的SVG文件。如果您碰巧知道这方面的一些情况,我也将感谢您的考虑: