How can I direct dot to use a shorter edge path?
Asked Answered
W

1

13

The diagram below is laid out almost perfectly, apart from the edge from the left "named pipe" node to "cat", which takes a long circuitous route, instead of the obvious short one I've marked with red on the diagram below. Is there a way to direct dot to use the short edge path? Note that the sequence diagram on the diagram's bottom, must be rendered as it currently appears, i.e. in the left to right order.

enter image description here

This is the code that draws the diagram.

digraph D {
fontname="Arial";
subgraph cluster_async {
    label="Asynchronous processes";
    style=filled;
    color=lightgrey;

    node [shape=box, style=solid, fillcolor=white, fontname="Arial"];
    {
        rank=same;
        npi_0_0_0 [label="named\npipe"];
        npi_0_3_0 [label="named\npipe"];
        npi_0_2_0 [label="named\npipe"];

    }

    node [shape=box, style=bold];
    tee [label="sgsh-tee"];
    "ls -l" -> tee;
    tee -> npi_0_0_0;
    tee -> npi_0_3_0;
    tee -> npi_0_2_0;

    NBYTES [label="sgsh-writeval -s NBYTES"];
    npi_0_3_0 -> "awk '{s += $5} END {print s}'" -> NBYTES;

    NDIRS [label="sgsh-writeval -s NDIRS"];
    npi_0_2_0  -> "grep -c '^d'" -> NDIRS;

    // Put some order in the appearance
    {
        rank=same;
        NDIRS;
        NBYTES;
    }
}

subgraph clustersync {
    label="Synchronous sequence";
    style=dashed;
    start [shape=circle, style=filled, label="", fillcolor=black, width=.2];
    node [shape=box, style=bold, fontname="Arial"];
    npi_0_0_0:sw -> cat:nw [constraint=false];
    "sgsh-readval -s NDIRS" -> echo;
    "sgsh-readval -s NBYTES" -> echo;

    NBYTES -> "sgsh-readval -s NBYTES";
    NDIRS -> "sgsh-readval -s NDIRS";

    end [shape=doublecircle, style=filled, label="", fillcolor=black, width=.2];
    {
        rank=same;
        edge [arrowhead=open];
        start -> cat -> echo -> end;
    }
}
}

(In case you're interested, the diagram illustrates the setup of an example from sgsh.)

Womanly answered 8/6, 2014 at 15:3 Comment(1)
If you don't mind it looks better horizontally and nasty edge is in place. Check graphviz.it/#/kRGFcBhF for the effect.Aleppo
P
3

For this graph, setting splines=ortho will produce a desirable result. enter image description here

Pelion answered 4/6, 2019 at 15:17 Comment(1)
Thanks! The splines=ortho option, which I didn't know, appears to be an incredibly handy styling alternative.Womanly

© 2022 - 2024 — McMap. All rights reserved.