简体   繁体   English

Graphviz重叠边缘标签

[英]Graphviz overlapping edge labels

I'm working on a Python script which discovers all of the Cisco devices in a network, and am now looking to add an option that creates a diagram for the user. 我正在研究一个发现网络中所有思科设备的Python脚本 ,现在我想添加一个为用户创建图表的选项。

I'm using the graphviz Python module and am still working on the code, but this is what it generates at this point in time: 我正在使用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"]
}

The problem is that some nodes' edge labels (eg R4) overlap one another and it is difficult to see which label applies to which edge. 问题是某些节点的边缘标签(例如R4)彼此重叠,很难看出哪个标签适用于哪个边缘。 This leads me to the question, how do I go about ensuring this overlap does not occur? 这引出了我的问题,我该如何确保不会发生这种重叠?

The solution would need to be dynamic (as opposed to only fixing it in this graph) so that it worked on other networks too. 解决方案需要是动态的(而不是仅在此图中修复它),以便它也适用于其他网络。

Any suggestions would be greatly appreciated. 任何建议将不胜感激。 Thank you. 谢谢。

You can try to use margin in nodes, to make them bigger. 您可以尝试在节点中使用边距,以使其更大。 And also the empty label in edges helps to create more space. 边缘的空标签也有助于创造更多空间。

Try this graph: 试试这个图:

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"]
}

You can see a full code in gist: https://gist.github.com/natenka/4d991cacc69e7353c84504c1581a5014 您可以在gist中看到完整的代码: https//gist.github.com/natenka/4d991cacc69e7353c84504c1581a5014

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM