user1273684
user1273684

Reputation: 1619

Same node in two subgraphs

I want to draw a border around two subgraphs but I have one node that belongs to both.

digraph {
    subgraph cluster_0 {
            color = red

            A -> D
            A -> C
            C -> D
    }

    subgraph cluster_1 {
            color = blue

            B -> C
            B -> E
            C -> E
    }
}

Now C should be part of both Clusters - instead I get this:

C should be part of both subgraphs

Upvotes: 6

Views: 963

Answers (1)

albert
albert

Reputation: 9077

There is a difference between the name / label of a node and its identification. When a node has no name / label the identification is taken as name / label.

Not sure if the following is what you intended (otherwise clarify your question).

digraph {
    subgraph cluster_0 {
            color = red

            A -> D
            A -> C
            C -> D
    }

    subgraph cluster_1 {
            color = blue
            C2 [label="C"]
            B -> C2
            B -> E
            C2 -> E
    }
}

From the comment of OP (image should be in original question) looks like OP wants something more like:

digraph {
    subgraph cluster_2 {
    color = none;
    C
    }
    subgraph cluster_0 {
            color = red

            A -> D
            A -> C
            C -> D
    }
    
    subgraph cluster_1 {
            color = blue
            
            B -> C
            B -> E
            C -> E
    }
}

this image does not provide the exact picture OP wants but I think a direction and with some ran setting together with some hidden nodes and edges it should give the right picture.

Upvotes: 3

Related Questions