I use graphviz to draw a diagram.
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"];
}
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.Two more things I would recommend:
b->a
, rather writea->b[dir="back"]
; this avoids graphviz getting confused when the number of nodes increasesI have not completely edited the file, as it is not strictly necessary for the two items just mentioned - here the job I have done:
which gives you