Search code examples
graphviz

How do I force straight edges in a (simple) Digraph?


I have the following simple digraph:

digraph clientproxyserver {
  "Client" -> "Proxy" [ label="Request from Client" ];
  "Proxy" -> "Server" [ label="Forwarded Request" ];
  "Server" -> "Proxy" [ label="Response from Server" ];
  "Proxy" -> "Client" [ label="Forwarded Response" ];
}

Running this trough dot:

dot -Grankdir=LR -Nshape=box -Nheight=1 -Tpng -ocps.png cps.gv

I get the following result:

Resulting graph

What can I do to make the two bottom edges straight lines?


Solution

  • That's what usually the option splines=ortho is for:

    digraph clientproxyserver {
        rankdir=LR;
        node[shape=box, height=1];
        splines=ortho
      "Client" -> "Proxy" [ label="Request from Client" ];
      "Proxy" -> "Server" [ label="Forwarded Request" ];
      "Server" -> "Proxy" [ label="Response from Server" ];
      "Proxy" -> "Client" [ label="Forwarded Response" ];
    }
    

    Unfortunately, the placement of the edges/labels is very confusing:

    otho layout

    In my experience, ortho splines produce rarely a satisfying result.

    An other option would be to use splines=polyline:

    polyline layout