Hi there I want to have a uml sequence diagram with dot language, now I have the following problem I want to have the layout as follows with a, b, c and d in a straight line at top but with the lines going straight to the bottom. How can I achieve that?
a b c d
| | | |
| | | |
perhaps can I achieve that the a, b, c and d with its belonging edges are clusters where I set a different rankdir for the clusters?
EDIT Just found a solution by adding invisible edges between a, b, c and d but any other solutions?
Where there is a will there is a way!
This is an example on how to do that using dot:
digraph SEQ_DIAGRAM {
graph [overlap=true, splines=line, nodesep=1.0, ordering=out];
edge [arrowhead=none];
node [shape=none, width=0, height=0, label=""];
{
rank=same;
node[shape=rectangle, height=0.7, width=2];
api_a[label="API A"];
api_b[label="API B"];
api_c[label="API C"];
}
// Draw vertical lines
{
edge [style=dashed, weight=6];
api_a -> a1 -> a2 -> a3;
a3 -> a4 [penwidth=5, style=solid];
a4 -> a5;
}
{
edge [style=dashed, weight=6];
api_b -> b1 -> b2 -> b3 -> b4;
b4 -> b5 [penwidth=5; style=solid];
}
{
edge [style=dashed, weight=6];
api_c -> c1;
c1-> c2 [penwidth=5, style=solid];
c2 -> c3 -> c4 -> c5;
}
// Draws activations
{ rank=same; a1 -> b1 [label="activate()"]; b1 -> c1 [arrowhead=normal]; }
{ rank=same; a2 -> b2 [style=invis]; b2 -> c2 [label="refund()", arrowhead=normal, dir=back]; }
{ rank=same; a3 -> b3 [arrowhead=normal, dir=back, label="place_order()"]; b3 -> c3; }
{ rank=same; a4 -> b4 [label="distribute()", arrowhead=normal]; }
{ rank=same; a5 -> b5 [style=invis]; b5 -> c5 [label="bill_order()", arrowhead=normal]; }
}
After rendered, this will yield this image:
There are some important hints on how this was achieved:
What you describe seems to be what dot
does by default.
For example, this graph:
digraph SO {
a -> a1 -> a2
b -> b1 -> b2
c -> c1 -> c2
d -> d1 -> d2
}
Comes out like this:
If you have a more complex graph you can force nodes to be at the same height using rank=same
. For example:
digraph SO {
{ rank = same
a b c d
}
a -> a1 -> a2
b -> b1 -> b2 -> b3 -> b4
c -> c1
d -> d1 -> d2 -> d3
d2 -> a2
}
Comes out like this:
However, if you want a
, b
, c
and d
to be in a specific order I think you're going to have to use invisible edges like you suggested. The dot
guide even recommends this:
Edge weights also play a role when nodes are constrained to the same rank. Edges with non-zero weight between these nodes are aimed across the rank in the samedirection (left-to-right, or top-to-bottom in a rotated drawing) as far as possible. This fact may be exploited to adjust node ordering by placing invisible edges (
style="invis"
) where needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With