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

问题描述 投票:2回答:1

我刚刚在Stackoverflow上学习了how to connect nodes and subgraphs。但是,我想将节点连接到包含的子图:

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

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

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

graphviz dot subgraph
1个回答
0
投票

你需要一些脚手架,即不可见的节点(也许是边缘),例如:

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上呈现:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.