Search code examples
graphviz

How can I make a graph in graphviz with an edge from an external node to an internal one?


I'm trying to figure out how to make graphviz generate an image like this:

enter image description here

Thanks!


Solution

  • There are three problems:

    1. Getting one node positioned intentionally on top of another
    2. Getting the edge placed as specified
    3. Getting the "B" label placed at the top of the node

    The FAQ (https://www.graphviz.org/faq/#FaqDotWithNodeCoords) tells us how to achieve node and edge placement. Label placement is done using newlines. The code was hand-written.

    digraph ontop {
      big [label="B\n\n\n\n" pos="2,2" shape=square height=1]
      little [label="A" pos="2,2" shape=square height=.4]
      big:e -> little:e
    }
    

    Command line:

    neato -n -Tpng ontop.dot >ontop.png
    

    enter image description here