I've got an undirected graph made by graphviz tools (now i'm using sfdp):
digraph structs {
node [shape=Mrecord, URL="index_new.php?object=\N&overlap=false"];
overlap = orthoxy;
bgcolor=transparent;
splines=true;
rankdir=TB;
node [fontname="Arial", fontsize=30, style=filled, fillcolor=chartreuse1, image="../common/img/monitor.png"]struct_swbposad91 [label = "sw-bposad9-1\n192.168.17.141\nC2960 "];
node [fontname="Arial", fontsize=30, style=filled, fillcolor=chartreuse1, image="../common/img/monitor.png"]struct_swmedikov5fan [label = "sw-medikov5-fan\n192.168.34.134\n "];
node [fontname="Arial", fontsize=30, style=filled, fillcolor=chartreuse1, image="../common/img/monitor.png"]struct_swlevash131 [label = "sw-levash13-1\n192.168.16.165\nC2960 "];
node [fontname="Arial", fontsize=30, style=filled, fillcolor=deepskyblue]struct_swpolevsabirov45a [label = "sw-polevsabirov45a\n192.168.18.182\nS2300 "];
...lots of lines goes here...
struct_swkazan71:f450212->struct_swbmorsk181:f450213 [weight=1.2, dir=both, color=black, penwidth=5, arrowhead="empty", arrowtail="odot"];
struct_swmikh171:f450222->struct_swbotk151:f450223 [weight=1.2, dir=both, color=black, penwidth=1, arrowhead="empty", arrowtail="odot"];
...lots of lines goes here...
here is full code: http://pastebin.com/P3MKTCm2 (it's really large, sorry)
and the output is like this one: (part)
Problem: i need my graph to grow horizontaly instead of verticaly. Is there any way to get the layout like the one on the image, but "rotated" 90 degrees?
A couple of observations made while trying to make something out of the graph:
The graph is not big, but the markup sure is redundant - I applied a little love and removed them so one can actually read it (see below)
The ports used for the edges do not exist and graphviz generates a load of warnings. While the output is still generated, this is certainly not a good thing.
This is a directed graph - digraph and -> are used for directed graphs.
overlap=orthoxy seems to be deprecated:
The remaining allowed values of overlap correspond to algorithms
which, at present, can produce bad aspect ratios. In addition, we
deprecate the use of the "ortho*" and "portho*".
Below the output when simply using overlap=false with sfdp, ignoring all warnings and the missing images:
digraph structs {
overlap=false;
bgcolor=transparent;
splines=true;
rankdir=TB;
node [shape=Mrecord, URL="index_new.php?object=\N&overlap=false", fontname="Arial", fontsize=30, style=filled, fillcolor=chartreuse1, image="../common/img/monitor.png"];
struct_swbposad91 [label = "sw-bposad9-1\n192.168.17.141\nC2960 "];
struct_swmedikov5fan [label = "sw-medikov5-fan\n192.168.34.134\n "];
struct_swlevash131 [label = "sw-levash13-1\n192.168.16.165\nC2960 "];
struct_swkant121 [label = "sw-kant12-1\n192.168.19.9\nC3400 "];
struct_swpolit91 [label = "sw-polit9-1\n192.168.18.102\n8012M "];
struct_swbotk151 [label = "sw-botk15-1\n192.168.18.36\nC2960 "];
struct_swmikh171 [label = "sw-mikh17-1\n192.168.18.37\nC2950 "];
struct_swchapaeva17 [label = "sw-chapaeva17\n192.168.17.136\n8000S "];
struct_swsamp871 [label = "sw-samp87-1\n192.168.19.7\nC2960 "];
struct_swlig291 [label = "sw-lig29-1\n192.168.39.133\nC2960 "];
struct_swbotk152 [label = "sw-botk15-2\n192.168.19.119\nC2960 "];
struct_swkubin842 [label = "sw-kubin84-2\n192.168.31.131\nI2110A "];
struct_swpugacheva571 [label = "sw-pugacheva5/7-1\n192.168.37.144\nI2110A "];
struct_swbposad92 [label = "sw-bposad9-2\n192.168.17.142\nC3550 "];
struct_swkapitolk177 [label = "sw-kapitol-k177\n192.168.40.134\n "];
struct_swkapitolk338 [label = "sw-kapitol-k338\n192.168.40.131\n "];
struct_swbmorsk181 [label = "sw-bmorsk18-1\n192.168.29.132\nC2960 "];
struct_swpirog171 [label = "sw-pirog17-1\n192.168.18.40\nSuperStack "];
struct_swkazan71 [label = "sw-kazan7-1\n192.168.19.228\nC2960 "];
struct_cskazac9brd [label = "cs-kazac9-brd\n192.168.30.251\nCASR1002F "];
struct_swgrib1261 [label = "sw-grib126-1\n192.168.19.235\nC2960 "];
struct_swlenin1391 [label = "sw-lenin139-1\n192.168.31.144\nC2960 "];
struct_swpirog151 [label = "sw-pirog15-1\n192.168.18.42\nI2110A "];
struct_swrastr21 [label = "sw-rastr2-1\n192.168.36.130\nC2960 "];
struct_swkazac92 [label = "sw-kazac9-2\n192.168.17.163\nC2960 "];
struct_swsmolen331 [label = "sw-smolen33-1\n192.168.17.108\nC2950 "];
struct_swkubin841 [label = "sw-kubin84-1\n192.168.31.134\nS2300 "];
struct_swkurskaya40 [label = "sw-kurskaya40\n192.168.26.144\nI2110A "];
struct_swvolkov171 [label = "sw-volkov17-1\n192.168.17.167\nC2960 "];
struct_swtall71 [label = "sw-tall7-1\n192.168.37.147\nC2960 "];
struct_swlevash132 [label = "sw-levash13-2\n192.168.16.174\n8000S "];
struct_swpetrovkosa11 [label = "sw-petrovkosa1-1\n192.168.16.164\nC2950 "];
struct_swobuh120e1 [label = "sw-obuh120e-1\n192.168.21.131\nC2960 "];
struct_swkurch101 [label = "sw-kurch10-1\n192.168.18.104\nC2960 "];
struct_swsamp873 [label = "sw-samp87-3\n192.168.19.57\nC2960 "];
struct_swengelsa291 [label = "sw-engelsa29-1\n192.168.18.163\nC2960 "];
struct_swsamp681 [label = "sw-samp68-1\n192.168.19.4\nC2950 "];
struct_swsamp421 [label = "sw-samp42-1\n192.168.19.2\nS2300 "];
struct_swbelovod71 [label = "sw-belovod7-1\n192.168.19.12\nS2300 "];
struct_swoktyabr381 [label = "sw-oktyabr38-1\n192.168.37.149\n8000S "];
struct_swural11 [label = "sw-ural1-1\n192.168.28.144\nI2110A "];
struct_swsamp68style [label = "sw-samp68-style\n192.168.19.10\n8012M "];
struct_swrevol69 [label = "sw-revol69\n192.168.37.141\n "];
struct_swlig292 [label = "sw-lig29-2\n192.168.39.134\nSuperStack "];
struct_swkolom331 [label = "sw-kolom33-1\n192.168.18.181\nC2950 "];
struct_swchernigov15 [label = "sw-chernigov15\n192.168.26.133\nI2110A "];
struct_swVO9line344 [label = "sw-VO9line34-4\n192.168.28.142\nI2110A "];
struct_swbmorsk182 [label = "sw-bmorsk18-2\n192.168.29.133\nC2960 "];
struct_swdom41 [label = "sw-dom4-1\n192.168.18.226\nC2960 "];
struct_swnevsky301 [label = "sw-nevsky30-1\n192.168.27.135\nC2960 "];
struct_swobuh116k11 [label = "sw-obuh116k1-1\n192.168.21.132\n "];
struct_swkapitol1 [label = "sw-kapitol-1\n192.168.40.145\n "];
node [fontname="Arial", fontsize=30, style=filled, fillcolor=deepskyblue];
struct_swpolevsabirov45a [label = "sw-polevsabirov45a\n192.168.18.182\nS2300 "];
struct_swvarshav111 [label = "sw-varshav11-1\n192.168.20.46\nSuperStack "];
struct_swtrefol2opor [label = "sw-trefol2-opor\n192.168.31.142\nC2960 "];
node [fontname="Arial", fontsize=30, style=filled, fillcolor=yellow];
struct_swVO9line341 [label = "sw-VO9line34-1\n192.168.28.137\nC2960 "];
struct_swkazac91 [label = "sw-kazac9-1\n192.168.17.104\nC2960 "];
struct_swVO9line345 [label = "sw-VO9line34-5\n192.168.28.143\nI2924GF "];
struct_swmagn17a2 [label = "sw-magn17a-2\n192.168.37.133\nSuperStack "];
struct_swpopova23gajot [label = "sw-popova23-gajot\n192.168.34.133\nC3400 "];
struct_swVO9line343 [label = "sw-VO9line34-3\n192.168.28.138\nC3400 "];
struct_swmagnit17a1 [label = "sw-magnit17a-1\n192.168.37.130\nC2960 "];
struct_swknipovich41 [label = "sw-knipovich4-1\n192.168.39.139\nI2126A "];
edge[weight=1.2, dir=both, color=black, penwidth=1, arrowhead="empty", arrowtail="odot"];
struct_swtrefol2opor:f450155->struct_swvarshav111:f450156 [color=red, penwidth=5];
struct_swkazan71:f450212->struct_swbmorsk181:f450213 [penwidth=5];
struct_swmikh171:f450222->struct_swbotk151:f450223;
struct_swpirog171:f450230->struct_swbotk151:f450231;
struct_swbotk152:f450232->struct_swbotk151:f450233;
struct_swoktyabr381:f450262->struct_swtall71:f450263;
struct_swvarshav111:f450291->struct_swlenin1391:f450292;
struct_swkazac92:f450313->struct_swkazac91:f450314;
struct_swkazac91:f450321->struct_swkazan71:f450322 [penwidth=5];
struct_swgrib1261:f450323->struct_swkazan71:f450324;
struct_cskazac9brd:f450333->struct_swkazac91:f450334;
struct_swlenin1391:f450335->struct_swkazan71:f450336 [penwidth=5];
struct_cskazac9brd:f450345->struct_swkazac91:f450346;
struct_swsmolen331:f450347->struct_swkazac91:f450348;
struct_swbotk151:f450349->struct_swkazac91:f450350 [penwidth=5];
struct_cskazac9brd:f450351->struct_swkazac91:f450352;
struct_swrastr21:f450361->struct_swkazac91:f450362 [penwidth=5];
struct_swlenin1391:f450363->struct_swkazac91:f450364 [penwidth=5];
struct_swpirog151:f450379->struct_swpirog171:f450380;
struct_swkurskaya40:f450383->struct_swvolkov171:f450384;
struct_swkubin841:f450389->struct_swlenin1391:f450390;
struct_swkubin842:f450403->struct_swkubin841:f450404;
struct_swVO9line345:f450431->struct_swbposad91:f450432;
struct_swbposad92:f450435->struct_swbposad91:f450436;
struct_swchapaeva17:f450441->struct_swbposad92:f450442;
struct_swmedikov5fan:f450453->struct_swbposad91:f450454 [penwidth=5];
struct_swbposad91:f450469->struct_swsamp871:f450470 [penwidth=5];
struct_swdom41:f450473->struct_swsamp871:f450474 [penwidth=5];
struct_swkurch101:f450477->struct_swsamp871:f450478;
struct_swsamp873:f450479->struct_swsamp871:f450480;
struct_swbposad91:f450487->struct_swsamp871:f450488 [penwidth=5];
struct_swkant121:f450491->struct_swsamp871:f450492;
struct_swpolit91:f450493->struct_swsamp871:f450494;
struct_swengelsa291:f450495->struct_swsamp871:f450496 [penwidth=5];
struct_swsamp681:f450497->struct_swsamp871:f450498;
struct_swsamp421:f450499->struct_swsamp871:f450500;
struct_swrastr21:f450539->struct_swbotk151:f450540 [penwidth=5];
struct_swpolevsabirov45a:f450605->struct_swkolom331:f450606;
struct_swbelovod71:f450613->struct_swsamp421:f450614;
struct_swpopova23gajot:f450630->struct_swmedikov5fan:f450631;
struct_swural11:f450636->struct_swVO9line345:f450637;
struct_swlig291:f450652->struct_swkazac91:f450653 [penwidth=5];
struct_swmagn17a2:f450657->struct_swmagnit17a1:f450658;
struct_swlevash132:f450674->struct_swlevash131:f450675;
struct_swmedikov5fan:f450678->struct_swlevash131:f450679 [penwidth=5];
struct_swpetrovkosa11:f450686->struct_swlevash131:f450687;
struct_swobuh120e1:f450711->struct_swmagnit17a1:f450712 [penwidth=5];
struct_swtall71:f450713->struct_swmagnit17a1:f450714;
struct_swpugacheva571:f450721->struct_swmagnit17a1:f450722;
struct_swobuh120e1:f450751->struct_swlig291:f450752 [penwidth=5];
struct_swlig292:f450757->struct_swlig291:f450758;
struct_swknipovich41:f450763->struct_swlig291:f450764;
struct_swsamp68style:f450777->struct_swsamp681:f450778;
struct_swrevol69:f450781->struct_swmagnit17a1:f450782;
struct_swchernigov15:f450827->struct_swsmolen331:f450828;
struct_swvolkov171:f450835->struct_swsmolen331:f450836;
struct_swobuh116k11:f450852->struct_swobuh120e1:f450853;
struct_swmagnit17a1:f450926->struct_swbotk151:f450927 [penwidth=5];
struct_swnevsky301:f450932->struct_swkazan71:f450933;
struct_swbmorsk182:f450948->struct_swbmorsk181:f450949;
struct_swkazan71:f450952->struct_swbmorsk181:f450953 [penwidth=5];
struct_swbmorsk181:f450972->struct_swVO9line341:f450973 [penwidth=5];
struct_swVO9line344:f450986->struct_swVO9line341:f450987;
struct_swVO9line343:f450994->struct_swVO9line341:f450995 [color=Red, penwidth=5];
struct_swbmorsk181:f450998->struct_swVO9line341:f450999 [penwidth=5];
struct_swlevash131:f451004->struct_swVO9line341:f451005 [penwidth=5];
struct_swkapitolk177:f451031->struct_swkapitol1:f451032;
struct_swkapitolk338:f451033->struct_swkapitol1:f451034;
struct_swkolom331:f451084->struct_swengelsa291:f451085;
struct_swdom41:f451086->struct_swengelsa291:f451087 [penwidth=5];
struct_swVO9line345:f451139->struct_swVO9line341:f451140;
struct_swsamp871:f451157->struct_swbotk151:f451158 [penwidth=5];
struct_swVO9line345:f451161->struct_swVO9line341:f451162;
struct_swbotk151:f451177->struct_swkazac91:f451178 [penwidth=5];
struct_swsamp871:f451184->struct_swbotk151:f451185 [penwidth=5];
struct_swkazac91:f451186->struct_swkazan71:f451187 [penwidth=5];
struct_swVO9line345:f451190->struct_swbposad91:f451191;
}
And here the same with dot:
Have you tried using [rankdir=TB] ?
http://www.graphviz.org/doc/info/attrs.html#d:rankdir
There may be something that I am missing, because rankdir=TB should be the default. Your sample graph appears to have rankdir=LR, but you didn't mention specifying it. (Also your graph looks like a directed graph, but you indicated undirected.)
Related
Trying to put all thick bordered items into a vertical alignment. How do I do this?
Also, I'm trying to get the empty dot, where the two lines combine into one, to go away so the edges are connected. They are denoted by the "i*" naming convention. Specifically for this, I want the two lines to merge back together then attach to the next item. I tried the concentrate = "true" and that did not work as expected. The lines basically did not merge back together.
digraph G {
concentrate = "true";
node[shape="box", style="rounded"];
{
start [penwidth = 2.0];
end [penwidth = 2.0];
}
// PROCESS
node[shape="box"];
{
calc [label = "Calculate\nSelected\nValues", penwidth = 2.0];
deployPara [label = "Deploy\nPatachute" ];
bldMsg [label = "Build\nMessage"];
sendMsg [label = "Transmit\nMessage"];
sleepCycle [label = "Sleep\nCycle", penwidth=2];
}
// Decision
node[shape="diamond", style=""]
{
decidePara [label = "Decide\nDeploy", penwidth=2];
decideMsg [label = "Decide\nMessage", penwidth=2];
}
node[shape = point, width = 0, height = 0];
{
iDeploy
iMsg
}
start -> decidePara
decidePara -> iDeploy [label = "No", arrowhead = "none"]
decidePara -> deployPara [label = "Yes"]
deployPara -> iDeploy [arrowhead = "none"]
iDeploy -> decideMsg ;
decideMsg -> iMsg [label = "No", arrowhead = "none"];
decideMsg -> bldMsg [label = "Yes"];
bldMsg -> sendMsg;
sendMsg -> iMsg [arrowhead = "none"]
iMsg -> sleepCycle
sleepCycle -> end;
{rank=same; decidePara deployPara}
{rank=same; decideMsg bldMsg sendMsg}
}
Edit the image commenter sees is:
Changes:
splines=false (assuming you want straight lines)
gave all nodes needing alignment a group attribute (see https://graphviz.org/docs/attrs/group/)
changed size of i* nodes to fill in the gap
also used headclip & tailclip attributes (https://graphviz.org/docs/attrs/headclip/) to fill in the gap (not sure if needed)
digraph G {
concentrate = "true";
splines=false
node[shape="box", style="rounded"];
{
start [penwidth = 2.0 group=S];
end [penwidth = 2.0 group=S];
}
// PROCESS
node[shape="box"];
{
calc [label = "Calculate\nSelected\nValues", penwidth = 2.0];
deployPara [label = "Deploy\nPatachute" ];
bldMsg [label = "Build\nMessage"];
sendMsg [label = "Transmit\nMessage"];
sleepCycle [label = "Sleep\nCycle", penwidth=2 group=S];
}
// Decision
node[shape="diamond", style=""]
{
decidePara [label = "Decide\nDeploy", penwidth=2 group=S];
decideMsg [label = "Decide\nMessage", penwidth=2 group=S];
}
node[shape = point, width = .01, height = .01 group=S];
{
iDeploy
iMsg
}
start -> decidePara
decidePara -> iDeploy [label = "No", arrowhead = "none" headclip=false]
decidePara -> deployPara [label = "Yes"]
deployPara -> iDeploy [arrowhead = "none" headclip=false]
iDeploy -> decideMsg [tailclip=false]
decideMsg -> iMsg [label = "No", arrowhead = "none" headclip=false];
decideMsg -> bldMsg [label = "Yes"];
bldMsg -> sendMsg;
sendMsg -> iMsg [arrowhead = "none"]
iMsg -> sleepCycle [tailclip=false]
sleepCycle -> end;
{rank=same; decidePara deployPara}
{rank=same; decideMsg bldMsg sendMsg}
}
Giving:
I have a PATRICA trie for which I'm generating a GraphViz file. The internal nodes are the skip values and the edges are dotted 0 and solid 1. It is preferred that 0 is to the left of 1, giving an alphabetical order of the leaves. I re-arranged the order I visit the graph so dot gives this result. However, when I group them in trees in a forest using subgraphs, I can't seem to force dot to reliably respect the order for inter-subgraph edges.
digraph {
rankdir=TB;
node [shape = box, style = filled, fillcolor = lightsteelblue];
// forest size 2.
subgraph cluster_tree0 {
style = filled; fillcolor = lightgray; label = "tree 0";
// branches
branch0_0 [label = "3", shape = none, fillcolor = none];
branch0_0 -> branch0_1;
branch0_1 [label = "0", shape = none, fillcolor = none];
branch0_1 -> branch0_2 [style = dashed];
branch0_2 [label = "1", shape = none, fillcolor = none];
branch0_2 -> leaf0_1 [style = dashed, color = royalblue];
branch0_2 -> leaf0_2 [color = royalblue];
branch0_1 -> branch0_3;
branch0_3 [label = "2", shape = none, fillcolor = none];
branch0_3 -> leaf0_3 [style = dashed, color = royalblue];
branch0_3 -> leaf0_4 [color = royalblue];
// leaves
leaf0_1 [label = "u"];
leaf0_2 [label = "v"];
leaf0_3 [label = "x"];
leaf0_4 [label = "y"];
}
branch0_0 -> branch1_0 [lhead = cluster_tree0, ltail = cluster_tree1, color = firebrick, style = dashed];
subgraph cluster_tree1 {
style = filled; fillcolor = lightgray; label = "tree 1";
// branches
branch1_0 [label = "0", shape = none, fillcolor = none];
branch1_0 -> leaf1_0 [style = dashed, color = royalblue];
branch1_0 -> branch1_1;
branch1_1 [label = "1", shape = none, fillcolor = none];
branch1_1 -> leaf1_1 [style = dashed, color = royalblue];
branch1_1 -> branch1_2;
branch1_2 [label = "0", shape = none, fillcolor = none];
branch1_2 -> leaf1_2 [style = dashed, color = royalblue];
branch1_2 -> leaf1_3 [color = royalblue];
// leaves
leaf1_0 [label = "f"];
leaf1_1 [label = "m"];
leaf1_2 [label = "n"];
leaf1_3 [label = "o"];
}
}
On one graph it works fine, but it the subgraphs are reversed to the order I want them.
I reversed the order in the file and it still looks the same. I played around with it and I could get it turned around by rank=same, ordering=out, and invis edges somehow, but I want it to be programmatic. Is there any easy way to draw the red dotted line, representing 0, to the left, instead of to the right, of the solid line, representing 1?
OK, a total kludge, but probably fully scriptable.
First, your input somewhat reworked:
digraph {
rankdir=TB;
newrank=true // helps
graph [splines=false]
node [shape = box, style = filled, fillcolor = lightsteelblue];
// forest size 2.
subgraph cluster_tree1 {
style = filled; fillcolor = lightgray; label = "tree 1";
// branches
branch1_0 [label = "0", shape = none, fillcolor = none];
branch1_0 -> leaf1_0 [style = dashed, color = royalblue];
branch1_0 -> branch1_1;
branch1_1 [label = "1", shape = none, fillcolor = none];
branch1_1 -> leaf1_1 [style = dashed, color = royalblue];
branch1_1 -> branch1_2;
branch1_2 [label = "0", shape = none, fillcolor = none];
branch1_2 -> leaf1_2 [style = dashed, color = royalblue];
branch1_2 -> leaf1_3 [color = royalblue];
// leaves
leaf1_0 [label = "f"];
leaf1_1 [label = "m"];
leaf1_2 [label = "n"];
leaf1_3 [label = "o"];
}
subgraph cluster_tree0 {
style = filled; fillcolor = lightgray; label = "tree 0";
// branches
branch0_0 [label = "3", shape = none, fillcolor = none];
branch0_0 -> branch0_1;
branch0_1 [label = "0", shape = none, fillcolor = none];
branch0_1 -> branch0_2 [style = dashed];
branch0_2 [label = "1", shape = none, fillcolor = none];
branch0_2 -> leaf0_1 [style = dashed, color = royalblue];
branch0_2 -> leaf0_2 [color = royalblue];
branch0_1 -> branch0_3;
branch0_3 [label = "2", shape = none, fillcolor = none];
branch0_3 -> leaf0_3 [style = dashed, color = royalblue];
branch0_3 -> leaf0_4 [color = royalblue];
// leaves
leaf0_1 [label = "u"];
leaf0_2 [label = "v"];
leaf0_3 [label = "x"];
leaf0_4 [label = "y"];
}
// position the clusters (trees)
{rank=same branch1_0 -> branch0_1 [style=invis weight=0]}
// a kludge, we'll add this edge in later
graph [comment="branch0_0 -> branch1_0 [color = firebrick, style = dashed constraint=false weight=0 ];"]
}
The "problem" is the cluster-to-cluster branch, so we remove it (for the first dot pass). And we add the invisible edge to position the clusters where we want them.
Run this input into dot -Tdot >myfile.dot. This sets positions for all nodes & edges.
Run that thru gawk (any language) to un-comment the commented branch(s) and insert into the file.
Finally, neato -n2 -Tpng fixedfile >fixed.png
(yuck, but it works)
f=atrie4.gv;
T=png; F=`basename $f .gv`;dot -Tdot $f >$F.dot;
gawk '
$1~/comment/{
sub(/[\t ]*comment="/,"")
sub(/"[\],;]?[\t ]*$/,"")
add[++a]=$0
next
}
{oline[++o]=$0}
END{
for (i=1;i<o;i++)print oline[i]
for (i=1;i<=a;i++)print add[i]
print oline[o]
}' $F.dot|
neato -n2 -Tpng >$F.$T
firefox $F.$T
I have a number of boxes that are put on the same level as such:
via multiple {rank=same a3 b3_1 b3_2 c3_1 c3_2 d3_1 d3_2}; lines whereas I define my elements with a3 [label = "Assigned"]; lines.
I'd like to get a (dotted, if possible) box around all elements that are on the same level, as such (mockup via editor):
The whole source looks as follows:
digraph customer {
layout=dot
label = "some diagram";
labelloc = "t"; // place the label at the top
node [shape=record];
{rank=same a1 b1 c1 d1};
{rank=same a2 b2 c2 d2};
{rank=same a3 b3_1 b3_2 c3_1 c3_2 d3_1 d3_2};
{rank=same a4 b4_1_1 b4_1_2 b4_2_1 b4_2_2 c4_1_1 c4_1_2 c4_2_1 c4_2_2 d4_1_1 d4_1_2 d4_2_1 d4_2_2};
{rank=same a5 b5_1 b5_2 b5_3 b5_4 c5_1 c5_2 c5_3 c5_4 d5_1 d5_2 d5_3 d5_4};
{rank=same a6 b6_1 b6_2 b6_3 b6_4 c6_1 c6_2 c6_3 c6_4 d6_1 d6_2 d6_3 d6_4};
a1 [label = "Level 1"];
a2 [label = "Level 2"];
a3 [label = "Level 3"];
a4 [label = "Level 4"];
a5 [label = "Level 5"];
a6 [label = "Level 6"];
a1 -> a2 -> a3 -> a4; a4 -> a5 [label = "case ..." ]; a5 -> a6;
b1 [label = "Text A"];
b2 [label = "false"];
b3_1 [label = "no"];
b3_2 [label = "yes"];
b4_1_1 [label = "same"];
b4_1_2 [label = "different"];
b4_2_1 [label = "same"];
b4_2_2 [label = "different"];
b5_1 [label = "no", fillcolor = red, style=filled];
b5_2 [label = "no", fillcolor = red, style=filled];
b5_3 [label = "no", fillcolor = red, style=filled];
b5_4 [label = "yes", fillcolor = green, style=filled];
b6_1 [label = "yes", fillcolor = green, style=filled];
b6_2 [label = "yes", fillcolor = green, style=filled];
b6_3 [label = "yes", fillcolor = green, style=filled];
b6_4 [label = "yes", fillcolor = green, style=filled];
b1 -> b2;
b2 -> b3_1; b3_1 -> b4_1_1; b4_1_1 -> b5_1 [label = "A" ]; b5_1 -> b6_1;
b3_1 -> b4_1_2; b4_1_2 -> b5_2 [label = "B" ]; b5_2 -> b6_2;
b2 -> b3_2; b3_2 -> b4_2_1; b4_2_1 -> b5_3 [label = "C" ]; b5_3 -> b6_3;
b3_2 -> b4_2_2; b4_2_2 -> b5_4 [label = "D" ]; b5_4 -> b6_4;
subgraph clusterone {
a1; b1; c1; d1;
label="level 1";
graph[style=dotted];
}
c1 [label = "Text B"];
c2 [label = "true"];
c3_1 [label = "no"];
c3_2 [label = "yes"];
c4_1_1 [label = "same"];
c4_1_2 [label = "different"];
c4_2_1 [label = "same"];
c4_2_2 [label = "different"];
c5_1 [label = "no", fillcolor = red, style=filled];
c5_2 [label = "no", fillcolor = red, style=filled];
c5_3 [label = "yes", fillcolor = green, style=filled];
c5_4 [label = "yes", fillcolor = green, style=filled];
c6_1 [label = "yes", fillcolor = green, style=filled];
c6_2 [label = "yes", fillcolor = green, style=filled];
c6_3 [label = "yes", fillcolor = green, style=filled];
c6_4 [label = "yes", fillcolor = green, style=filled];
c1 -> c2;
c2 -> c3_1; c3_1 -> c4_1_1; c4_1_1 -> c5_1 [label = "E" ]; c5_1 -> c6_1;
c3_1 -> c4_1_2; c4_1_2 -> c5_2 [label = "F" ]; c5_2 -> c6_2;
c2 -> c3_2; c3_2 -> c4_2_1; c4_2_1 -> c5_3 [label = "G" ]; c5_3 -> c6_3;
c3_2 -> c4_2_2; c4_2_2 -> c5_4 [label = "H" ]; c5_4 -> c6_4;
d1 [label = "(else)"];
d2 [label = "???", fillcolor = yellow, style=filled];
d3_1 [label = "no"];
d3_2 [label = "yes"];
d4_1_1 [label = "same"];
d4_1_2 [label = "different"];
d4_2_1 [label = "same"];
d4_2_2 [label = "different"];
d5_1 [label = "no", fillcolor = red, style=filled];
d5_2 [label = "no", fillcolor = red, style=filled];
d5_3 [label = "no", fillcolor = red, style=filled];
d5_4 [label = "no", fillcolor = red, style=filled];
d6_1 [label = "yes", fillcolor = green, style=filled];
d6_2 [label = "yes", fillcolor = green, style=filled];
d6_3 [label = "yes", fillcolor = green, style=filled];
d6_4 [label = "yes", fillcolor = green, style=filled];
d1 -> d2;
d2 -> d3_1; d3_1 -> d4_1_1; d4_1_1 -> d5_1 [label = "I" ]; d5_1 -> d6_1;
d3_1 -> d4_1_2; d4_1_2 -> d5_2 [label = "J" ]; d5_2 -> d6_2;
d2 -> d3_2; d3_2 -> d4_2_1; d4_2_1 -> d5_3 [label = "K" ]; d5_3 -> d6_3;
d3_2 -> d4_2_2; d4_2_2 -> d5_4 [label = "L" ]; d5_4 -> d6_4;
}
By some reason it conflicts with rank=same declaration.
Try removing it and use cluster instead with rank=same inside, like this:
subgraph cluster_one {
label="cluster one";
rank=same;
style=dotted;
a1 b1 c1 d1
};
subgraph cluster_two {
label="cluster two";
rank=same;
style=dotted;
a2 b2 c2 d2
};
or even shorter (one line):
subgraph cluster_one { label="cluster one" rank=same style=dotted a1 b1 c1 d1 }
Keep in mind, that width of subgraphs will not be the same, as it used to be.
I'm trying to obtain nested subgraphs in graphviz.
Graphviz version is 2.38.0 (20140413.2041)
Here is the code:
digraph G {
subgraph cluster_win {
style=filled;
color=lightgrey;
label = "Windows"
subgraph extra_enabled {
fillcolor = "#EDF1F2";
color = "#028d35";
label="Subdirectory extra included";
node [style=filled,color=white];
config_debug1 [label = "Configure Debug"];
config_release1 [label = "Configure Release"];
build_debug1 [label = "Build"];
build_release1 [label = "Build"];
config_debug1 -> build_debug1;
config_release1 -> build_release1;
shape=rect;
style=rounded;
}
subgraph extra_disabled {
label = "Subdirectory extra excluded";
config_debug2 [label = "Configure Debug"];
config_release2 [label = "Configure Release"];
build_debug2 [label = "Build"];
build_release2 [label = "Build"];
config_debug2 -> build_debug2;
config_release2 -> build_release2;
}
checkout [style=filled, color=white];
checkout -> extra_enabled;
checkout -> extra_disabled;
}
start -> checkout;
start [label="git push"; shape=Mdiamond];
}
And this is the result.
Graphviz draws two ordinary nodes "extra_enabled" and "extra_disabled". However, I want them to be subgraphs, containing nodes "Configure Release", "Configure Debug", "Build" and another "Build".
How can I fix it?
You need to do two things:
Connect nodes only, you cannot connect to a cluster
Cluster names need to be prefixed by cluster_
Applying this to your code
digraph G {
subgraph cluster_win {
style=filled;
color=lightgrey;
label = "Windows "
subgraph cluster_extra_enabled {
fillcolor = "#EDF1F2";
color = "#028d35";
label="Subdirectory extra included";
node [style=filled,color=white];
config_debug1 [label = "Configure Debug"];
config_release1 [label = "Configure Release"];
build_debug1 [label = "Build"];
build_release1 [label = "Build"];
config_debug1 -> build_debug1;
config_release1 -> build_release1;
shape=rect;
style=rounded;
}
subgraph cluster_extra_disabled {
label = "Subdirectory extra excluded";
config_debug2 [label = "Configure Debug"];
config_release2 [label = "Configure Release"];
build_debug2 [label = "Build"];
build_release2 [label = "Build"];
config_debug2 -> build_debug2;
config_release2 -> build_release2;
}
checkout [style=filled, color=white];
checkout -> config_debug1;
checkout -> config_release2;
}
start -> checkout;
start [label="git push"; shape=Mdiamond];
}
I get
which is probably close to what you want. Note that I have added a few spaces to the label "Windows " to get it out of the way of the arrow. You could also use labeljust. There are also ways to make the edge end at the boundary of the cluster, but that would have needed a lot more editing on my part which I was not sure you want it.
I just wanted to append to the answer that vaettchen added. While it is correct that you cannot directly connect edges to clusters, edges must travel between nodes, there is a way to do so visually with lhead and ltail.
You can do the following:
node1 -> node2 [lhead=cluster_name_1, ltail=cluster_name_2]
Which will cut the connectors off at the limit of the cluster to connect clusters, this is just visual and is logged as a node connection, but it is a nicer way to visually display connections between whole clusters.
How to set the graph to try to fill the area allocated to it? With an increase in the number of nodes, it simply decreases in size, but also remains in one line, although the vertical size (40) allows placement down. If you remove the rankdir, then it places vertically, but also in one line.
digraph "test_graph"{
rankdir = LR;
bgcolor = whitesmoke;
graph [size = "15, 40"];
node [shape = circle,
style = filled,
margin = 0,
fontsize = 14,
color = sandybrown];
edge [fontsize = 10,
arrowhead = vee];
1->2 [label = "R"];
2->3 [label = "R"];
3->4 [label = "R"];
3->5 [label = "B"];
4->1 [label = "R"];
5->6 [label = "U"];
6->7 [label = "U"];
7->8 [label = "U"];
7->9 [label = "F"];
8->5 [label = "U"];
9->10 [label = "F"];
10->11 [label = "D"];
11->12 [label = "D"];
12->13 [label = "D"];
13->10 [label = "D"];
13->14 [label = "L"];
14->15 [label = "L"];
15->16 [label = "D"];
16->17 [label = "D"];
17->18 [label = "D"];
17->19 [label = "L"];
18->15 [label = "D"];
19->20 [label = "F"];
20->21 [label = "F"];
21->22 [label = "F"];
21->23 [label = "L"];
22->19 [label = "F"];
23->24 [label = "L"];
24->25 [label = "F"];
}
You will need to select suitable nodes that
are connected by one edge
connect to other nodes in a way that fills the available width as you like it
and then
connect them in the desired order by invisible edges (so that you avoid graphviz reordering them)
ranking them on the same lavel so that they appear one below the other
In concrete terms this means that adding
1 -> 10 -> 19[ style = invis ];
{ rank = same; 1 10 19 }
just before the closing curly brace, as the last two lines, will produce
which is, as far as I understand your requirement, what you want.