Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphViz: how to connect a node to the containing subgraph

I just learned how to connect nodes and subgraphs here on Stackoverflow. However, I want to connect a node to the containing subgraph:

digraph G {
    compound=true;
    subgraph cluster0 {
        a -> b;
        a -> c;
        c -> {a b c} [lhead=cluster0];
    }
    c -> d;
    d -> {a b c} [lhead=cluster0];
}

A quick sketch what I mean:

enter image description here

I want to connect d -> {a b c}, but for clarity reasons, I don't want to draw three different arrows, but just one arrow to the grouping of nodes. One way to do that is only list one arrow, like d -> a. That works, but is there a way to "collapse" three arrows into one when the head points to a cluster?

However, c -> {a b c} is not possible to point to a cluster, because c is part of that cluster. Is there a way to go around this?

like image 602
doekman Avatar asked Oct 17 '22 12:10

doekman


1 Answers

you will need some scaffolding i.e. invisible node (and maybe edges) e.g.:

digraph top {
    compound=true
    node[shape=rectangle]
    subgraph cluster1 {
        a->{b c}
    }
    c->d
    d->b[lhead=cluster1]
    ca[shape=point height=0] // make ca invisible
    a->ca:n[dir=back ltail=cluster1] // by drawing the arrow backward we get more control of the layout, n and s compass make the edge go smooth when enter and exiting ca
    ca:s->c[dir=none] // no arrow on the tail part
}

rendered on viz-js.com:

enter image description here

like image 66
Jens Avatar answered Oct 20 '22 23:10

Jens