使用 Dot 语言和 Graphviz 进行渲染,我已经能够创建两个标记为“A”和“B”的框(节点),一个在另一个上方,周围有一个虚线边框:
digraph G {
// Define a subgraph representing the outer box
subgraph outer_box {
cluster=true; // Designate this subgraph as a cluster in order to enable the boundary box
rankdir="TB"; // Arrange boxes from top to bottom
style=dashed; // Fill the outer box with color
fillcolor=lightgray; // Set the fill color of the outer box
// Top box with text "A"
node [shape=box, style=filled, fillcolor=lightblue];
A [label="A"];
// Bottom box with text "B"
node [shape=box, style=filled, fillcolor=lightyellow];
B [label="B"];
// Connect boxes
A -> B [style=invis]; // Invisible edge to stack boxes vertically
}
}
可以在这里查看可视化效果,它看起来像这样:
如何使外部虚线框连接到另一个带有标签“C”的框?
即我想生成这样的图片:
我愿意接受
outer_box
、A
和/或 B
的类别/类型的任何更改;它们各自作为簇子图和节点的分类只是来自我目前尝试 Dot 语言的状态。
我尝试创建
C
作为另一个集群子图,然后添加 outer_box -> C
语句,但这不起作用。我还一直在 https://graphviz.org/doc/info/lang.html 阅读 Graphviz/Dot 语言文档,但我还没有找到与我想要实现的目标相符的示例。
并不像人们想象的那么容易,但你可以获得你所描述的图表。看看:
digraph G {
compound=true // allow edges to-from clusters (pseudo)
rankdir="TB"; // only valid if applied to Root graph - Arrange boxes from top to bottom
ranksep=.25 // snug up the ranks
newrank=true // allow rank=same to apply to ALL nodes, not just those in same cluster
// Define a subgraph representing the outer box
subgraph outer_box {
cluster=true; // Designate this subgraph as a cluster in order to enable the boundary box
style=dashed; // Fill the outer box with color
fillcolor=lightgray; // Set the fill color of the outer box
// Top box with text "A"
node [shape=box, style=filled, fillcolor=lightblue];
A [label="A"];
// Bottom box with text "B"
node [shape=box, style=filled, fillcolor=lightyellow];
B [label="B"];
dummy [shape=point height=0 width=0 label="" style=invis] // place a node in-between A & B
// Connect boxes
A -> dummy ->B [style=invis]; // Invisible edge to stack boxes vertically
}
C [shape=box]
{rank=same dummy C}
// the empty label pushes C farther to the right of the cluster
dummy -> C [ltail=outer_box label=" "]
}