GraphViz:如何将节点连接到包含子图

doe*_*man 5 dot graphviz subgraph

我刚刚在 Stackoverflow 上学习了如何连接节点和子图。但是,我想将一个节点连接到包含的子图:

digraph G {
    compound=true;
    subgraph cluster0 {
        a -> b;
        a -> c;
        c -> {a b c} [lhead=cluster0];
    }
    c -> d;
    d -> {a b c} [lhead=cluster0];
}
Run Code Online (Sandbox Code Playgroud)

快速概述一下我的意思:

在此输入图像描述

我想连接d -> {a b c},但为了清楚起见,我不想绘制三个不同的箭头,而只想绘制一个指向节点分组的箭头。一种方法是仅列出一个箭头,例如d -> a。这可行,但是当头指向一个簇时,有没有办法将三个箭头“折叠”为一个?

但是,c -> {a b c}不可能指向一个簇,因为c是该簇的一部分。有办法解决这个问题吗?

Jen*_*ens 4

你将需要一些脚手架,即不可见的节点(可能还有边缘),例如:

digraph top {
    compound=true
    node[shape=rectangle]
    subgraph cluster1 {
        a->{b c}
    }
    c->d
    d->b[lhead=cluster1]
    ca[shape=point height=0] // make ca invisible
    a->ca:n[dir=back ltail=cluster1] // by drawing the arrow backward we get more control of the layout, n and s compass make the edge go smooth when enter and exiting ca
    ca:s->c[dir=none] // no arrow on the tail part
}
Run Code Online (Sandbox Code Playgroud)

在 viz-js.com 上呈现:

在此输入图像描述