Stéphane Gourichon
Stéphane Gourichon

Reputation: 6971

Graphviz render nodes in subgraph, why?

I want to show a node a pointing to a node b. b is in a subgraph. The following dot graphviz code should work.

digraph
{
    a;

    subgraph cluster_mysubgraph
    {
        a->b;       
    }
}

Alas, while the node a is declared outside of any subgraph, it is rendered inside mysubgraph (observed on graphviz 2.36.0 on Ubuntu 14.04):

a should not be in b subgraph

I've tried variants like pre-declaring b and the like. No success.

A workaround is to declare a in another cluster subgraph.

digraph
{
    subgraph cluster_pseudo
    {
        a;
    }

    subgraph cluster_mysubgraph
    {
        a->b;       
    }
}

This prevents a from appearing inside mysubgraph, but another subgraph is not really an option.

workaround puts a in own subgraph, not good

a should really be outside of any subgraph.

Questions

Upvotes: 0

Views: 605

Answers (1)

Stéphane Gourichon
Stéphane Gourichon

Reputation: 6971

It looks like the following works:

digraph
{
    a;


    subgraph cluster_mysubgraph
    {
        b;
    }

    a->b;

}

enter image description here

So, there might be some rule like: "declare nodes in subgraph, beware of declaring edge in subgraphs because that tends to make nodes to be attached to that subgraph (unless they are already attached to another)".

It might be so, yet it's easier, when generating a dot file, to generate nodes and edges in one pass and in my case that makes declaring nodes and edges in the same subgraph.

Upvotes: 6

Related Questions