views:

1198

answers:

2

In the DOT language for GraphViz, I'm trying to represent a dependency diagram. I need to be able to have nodes inside a container and to be able to make nodes and/or containers dependent on other nodes and/or containers.

I'm using subgraph to represent my containers. Node linking works just fine, but I can't figure out how to connect subgraphs.

Given the program below, I need to be able to connect cluster_1 and cluster_2 with an arrow, but anything I've tried creates new nodes instead of connecting the clusters:

digraph G {

    graph [fontsize=10 fontname="Verdana"];
    node [shape=record fontsize=10 fontname="Verdana"];

    subgraph cluster_0 {
        node [style=filled];
        "Item 1" "Item 2";
        label = "Container A";
        color=blue;
    }

    subgraph cluster_1 {
        node [style=filled];
        "Item 3" "Item 4";
        label = "Container B";
        color=blue;
    }

    subgraph cluster_2 {
        node [style=filled];
        "Item 5" "Item 6";
        label = "Container C";
        color=blue;
    }

    // Renders fine
    "Item 1" -> "Item 2";
    "Item 2" -> "Item 3";

    // Both of these create new nodes
    cluster_1 -> cluster_2;
    "Container A" -> "Container C";
}
A: 

It's been a while but if I remember correctly you can't connect clusters directly.

What you can do is connect a node in one cluster to a node in another like you have done above with:

"Item 2" -> "Item 3";

I believe clusters and subgraphs are only used to enhance how a group of nodes are displayed and not to define graph connections.

morechilli
I know I can connect nodes between clusters but that's not what I want. I need to be able to connect containers as well. Is there another idiom I should use other than `subgraph cluster`?
Winston Smith
+7  A: 

Hi

The DOT user manual gives the following example of a graph with clusters with edges between clusters

digraph G {
  compound=true;
  subgraph cluster0 {
  a -> b;
  a -> c;
  b -> d;
  c -> d;
  }
  subgraph cluster1 {
  e -> g;
  e -> f;
  }
  b -> f [lhead=cluster1];
  d -> e;
  c -> g [ltail=cluster0,
  lhead=cluster1];
  c -> e [ltail=cluster0];
  d -> h;
}

and edges between nodes and clusters.

HTH

Mark

High Performance Mark
Thanks - that works, but it really feels like an ugly hack. I'm **hoping** I don't have a scenario where I have a container with no nodes.
Winston Smith
In case anyone is interested in, this can cause positioning problems if you have labelled links (edges). While the head or the tail of the edge may be hidden beneath a cluster, the label is still positioned at the midpoint, meaning some edge labels appear to be floating over a cluster instead of being positioned by the edge itself.
Winston Smith