将GraphViz群集连接到自身

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

This answer描述了如何将GraphViz集群连接到节点和其他集群。

我想将一个集群连接到自身,因此箭头退出集群边界并重新进入(想想一个转换为自身的状态机)。

以下是一个例子:

digraph example {                                                               
    compound=true;                                                              
    "B" -> "C" [ltail="cluster_s0", lhead="cluster_s1", minlen=2];              
    "D" -> "C" [ltail="cluster_s1", lhead="cluster_s1", minlen=2];              
    subgraph cluster_s0 {                                                       
        "A" -> "B";                                                             
    }                                                                           
    subgraph cluster_s1 {                                                       
        "C" -> "D";                                                             
    }                                                                           
}

这会抛出警告并在集群内而不是外部绘制箭头:

Arrow is drawn inside the cluster

这是我想要的(非常粗略)草图:

Desired graph

有没有办法让GraphViz从DC绘制一个箭头,退出并重新进入群集边界,如上例所示?

graphviz dot
2个回答
0
投票

我不认为这是可能的(并且会急切地等待一位发烧友证明相反)。与此同时,你会考虑使用shape = record解决方法吗?我的MWE

digraph example 
{                                                               
    rankdir = LR;

    node[ shape = record ];
    x   [ label = " { <a>A | <b>B } " ];
    y   [ label = " { <c>C | <d>D } " ];

    // edge
    x -> y;
    y:d:n -> y:c:n;
}

产量

enter image description here

可以做一些工作,使它看起来更像你的要求,但毕竟,它是一个不同的动物。


0
投票

这是另一种解决方法,虽然它有点难看,基本上你在子图外部放置一些额外的点节点并连接没有箭头的边缘,你也可能想要以相反的顺序连接它们以避免对布局产生奇怪的影响:

digraph example {      
    rankdir=LR                                                         
    compound=true;                                                              
    "B" -> "C" [ltail="cluster_s0", lhead="cluster_s1"];              
    "C" -> "DC1" [ltail="cluster_s1", dir=none];     
    DC1[shape=point]
    DC2[shape=point]
    DC1 -> DC2 [dir=none]
    "DC2" -> "D" [lhead="cluster_s1"];              
    subgraph cluster_s0 {                                                       
        "A" -> "B";                                                             
    }                                                                           
    subgraph cluster_s1 {                                                       
        "C" -> "D";         
    }                                                                           
}

enter image description here

您可以通过添加一个不可见的虚拟节点来改善布局,但这可能不会扩展(我的猜测是您将难以确定何时添加虚拟节点)

digraph example {      
    rankdir=LR                                                         
    compound=true;                                                              
    "B" -> "C" [ltail="cluster_s0", lhead="cluster_s1"];              
    "C" -> "DC1" [ltail="cluster_s1", dir=back];     
    DC1[shape=point]
    "DC2" -> "D" [lhead="cluster_s1"];              
    subgraph cluster_s0 {                                                       
        "A" -> "B";                                                             
    }                                                                           
    subgraph cluster_s1 {                                                       
        "C" -> "D";         
    }    
    DD[shape=point color=none]
    {D DC2}->DD[color=none]                                                                
}           

enter image description here

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