There is no easy way to specify that two connected nodes be “ranked” close to each other. TBbalance attribute comes close, but “no cigar”. Makes sense, but not today.
Here is a pipeline that does what you ask:
- run your Python prog, modified to produce an output similar to the file shown below, but create dot output
- run this command:
dot -Gphase=3 myfile.dot -o myNewFile.dot
Ignore error/warnings about no position for edge
(seemingly a bug in dot)
- then
gvpr -aD -cf makeClose.gvpr myNewFile.dot | dot -Tpng ...
makeClose.gvpr:
BEG_G{
int doubleRanks;
int i=0;
int delta;
string help="no help, yet";
doubleRanks=0;
while (i<ARGC) {
if (ARGV[i]=="D") {
doubleRanks=1;
print("// halving rank distance");
}else{
printf(2, help);
exit (1);
}
i++;
}
$G.phase="";
}
E[makeclose=="1"]{
edge_t anEdge;
node_t tailtailNode;
anEdge=fstin($.tail);
tailtailNode=anEdge.tail;
print("// edge: ", $,name, " ",tailtailNode.name);
delta=(int)$.head.rank - (int)tailtailNode.rank;
print("// delta: ",delta);
if (doubleRanks){
delta=delta/2;
}
delta--;
print("// delta: ",delta);
anEdge.minlen=delta;
print ("// minlen: ", anEdge.minlen, " ", $.head.rank, " ",tailtailNode.rank);
}
Finally, the modified version of your file (I removed attributes that were not needed, added group=same a few places, and created a new attribute makeclose):
digraph {
graph [bb="0,0,615.5,2108",
// nodesep=0.3,
// pad=1,
// ranksep=.3,
splines=true
//splines=polyline
TBbalance=min
];
node [label="\N"];
"place order" [color=powderblue,
height=0.56944,
label="place order
168",
shape=box,
style="rounded,filled",
width=2];
o_2 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
"place order" -> o_2 [arrowhead=none,
color=black,
labeldistance=10,
];
o_4 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
"place order" -> o_4 [arrowhead=none,
color=black,
labeldistance=10,
];
o_5 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=8,
xlp="193.38,2052.3"];
"place order" -> o_5 [arrowhead=none,
color=black,
labeldistance=10,
];
o_1 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
{rank=same o_1 o_2 }
o_1 -> o_2 [arrowhead=none,
color=black,
label=125,
lp="135.12,1988.8",
style=dashed];
o_3 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_1 -> o_3 [arrowhead=none,
color=black,
labeldistance=10,
];
i_1 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=35,
xlp="45.01,1274.7"];
o_2 -> i_1 [arrowhead=none,
color=black,
label="35 / 0.97",
labeldistance=10,
lp="24.375,1643.4",
];
{rank=same o_3 o_4}
o_3 -> o_4 [arrowhead=none,
color=black,
label=26,
lp="185.75,1943.8",
style=dashed];
i_3 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=118,
xlp="235.63,1677.4"];
o_3 -> i_3 [arrowhead=none,
color=black,
label="118 / 0.99",
labeldistance=10,
lp="269.75,1823.4",
];
i_15 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=6,
xlp="99.385,1800.4"];
o_4 -> i_15 [arrowhead=none,
color=black,
label="6 / 0.86",
labeldistance=10,
lp="127,1862.9",
];
o_5 -> o_1 [arrowhead=none,
color=black,
labeldistance=10,
];
"pick item" [color=powderblue,
height=0.56944,
label="pick item
138",
shape=box,
style="rounded,filled",
width=2];
o_6 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=54,
xlp="96.01,1164"];
"pick item" -> o_6 [arrowhead=none,
color=black,
labeldistance=10,
];
i_6 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_6 -> i_6 [arrowhead=none,
color=black,
label="54 / 0.95",
labeldistance=10,
lp="171.38,1078.5",
];
"confirm order" [color=powderblue,
height=0.56944,
label="confirm order
159",
shape=box,
style="rounded,filled",
width=2];
o_7 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=69,
xlp="312.01,1568.4"];
"confirm order" -> o_7 [arrowhead=none,
color=black,
labeldistance=10,
];
o_8 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=13,
xlp="232.01,1568.4"];
"confirm order" -> o_8 [arrowhead=none,
color=black,
labeldistance=10,
];
o_10 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_7 -> o_10 [arrowhead=none,
color=black,
labeldistance=10,
];
o_9 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_8 -> o_9 [arrowhead=none,
color=black,
labeldistance=10,
];
{rank=same o_9 o_10 }
o_9 -> o_10 [arrowhead=none,
color=black,
label=5,
lp="261.38,1505",
style=dashed];
i_7 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_9 -> i_7 [arrowhead=none,
color=black,
label="18 / 0.95",
labeldistance=10,
lp="236.38,1263.2",
];
i_4 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=53,
xlp="345.01,1321.5"];
o_10 -> i_4 [arrowhead=none,
color=black,
label="20 / 0.95",
labeldistance=10,
lp="360.38,1384",
];
"pay order" [color=powderblue,
height=0.56944,
label="pay order
74",
shape=box,
style="rounded,filled",
width=2];
o_11 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=27,
xlp="345.01,1210.7"];
"pay order" -> o_11 [arrowhead=none,
color=black,
labeldistance=10,
];
i_5 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_11 -> i_5 [arrowhead=none,
color=black,
label="27 / 0.96",
labeldistance=10,
lp="379.38,1118",
];
"create package" [color=powderblue,
height=0.56944,
label="create package
99",
shape=box,
style="rounded,filled",
width=2];
o_12 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=95,
xlp="264.01,842.59"];
"create package" -> o_12 [arrowhead=none,
color=black,
labeldistance=10,
];
i_12 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=95,
xlp="264.01,725.61"];
o_12 -> i_12 [arrowhead=none,
color=black,
label="94 / 0.99",
labeldistance=10,
lp="298.38,772.61",
];
"send package" [color=powderblue,
height=0.56944,
label="send package
95",
shape=box,
style="rounded,filled",
width=2];
o_13 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=53,
xlp="239.01,632.13"];
"send package" -> o_13 [arrowhead=none,
color=black,
labeldistance=10,
];
o_14 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=30,
xlp="290.01,632.13"];
"send package" -> o_14 [arrowhead=none,
color=black,
labeldistance=10,
];
i_13 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=53,
xlp="240.01,289.19"];
o_13 -> i_13 [arrowhead=none,
color=black,
label="46 / 0.98",
labeldistance=10,
lp="271.38,456.92",
];
i_19 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_14 -> i_19 [arrowhead=none,
color=black,
label="30 / 0.97",
labeldistance=10,
lp="395.38,562.15",
];
"package delivered" [color=powderblue,
height=0.56944,
label="package delivered
83",
shape=box,
style="rounded,filled",
width=2];
o_15 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=5,
xlp="269.38,195.71"];
"package delivered" -> o_15 [arrowhead=none,
color=black,
labeldistance=10,
];
i_17 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=5,
xlp="269.38,78.73"];
o_15 -> i_17 [arrowhead=none,
color=black,
label="5 / 0.83",
labeldistance=10,
lp="297,125.73",
];
"item out of stock" [color=powderblue,
height=0.56944,
label="item out of stock
26",
shape=box,
style="rounded,filled",
width=2];
o_16 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=25,
xlp="96.01,1706.9"];
"item out of stock" -> o_16 [arrowhead=none,
color=black,
labeldistance=10,
];
i_16 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=25,
xlp="96.01,1538.9"];
o_16 -> i_16 [arrowhead=none,
color=black,
label="18 / 0.95",
labeldistance=10,
lp="130.38,1603.7",
];
"reorder item" [color=powderblue,
height=0.56944,
label="reorder item
25",
shape=box,
style="rounded,filled",
width=2];
o_17 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=13,
xlp="96.01,1430"];
"reorder item" -> o_17 [arrowhead=none,
color=black,
labeldistance=10,
];
i_2 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=13,
xlp="96.01,1274.7"];
o_17 -> i_2 [arrowhead=none,
color=black,
label="9 / 0.90",
labeldistance=10,
lp="127,1344.5",
];
"payment reminder" [color=powderblue,
height=0.56944,
label="payment reminder
6",
shape=box,
style="rounded,filled",
width=2];
"failed delivery" [color=powderblue,
height=0.56944,
label="failed delivery
44",
shape=box,
style="rounded,filled",
width=2];
o_18 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=30,
xlp="378.01,421.67"];
"failed delivery" -> o_18 [arrowhead=none,
color=black,
labeldistance=10,
];
o_19 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=14,
xlp="429.01,421.67"];
"failed delivery" -> o_19 [arrowhead=none,
color=black,
labeldistance=10,
];
i_14 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=30,
xlp="291.01,289.19"];
o_18 -> i_14 [arrowhead=none,
color=black,
label="23 / 0.96",
labeldistance=10,
lp="327.38,336.19",
];
i_18 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
o_19 -> i_18 [arrowhead=none,
color=black,
label="14 / 0.93",
labeldistance=10,
lp="420.38,336.19",
];
i_1 -> "pick item" [arrowhead=vee,
makeclose=1
color=black,
dir=forward,
];
i_3 -> "confirm order" [arrowhead=vee,
makeclose=1
color=black,
dir=forward,
];
i_15 -> "item out of stock" [arrowhead=vee,
color=black,
dir=forward,
];
i_8 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09];
i_6 -> i_8 [arrowhead=none,
color=black,
labeldistance=10,
];
{rank=same i_7 i_8}
i_7 -> i_8 [arrowhead=none,
color=black,
label=64,
lp="243.75,976.55",
style=dashed];
i_10 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=2,
xlp="187.38,936.07"];
i_7 -> i_10 [arrowhead=none,
color=black,
labeldistance=10,
];
i_4 -> "pay order" [arrowhead=vee,
color=black,
dir=forward,
];
{rank=same i_5 i_6}
i_5 -> i_6 [arrowhead=none,
color=black,
label=33,
lp="330.75,1021.5",
style=dashed];
i_9 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=21,
xlp="385.01,936.07"];
i_5 -> i_9 [arrowhead=none,
color=black,
labeldistance=10,
];
i_12 -> "send package" [arrowhead=vee,
color=black,
dir=forward,
];
i_13 -> "package delivered" [arrowhead=vee,
makeclose=1
color=black,
dir=forward,
];
i_19 -> "failed delivery" [arrowhead=vee,
color=black,
dir=forward,
];
i_17 -> "payment reminder" [arrowhead=vee,
color=black,
dir=forward,
];
i_16 -> "reorder item" [arrowhead=vee,
color=black,
dir=forward,
];
i_2 -> "pick item" [arrowhead=vee,
color=black,
dir=forward,
];
i_14 -> "package delivered" [arrowhead=vee,
makeclose=1
color=black,
dir=forward,
];
{rank=same i_18 i_19 }
i_18 -> i_19 [arrowhead=none,
color=black,
label=30,
lp="608.75,375.69",
style=dashed];
i_20 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=44,
xlp="538.01,242.45"];
i_18 -> i_20 [arrowhead=none,
color=black,
labeldistance=10,
];
i_9 -> "create package" [arrowhead=vee,
color=black,
dir=forward,
];
i_11 [color=black,
height=0.09,
shape=point,
style=filled,
width=0.09,
xlabel=2,
xlp="265.38,936.07"];
i_8 -> i_11 [arrowhead=none,
color=black,
labeldistance=10,
];
i_10 -> "create package" [arrowhead=vee,
color=black,
dir=forward,
];
i_11 -> "create package" [arrowhead=vee,
color=black,
dir=forward,
];
i_20 -> "failed delivery" [arrowhead=vee,
color=black,
dir=forward,
];
}