0

enter image description hereI want to draw a graph with "dot" format. The graph I want is a (sub)graph in a graph style. The subgraph (a child) has internal graph, and the (parent) graphs are connected among the parents, and does not connect to children that are connected only in the subgraph.

Could you please guide how writing such style with the dot-format, with an example?

S. Takano
  • 313
  • 2
  • 12

1 Answers1

0

Good news:

  • creating your "parent nodes" is pretty easy. Graphviz, (dot) calls them "cluster subgraphs" (or clusters). (well documented on p. 19 of https://www.graphviz.org/pdf/dotguide.pdf) see below for an example.

Bad news:

  • explicitly sizing clusters is very difficult. Dot sizes a cluster to be just big enough to contain its nodes.
  • explicitly positioning clusters is also quite difficult. Dot positions clusters based on the "best" positioning of the component nodes, specifically the edges that connect nodes within the various clusters.
  • drawing edges from one cluster to another is a kludge. You define an edge from a node contained within one cluster to another node contained within a different cluster and instruct dot to clip that edge so it appears to be from cluster to cluster. This uses the attribute compound=true. (again, read the documentation listed above)

Finally: the fdp engine allows cluster-to-cluster edges, but you lose the directionality of the edges

Drawn with dot:

digraph C {
  graph [compound=true] // allows edges to/from clusters

// create an extra cluster to try to keep clusterA above clusterB
subgraph clusterWrapper {
  graph [peripheries=0]  // no box around

  subgraph clusterA {
    graph [peripheries=1]  // box around
    a -> c
    b->c
    c->d
  }
  subgraph clusterB {
    graph [peripheries=1]  // box around  
    f->g
    e->g
  }
  }  // end of wrapper

  subgraph clusterC {
    edge [dir=none ]  // no arrowheads
    h->k
    i->k
    i->l
    j->l
    {rank=same  h->i->j [style=invis]}
  }

  b->f [ltail=clusterA, lhead=clusterB];
  l:s->b:n [ltail=clusterC, lhead=clusterA];
  l->f [style=invis weight=50]
}

Giving:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11