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.

Hi Steve,

Sorry I just saw this… I’m looking for something like this where it is hierarchical and thing 3a and thing 3b are “joined”. The dotted line would be a nice plus.

If there are any suggestions on how to achieve something like this it would be much appreciated!

Thanks Ed

Thing A, B an4 could be done w/ simple nodes, but here they are all HTML labels.
Record labels (same page) would also work, except for the dashed-line.

graph things {
  splines=false
  nodesep=.8

    A [shape=plain label=<
     <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" bgcolor="lightblue">
       <TR><TD PORT="f0">Thing A</TD></TR>
     </TABLE>>];
    B [shape=plain label=<
     <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" bgcolor="lightblue">
       <TR><TD PORT="f0">Thing B</TD></TR>
     </TABLE>>];

    t42 [shape=rect style=dashed label=<
     <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" bgcolor="lightblue">
       <TR><TD PORT="p3a">Thing 3a</TD><TD PORT="p3b">Thing 3b</TD></TR>
     </TABLE>>];
     
    t4 [shape=plain label=<
     <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" bgcolor="lightblue">
       <TR><TD PORT="f0">Thing 4</TD></TR>
     </TABLE>>];

  A -- t42:p3a
  B -- t42:p3b
  t42:p3a -- t4
  t42:p3b -- t4  
}

Giving:

Hi thanks but maybe I’m missing something. I want to do this with pygraphviz. I want the 3 tiered hierarchical format and the grouping of thing 3a/3b. Not there will be multiple other things in the middle level (e,g, thing 4a/4b, thing 5a/5b, etc.). I’m using neato with ‘heir’ and it’s sort of OK but I need the grouping.

Thanks, Ed

Can you show us a larger example of the output you are looking for? Even a hand sketch? It is very difficult to improve a graph without seeing the input and outputs.
If there is an issue with proprietary content, there is an anonymizer you can use.
If you want a 3-level format showing a hierarchical structure, dot is probably the engine needed. I understand that a previous dot attempt was not acceptable, but there many ways to tune a graph with dot.