Search code examples
graphviz

graphwiz: How to draw an edge from a node to a cluster?


I'd like to draw an edge from a node to the center of a cluster.

Here is an attempt:

digraph top {
    compound=true
    node[shape=rectangle]
    subgraph cluster1 {
        a_very_long_label
        b
        i [fixedsize=true,margin=0,width=0,style=invis]
        c
        d
    }
    p->i [lhead=cluster1]
}

How can I do it without the "i" node and the arrow's port is centered at the cluster? rendered by magjac.com


Solution

  • You can get pretty close using an "html-like" node label (see https://graphviz.org/doc/info/shapes.html#html)

    digraph top {
        compound=true
        node[shape=rectangle]
        i [label=<<TABLE CELLSPACING="12" CELLPADDING="8" BORDER="0" CELLBORDER="1">
        <TR>
          <TD>a_very_long_label</TD>
          <TD>b</TD>
          <TD>c</TD>
          <TD>d</TD>
        </TR>  
        </TABLE>>]
    
        p->i 
    }
    

    Giving:
    enter image description here