0

I want to connect a cluster edge to a node. Please find a simple Graphviz code below. Here is the online demo.

digraph G {
    compound=true;
    node1
    subgraph cluster0 {
        label="cluster"
        node2;
     }
    node2 -> node1 [ltail="cluster0"]
}

It produces this output:

enter image description here

So, in the above method the cluster0 is connected to a node1. node2 is inside the cluster.

To connect the cluster itself to node we need compound=true and [ltail="cluster0"]. So we are just connecting node2 to node1 behind the scene and generating the edge from behind the cluster.

node2 -> node1 [ltail="cluster0"]

What I really want is to connect the cluster itself in the code like:

digraph G {
    compound=true;
    node1
    subgraph cluster0 {
        label="cluster"
        node2;
     }
    cluster0 -> node1 [ltail="cluster0"]
}

But unfortunately, it produces this:

enter image description here

Well, the first one produces the image as desired but not the right approach. I'm working with State machines and generating the Graphviz code programmatically. Logically speaking, there is only one transition in the state digram:

cluster -> node1

But to do so we're trasitioning from node2 to node1 which is logically not right. I am curious that there is a way to achieve this and connect the cluster directly to a node instead of using a node inside the cluster.

Thanks in advance!

1 Answers1

0

The ltail attribute is what is connecting it with the cluster edge.

(It seems like what you say is correct, that it's connecting the nodes on the back end but covering the edge when it gets to the cluster.)

Removing the ltail attribute should fix it:

digraph G {
    compound=true;
    node1
    subgraph cluster0 {
        label="cluster"
        node2;
     }
node2 -> node1
    
}

enter image description here

goodship11
  • 326
  • 2
  • 4
  • 1
    Hi @goodship11. Thanks for the response but the requirement here is to connect the whole cluster to the node, not connecting the two nodes. So I want to achieve the first diagram mentioned but wondering that is there a way to connect the cluster to the node without using ltail and in the code use the cluster name directly instead of the inner node. – Gaurav Saxena Sep 17 '21 at 06:44
  • Ahh, so the diagram you had *looked* correct, but the code wasn’t what you wanted? Makes sense. I don’t know if you can do that but I’m curious if it’s possible too! – goodship11 Sep 18 '21 at 12:30
  • 1
    If the reason you want to do that is to facilitate code, it looks like you you could place the cluster0 *node* inside the cluster0 *cluster*, style it invisible (and small), and then reference the node as the cluster. You’d still probably need ltail but if the ultimate goal is to reference the cluster easier then that might be helpful. – goodship11 Sep 18 '21 at 14:15
  • 1
    That can be a good approach, thanks. But it leaves inconsistent padding. – Gaurav Saxena Sep 21 '21 at 06:41
  • 1
    I'm using the approach you suggested in the above comment. I did not find any solution better than that. Thanks again! – Gaurav Saxena Oct 28 '21 at 11:55
  • Glad it worked! – goodship11 Dec 07 '21 at 00:06