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

5
我刚刚在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];
}

我所指的快速草图:

enter image description here

我想连接 {a b c}>,但为了清晰起见,我不想画三个不同的箭头,而只想画一个指向节点组的箭头。一种方法是只列出一个箭头,比如 a>。这样做是可行的,但是否有一种方法可以将三个箭头“折叠”成一个箭头,当箭头指向群集时?
然而, {a b c}>不可能指向一个群集,因为是该群集的一部分。有没有办法绕过这个问题?
1个回答

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
}

在 viz-js.com 上渲染:

输入图像描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接