Layout in Graphviz
The essential question is how to开发者_如何学JAVA control the vertical and horizontal positioning of elements in Graphviz diagrams.
Consider this excerpt of a diagram (created in wysiwig editor).
I was trying to reproduce it in Graphviz to figure out whether it is suitable for my purposes.
digraph G {
compound=true;
node [shape=box];
edge [dir=none];
subgraph cluster_tmk_web6 {
nginx [label="nginx-frontend TCP 0.0.0.0:80"];
subgraph clusteradminapp {
unicorn [label="unicorn_rails TCP 127.0.0.1:8080"];
subgraph clusterROR {
label="ROR v.2.1";
brida [label="brida_face_client"];
}
label="Admin App";
}
memcached [label="memcached"];
sphinx;
mongodb;
subgraph cluster_errbit {
unicorn2;
ror3;
}
label="tmk-web6.service.home";
}
nginx -> unicorn;
memcached -> brida [lhead=clusterROR];
}
And the result goes like
I omitted some of the arrows, but the positioning is crucial for me. How do I move 'memcached' and 'sphinx' to the bottom of the cluster? How to shift 'mongodb' to the right? And finally, the diagram will consist of some 6 to 10 clusters of this size. How do I control the layout, placing some clusters in a row and others — above and below? I guess I should use "rank" attribute here, but not sure how. Please, help.
Just by adding the remaining edges (and two invisible edges), the graphviz output comes closer to your desired result:
digraph G {
compound=true;
node [shape=box];
edge [dir=none];
subgraph cluster_tmk_web6 {
nginx [label="nginx-frontend TCP 0.0.0.0:80"];
subgraph clusteradminapp {
unicorn [label="unicorn_rails TCP 127.0.0.1:8080"];
subgraph clusterROR {
label="ROR v.2.1";
brida [label="brida_face_client"];
}
unicorn -> brida[style=invis];
label="Admin App";
}
memcached [label="memcached"];
sphinx;
mongodb;
subgraph cluster_errbit {
unicorn2;
ror3;
unicorn2 -> ror3[style="invis"];
label="Errbit";
}
label="tmk-web6.service.home";
}
nginx -> unicorn;
nginx -> unicorn2;
brida -> memcached [lhead=clusterROR];
brida -> sphinx [lhead=clusterROR];
ror3 -> mongodb;
}
Add some colors etc., and you're almost there.
But keep in mind, Graphviz is not a wysiwyg tool - its strong point is the automatic layout of nodes.
精彩评论