使用 cluster_ 时的子图位置问题
Subgraph position issues when using cluster_
我刚刚发现了 GraphViz,我正在尝试根据文档和示例创建一个相当简单的网络图。
所以,我尝试将其分为 3 个主要类别,我希望这 3 个类别从上到下排列:管理程序 -> 核心 -> 边缘。
以下代码呈现效果很好,但如果我尝试将 subgraph core
转换为 subgraph cluster_core
,它就会变得有点乱。突然 core
向左移动,节点垂直排列(尝试用 rankdir
和 rank=same
覆盖节点) - 但我真的想要外边框和标签!我在这里错过了什么吗?问题出在椅子和电脑之间吗?
我目前的代码是:
digraph network {
graph [overlap = false]
// Node definitions
subgraph core {
rank = same
labelloc = c
label = "Core"
node [shape=square]
SR_CORE DR_CORE
node [shape=plaintext]
ROUTE2 ROUTE1
}
subgraph cluster_hypervisors {
rank = same
labelloc = c
style = filled
label = "Hypervisors"
node [shape=circle style=filled fillcolor=white]
NODE01 NODE02 NODE03 NODE04
}
subgraph cluster_edge {
rank = same
labelloc = c
label = "Edge"
node [shape=rectangle]
SWITCH01 SWITCH02 SWITCH03
}
// Edge definitions
SR_CORE -> ROUTE2 -> DR_CORE [dir=none]
SR_CORE -> ROUTE1 -> DR_CORE [dir=none]
SR_CORE -> { SWITCH01 SWITCH02 }
DR_CORE -> { SWITCH03 }
NODE01 -> SR_CORE [dir=back]
NODE02 -> SR_CORE [dir=back]
NODE03 -> DR_CORE [dir=back]
NODE04 -> DR_CORE [dir=back]
}
您必须使用 {}
对 cluster_core
中的节点进行分组。要调整外观,您还可以添加一些 constraint=false
到几个边缘:
digraph network {
graph [overlap = false]
// Node definitions
subgraph cluster_core {
rank = same
labelloc = c
label = "Core"
node [shape=square]
SR_CORE DR_CORE
node [shape=plaintext]
ROUTE2 ROUTE1
{SR_CORE DR_CORE ROUTE2 ROUTE1}
}
subgraph cluster_hypervisors {
rank = same
labelloc = c
style = filled
label = "Hypervisors"
node [shape=circle style=filled fillcolor=white]
NODE01 NODE02 NODE03 NODE04
}
subgraph cluster_edge {
rank = same
labelloc = c
label = "Edge"
node [shape=rectangle]
SWITCH01 SWITCH02 SWITCH03
}
// Edge definitions
SR_CORE -> ROUTE2 [dir=none]
SR_CORE -> ROUTE1 [dir=none, constraint=false]
ROUTE2 -> DR_CORE [dir=none, constraint=false]
ROUTE1 -> DR_CORE [dir=none, constraint=false]
SR_CORE -> { SWITCH01 SWITCH02 }
DR_CORE -> { SWITCH03 }
NODE01 -> SR_CORE [dir=back]
NODE02 -> SR_CORE [dir=back]
NODE03 -> DR_CORE [dir=back]
NODE04 -> DR_CORE [dir=back]
}
上查看工作示例
我刚刚发现了 GraphViz,我正在尝试根据文档和示例创建一个相当简单的网络图。
所以,我尝试将其分为 3 个主要类别,我希望这 3 个类别从上到下排列:管理程序 -> 核心 -> 边缘。
以下代码呈现效果很好,但如果我尝试将 subgraph core
转换为 subgraph cluster_core
,它就会变得有点乱。突然 core
向左移动,节点垂直排列(尝试用 rankdir
和 rank=same
覆盖节点) - 但我真的想要外边框和标签!我在这里错过了什么吗?问题出在椅子和电脑之间吗?
我目前的代码是:
digraph network {
graph [overlap = false]
// Node definitions
subgraph core {
rank = same
labelloc = c
label = "Core"
node [shape=square]
SR_CORE DR_CORE
node [shape=plaintext]
ROUTE2 ROUTE1
}
subgraph cluster_hypervisors {
rank = same
labelloc = c
style = filled
label = "Hypervisors"
node [shape=circle style=filled fillcolor=white]
NODE01 NODE02 NODE03 NODE04
}
subgraph cluster_edge {
rank = same
labelloc = c
label = "Edge"
node [shape=rectangle]
SWITCH01 SWITCH02 SWITCH03
}
// Edge definitions
SR_CORE -> ROUTE2 -> DR_CORE [dir=none]
SR_CORE -> ROUTE1 -> DR_CORE [dir=none]
SR_CORE -> { SWITCH01 SWITCH02 }
DR_CORE -> { SWITCH03 }
NODE01 -> SR_CORE [dir=back]
NODE02 -> SR_CORE [dir=back]
NODE03 -> DR_CORE [dir=back]
NODE04 -> DR_CORE [dir=back]
}
您必须使用 {}
对 cluster_core
中的节点进行分组。要调整外观,您还可以添加一些 constraint=false
到几个边缘:
digraph network {
graph [overlap = false]
// Node definitions
subgraph cluster_core {
rank = same
labelloc = c
label = "Core"
node [shape=square]
SR_CORE DR_CORE
node [shape=plaintext]
ROUTE2 ROUTE1
{SR_CORE DR_CORE ROUTE2 ROUTE1}
}
subgraph cluster_hypervisors {
rank = same
labelloc = c
style = filled
label = "Hypervisors"
node [shape=circle style=filled fillcolor=white]
NODE01 NODE02 NODE03 NODE04
}
subgraph cluster_edge {
rank = same
labelloc = c
label = "Edge"
node [shape=rectangle]
SWITCH01 SWITCH02 SWITCH03
}
// Edge definitions
SR_CORE -> ROUTE2 [dir=none]
SR_CORE -> ROUTE1 [dir=none, constraint=false]
ROUTE2 -> DR_CORE [dir=none, constraint=false]
ROUTE1 -> DR_CORE [dir=none, constraint=false]
SR_CORE -> { SWITCH01 SWITCH02 }
DR_CORE -> { SWITCH03 }
NODE01 -> SR_CORE [dir=back]
NODE02 -> SR_CORE [dir=back]
NODE03 -> DR_CORE [dir=back]
NODE04 -> DR_CORE [dir=back]
}