You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Graphviz拓扑图配置:如何将子图按从上到下顺序排列

实现交换机拓扑子图垂直排列的方法

要让Bridge1到Bridge5按从上到下的顺序排列,只需在原有Graphviz代码中添加不可见的垂直边,强制指定子图的排名顺序。具体修改如下:

修改后的完整代码

node [shape=box,style=filled];
newrank=True;
rankdir=TB;

subgraph cluster_1 {
label="Bridge1
8001.5254aabbcce6";
rank=same;
rstp_1_1[label="port1
D
20000"];
rstp_1_2[label="port2
R
20000"];
rstp_1_3[label="port3
D
20000"];
rstp_1_4[label="port4
D
20000"];
}
subgraph cluster_2 {
label="Bridge2
8001.5254aabbcca6";
rank=same;
rstp_2_1[label="port1
D
20000"];
rstp_2_2[label="port2
D
20000"];
rstp_2_3[label="port3
D
20000"];
rstp_2_4[label="port4
R
20000"];
}
subgraph cluster_3 {
label="Bridge3
8001.5254aabbcc6c";
rank=same;
bgcolor=red;
rstp_3_1[label="port1
D
0"];
rstp_3_2[label="port2
D
0"];
rstp_3_3[label="port3
D
0"];
rstp_3_4[label="port4
D
0"];
}
subgraph cluster_4 {
label="Bridge4
8001.5254aabbccba";
rank=same;
rstp_4_1[label="port1
D
20000"];
rstp_4_2[label="port2
D
20000"];
rstp_4_3[label="port3
R
20000"];
rstp_4_4[label="port4
D
20000"];
}
subgraph cluster_5 {
label="Bridge5
8001.5254aabbccb2";
rank=same;
rstp_5_1[label="port1
D
20000"];
rstp_5_2[label="port2
D
20000"];
rstp_5_3[label="port3
R
20000"];
rstp_5_4[label="port4
D
20000"];
}
// 添加不可见边强制子图垂直顺序
rstp_1_1 -> rstp_2_1 [style=invis];
rstp_2_1 -> rstp_3_1 [style=invis];
rstp_3_1 -> rstp_4_1 [style=invis];
rstp_4_1 -> rstp_5_1 [style=invis];

// 原有拓扑连接
rstp_1_2 -> rstp_5_2 [arrowhead=none];
rstp_2_3 -> rstp_5_3 [arrowhead=none];
rstp_2_4 -> rstp_3_4 [arrowhead=none];
rstp_3_3 -> rstp_4_3 [arrowhead=none];
rstp_4_4 -> rstp_5_4 [arrowhead=none];
}

改动说明

  • 用style=invis添加的不可见边不会在图中显示,但会给Graphviz传递垂直排列的优先级,确保Bridge1处于最顶部,后续Bridge依次向下排列。
  • 保留原有newrank=true和rankdir=TB配置,保证每个集群内的节点水平排列,整体布局为垂直方向。

内容的提问来源于stack exchange,提问作者othernamen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 00:05:34