graphvizdot

How to join edges to same point on node?


I want two edges to connect to the same point on a node, like in this screenshot:

graph with nodes converging on central point

I tried the following simple code but the edges aren't connecting as I want them. I want them to connect to a central point under the node, not inside the node. So if the shape were a box instead plaintext the edges should be connecting underneath the box to the middle of its lower perimeter.

strict graph {

    node [
        shape=plaintext,
    ]

    A
    B
    C

    A -- B
    A -- C
}

graph with nodes converging on peripheral point

I also tried several things using ports but I couldn't get the desired result. What I want is a binary tree of plain text nodes that always follow the shown pattern - so ideally I wouldn't have to set the attribute on each node/edge but could specify the necessary attributes at top level for the whole graph.


Solution

  • If I understand the request, adding ports does the trick. Also added splines=false to guarantee straight lines.

    strict graph {
      splines=false  // for straight lines
        node [
            shape=plaintext,
        ]
    
        A
        B
        C
    
        A:s -- B  // added port
        A:s -- C  // added port
    }
    

    Giving:
    enter image description here