Does a subgraph (non-cluster!) group the nodes?

Question regarding DOT Language | Graphviz

Subgraphs play three roles in Graphviz. First, a subgraph can be used to represent graph structure, indicating that certain nodes and edges should be grouped together.

But is that used anywhere? Dot doesn’t seem to care about the grouping, unless it is a cluster.

digraph G {
  subgraph cluster_test {c1 c2}
  a -> b 
  a ->c1
  b->c2
}

vs

digraph G {
  subgraph test {c1 c2}
  a -> b 
  a ->c1
  b->c2
}

While cluster subgraphs physically group/gather their embedded nodes, non-cluster subgraphs (only) logically effect the embedded nodes/edges - by applying common attributes to the set.

Hi Steve and others,

I think I’d like to use this subgraph feature to physically group nodes. I’m trying to understand what you are referring to as a cluster? I don’t see anything in the AGraph class documentation about a cluster? I’m taking two nodes that have already been added to the graph and putting them in a python list and doing the G.add_subgraph(list) function call. The result is they do not seem to be grouped together in the resulting graph.

I look at your example and the only difference I see is in the name ‘cluster_test’ vs. ‘cluster’.

Any help is appreciated!

Thanks, Ed Mazurek

OK I found that cluster is an attribute so I specified ‘cluster=True’ on the add_subgraph()… The script seemed to run OK but I didn’t see any difference. I’m using prog=‘neato’. I’m not really sure if it’s valid for neato?

OK now I find a post that neato doesn’t support clusters?

Any help is appreciated.

Thanks, Ed

Hi Ed!
I didn’t even know about the cluster property. Normally, you use the shortcut and write the “cluster” or “cluster_” as part of the name.

Steve,
forgot to say “thanks” for your answer. It makes sense what you say, but i think the wording in the documentation could be improved. :wink:
/Klaus

dot and fdp are the only layout engines that usefully recognize clusters. (ie. they physically group the nodes in the cluster)

OK well I tried ldp and didn’t get the grouping but the graph looks worse. Mine is a 3 tiered hierarchical graph and I was using the mode=hier in neato. I tried dot and that produced an unreadable graph. So anyone have any suggestions for a 3 tiered graph?

Thanks in advance!
Ed

Can you share the input file and/or a sketch of your desired output?

The discrepancy between cluster_ prefixes and cluster=true unfortunately has a messy history. They’re still not entirely equivalent, Stop requiring clusters / subgraphs with attributes to use the cluster_ id prefix (#2187) · Issues · graphviz / graphviz · GitLab.