Search code examples
graphviz

strictly left to right arcs in graphviz


I would like to create a figure where the arcs only enter a node on the left hand side, and exit only from the right hand side.

I have created the following dot file, and its picture is shown below:

digraph net {
    "C0" [shape=oval label="C0"]
    "C1" [shape=oval label="C1"]
    "B0" [shape=box label="B0"]
    rankdir="LR"
    "C0" -> "B0"
    "B0" -> "C1"
    "C1" -> "B0"
}

enter image description here

But I would like to see the arc C1->B0 as exiting C1 from its right hand side, and curving (or even a rectangular arc) back to the left side of B0. How do I do that?


Solution

  • Use port positions (https://graphviz.org/docs/attr-types/portPos/) to specify tail & head positions.
    Note the syntax including/excluding " character. (The "s are not needed for these node names)

    digraph net {
        "C0" [shape=oval label="C0"]
        "C1" [shape=oval label="C1"]
        "B0" [shape=box label="B0"]
        rankdir="LR"
        "C0" -> "B0"
        "B0" -> "C1"
        "C1":e -> B0:w  // note portpos with/without "s.  Both work
    }
    

    Giving:
    enter image description here