Graphviz overlapping edge labels

OzNetNerd

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.

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:

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 (e.g R4) overlap one another and it is difficult to see which label applies to which edge. 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.

Natasha Samoylenko

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related