labelgraph-theorygraphviz

Equivalent of `xlabel` for clusters in graphviz?


The DOT code

digraph {
    newrank=true;

    {
        node [shape=box]
        edge [dir=none, style=dotted]
        
        A -> B
        B -> C
        C -> D
    }

    Aa;Ab
    subgraph cluster_0 {   
        label="subgraph"
        Ba;Bb
    }
    Ca;Cb [xlabel="xlabel Cb"]

    { rank=same; A; Aa; Ab}
    { rank=same; B; Ba; Bb}
    { rank=same; C; Ca; Cb}
    { rank=same; D; }
}

(thanks welgriv,dubek)

generates

graph.

We can see the first edge shows 6.5 dots, while the other two show 5.5, because the cluster's label, "subgraph", is affecting the positioning of other nodes, maybe because GZ internally treats it as some sort of node.

This is annoying, I only want nodes to affect nodes, not cluster labels.

Node Cb's xlabel does not do this.

xlabel does not apply to clusters, only edges and nodes.

Is there some equivalent of xlabel for clusters? Or a better option than the ones below.

Known workaround options:

  1. use node xlabel to mimic cluster label. Note, it cannot be manually positioned.
  2. use node label, place with lp. Example.
  3. cluster all of the rightside nodes, then set clusters' pencolor and label attrs to invis and a whitespace respectively, except for the one desired.

Solution

  • A arguably cleaner way to do #3 is to put each set of nodes in a cluster, but set peripheries=0 instead of fiddling with pencolor
    or
    use the margin attribute on the one cluster. But note that the box around the cluster is snuggier on all sides

    digraph {
        newrank=true;
    
        {
            node [shape=box]
            edge [dir=none, style=dotted]
            
            A -> B
            B -> C
            C -> D
        }
        subgraph cluster_00 {
          margin=2
            label="subgraph"
            Aa;Ab
        }
    
        subgraph cluster_0 {
        margin=2
            label="subgraph"
            Ba;Bb
        }
        Ca;Cb [xlabel="xlabel Cb"]
    
        { rank=same; A; Aa; Ab}
        { rank=same; B; Ba; Bb}
        { rank=same; C; Ca; Cb}
        { rank=same; D; }
    }
    

    Giving:
    enter image description here