Graphviz 重叠边缘标签
Graphviz overlapping edge labels
我正在研究 a Python script,它可以发现网络中的所有 Cisco 设备,现在我希望添加一个为用户创建图表的选项。
我正在使用 graphviz Python 模块并且仍在编写代码,但这是它此时生成的内容:
graph {
graph [nodesep=1.5 ranksep=1]
edge [fontsize=10 weight=0.5]
"R3.lab"
"R3.lab" -- "R1.lab" [headlabel="Fa0/1" taillabel="Fa0/1"]
"R2.lab"
"R2.lab" -- "R1.lab" [headlabel="Fa3/0" taillabel="Fa3/0"]
"R2.lab"
"R2.lab" -- "R1.lab" [headlabel="Fa1/0" taillabel="Fa0/1"]
"R4.lab"
"R4.lab" -- "R1.lab" [headlabel="Fa4/0" taillabel="Fa4/0"]
"R2.lab"
"R2.lab" -- "R3.lab" [headlabel="Fa0/0" taillabel="Fa0/0"]
"R5.lab"
"R5.lab" -- "R3.lab" [headlabel="Fa4/0" taillabel="Fa3/0"]
"R4.lab"
"R4.lab" -- "R3.lab" [headlabel="Fa1/0" taillabel="Fa0/0"]
"R4.lab"
"R4.lab" -- "R2.lab" [headlabel="Fa1/0" taillabel="Fa1/0"]
"R4.lab"
"R4.lab" -- "R5.lab" [headlabel="Fa0/1" taillabel="Fa0/1"]
}
问题在于某些节点的边标签(例如 R4)彼此重叠,很难看出哪个标签适用于哪条边。这让我想到了一个问题,我该如何确保不会发生这种重叠?
解决方案需要是动态的(而不是仅在此图中修复它),以便它也适用于其他网络。
如有任何建议,我们将不胜感激。谢谢。
您可以尝试在节点中使用边距,使它们更大。
边缘中的空标签也有助于创建更多 space.
试试这张图:
graph {
graph [bgcolor="#333333" fontcolor=white fontsize=16 label="Network Map" rankdir=BT]
node [color="#006699" fillcolor="#006699" fontcolor=white fontname=Helvetica margin=0.4 shape=box style=filled]
edge [arrowhead=open color=green fontcolor=white fontname=Courier fontsize=14 style=dashed]
R4
R5
R1
R2
R3
R2 -- R3 [label=" " headlabel="Fa0/0" taillabel="Fa0/0"]
R4 -- R2 [label=" " headlabel="Fa1/0" taillabel="Fa1/0"]
R2 -- R1 [label=" " headlabel="Fa3/0" taillabel="Fa3/0"]
R4 -- R1 [label=" " headlabel="Fa4/0" taillabel="Fa4/0"]
R4 -- R5 [label=" " headlabel="Fa0/1" taillabel="Fa0/1"]
R3 -- R1 [label=" " headlabel="Fa0/1" taillabel="Fa0/1"]
R2 -- R1 [label=" " headlabel="Fa0/1" taillabel="Fa1/0"]
R5 -- R3 [label=" " headlabel="Fa3/0" taillabel="Fa4/0"]
}
您可以在要点中查看完整代码:https://gist.github.com/natenka/4d991cacc69e7353c84504c1581a5014
我正在研究 a Python script,它可以发现网络中的所有 Cisco 设备,现在我希望添加一个为用户创建图表的选项。
我正在使用 graphviz Python 模块并且仍在编写代码,但这是它此时生成的内容:
graph {
graph [nodesep=1.5 ranksep=1]
edge [fontsize=10 weight=0.5]
"R3.lab"
"R3.lab" -- "R1.lab" [headlabel="Fa0/1" taillabel="Fa0/1"]
"R2.lab"
"R2.lab" -- "R1.lab" [headlabel="Fa3/0" taillabel="Fa3/0"]
"R2.lab"
"R2.lab" -- "R1.lab" [headlabel="Fa1/0" taillabel="Fa0/1"]
"R4.lab"
"R4.lab" -- "R1.lab" [headlabel="Fa4/0" taillabel="Fa4/0"]
"R2.lab"
"R2.lab" -- "R3.lab" [headlabel="Fa0/0" taillabel="Fa0/0"]
"R5.lab"
"R5.lab" -- "R3.lab" [headlabel="Fa4/0" taillabel="Fa3/0"]
"R4.lab"
"R4.lab" -- "R3.lab" [headlabel="Fa1/0" taillabel="Fa0/0"]
"R4.lab"
"R4.lab" -- "R2.lab" [headlabel="Fa1/0" taillabel="Fa1/0"]
"R4.lab"
"R4.lab" -- "R5.lab" [headlabel="Fa0/1" taillabel="Fa0/1"]
}
问题在于某些节点的边标签(例如 R4)彼此重叠,很难看出哪个标签适用于哪条边。这让我想到了一个问题,我该如何确保不会发生这种重叠?
解决方案需要是动态的(而不是仅在此图中修复它),以便它也适用于其他网络。
如有任何建议,我们将不胜感激。谢谢。
您可以尝试在节点中使用边距,使它们更大。 边缘中的空标签也有助于创建更多 space.
试试这张图:
graph { graph [bgcolor="#333333" fontcolor=white fontsize=16 label="Network Map" rankdir=BT] node [color="#006699" fillcolor="#006699" fontcolor=white fontname=Helvetica margin=0.4 shape=box style=filled] edge [arrowhead=open color=green fontcolor=white fontname=Courier fontsize=14 style=dashed] R4 R5 R1 R2 R3 R2 -- R3 [label=" " headlabel="Fa0/0" taillabel="Fa0/0"] R4 -- R2 [label=" " headlabel="Fa1/0" taillabel="Fa1/0"] R2 -- R1 [label=" " headlabel="Fa3/0" taillabel="Fa3/0"] R4 -- R1 [label=" " headlabel="Fa4/0" taillabel="Fa4/0"] R4 -- R5 [label=" " headlabel="Fa0/1" taillabel="Fa0/1"] R3 -- R1 [label=" " headlabel="Fa0/1" taillabel="Fa0/1"] R2 -- R1 [label=" " headlabel="Fa0/1" taillabel="Fa1/0"] R5 -- R3 [label=" " headlabel="Fa3/0" taillabel="Fa4/0"] }
您可以在要点中查看完整代码:https://gist.github.com/natenka/4d991cacc69e7353c84504c1581a5014