René Nyffenegger
René Nyffenegger

Reputation: 40523

In graphviz: can I have node ids that are unique within clusters only?

I understand that node ids should be unique within a graphviz (here: dot) file.

However, I wish I could have them be unique within their cluster only, that is, I'd like the following file to produce 4 nodes:

digraph G {


  subgraph cluster_clust_one {
     node [shape=record];

     a [label = "A / 1"];
     b [label = "B / 1"];

     a -> b;
  }


  subgraph cluster_clust_two {
     node [shape=record];

     a [label = "A / 2"];
     b [label = "B / 2"];

     a -> b;
  }

}

However, it doesn't, because the node ids are not unique. Obviously, I can solve this by assigning unique ids, for example by changing cluster_clust_two to

  subgraph cluster_clust_two {
     node [shape=record];

     c [label = "A / 2"];
     d [label = "B / 2"];

     c -> d;
  }

Unfortunately, this would entail changing a script that produces the dot files which I wouldn't want to do if not absolutely necessary. So if there is a flag or something I could set instead, I'd prefer this route.

Upvotes: 5

Views: 3008

Answers (2)

Antoine Gersant
Antoine Gersant

Reputation: 536

As far as I know, there is no way to have separate nodes with identical IDs. A sensible workaround was proposed by dgw =)

Upvotes: 2

dgw
dgw

Reputation: 13656

You could prepend the node name with the name of the cluster like cluster_clust_two__a. It would still mean a change in the generating script.

Upvotes: 5

Related Questions