Graphviz: Place edge label on the other side (II)

前端 未结 1 1236
旧时难觅i
旧时难觅i 2020-12-31 01:08

related questions are:

Graphviz: Place edge label on the other side

How to place edge labels ON edge in graphviz

Consider following dot file:

相关标签:
1条回答
  • 2020-12-31 01:47

    As you've found out, graphviz doesn't let you choose horizontal label placement, so all solutions are slightly hacky.

    Attempt #1: The two solutions posted by marapet (here)

    1. The labelangle and labeldistance trick doesn't adapt well to different lengths of label text (you'd have to recalculate new distance/angle numbers).

    2. The splines=false trick doesn't work so well where the number of edges between nodes > the number of nodes (you end up with overlapping edges).

    Attempt #2: xlabels and anchors to create curved edges

    This uses a relatively new feature of graphviz, xlabel (which places the label AFTER the coordinates for the nodes/edges have been decided). The ports feature is used to create curved edges. The padding on the labels is achieved with space characters.

    gv

    digraph {
    forcelabels=true;
    
        0:sw -> 1:nw [ dir=forward, xlabel="  (1, 0)  "];
        0 -> 1 [dir=none];
        1:ne -> 0:se [ dir=backward, xlabel= "  (0, -1)  "];
    
    }
    

    I believe you need graphviz version >2.29 to use xlabel.

    0 讨论(0)
提交回复
热议问题