1

Maybe I'm trying to bend graphviz more than I should, but would it be possible to straighten the arrows? I need the labels to be over the arrow, not to the side as with label/xlabel; I'm using boxes to hold what is essentially label text, since using labels on the edges seems to lead to whacky behavior when the labels are long.

digraph G {
    node [shape=rect style=filled
         fontcolor=white fontsize=12 fontname="Helvetica Bold"]
    edge [style=solid color="#777777"]

    // introduce nodes; set fill
    a1, a2, a3 [fillcolor="#438dd5"]
    c1         [fillcolor="#08427b"]

    b1, b2, b3 [fillcolor=white fontcolor=black fontname="Helvetica" shape=plain]

    a1 -> b1[dir=none]
    a2 -> b2[dir=none]
    a3 -> b3[dir=none]

    b1 -> c1
    b2 -> c1
    b3 -> c1

    { rankdir=LR  rank=same  a1 a2 a3  }
    { rankdir=LR  rank=same  b1 b2 b3 }
    { rankdir=LR  rank=same  c1 }
}

What I get:

enter image description here

What I want:

enter image description here

RoyM
  • 1,118
  • 1
  • 9
  • 28
  • Related to https://stackoverflow.com/questions/2350617/how-to-place-edge-labels-on-edge-in-graphviz – tk421 Feb 28 '19 at 20:59

1 Answers1

4

I usually do it using tables with no borders and white background instead of labels. You would probably also need to use headlabel or taillabel, because in this case you can precisely control their position with labeldistance and labelangle:

digraph G {
    node  [shape=rect style=filled
           fontcolor=white fontsize=12 fontname="Helvetica Bold"]
    graph [ranksep=1]
    edge  [style=solid color="#777777"]

    a1 [fillcolor="#438dd5"]
    a2 [fillcolor="#438dd5"]
    a3 [fillcolor="#438dd5"]
    c1 [fillcolor="#08427b"]

    a1 -> c1 [
        labeldistance=5
        labelangle=0
        headlabel=<
            <table bgcolor="white" border="0">
                <tr>
                    <td>b1</td>
                </tr>
            </table>
        >
    ]
    a2 -> c1 [
        labeldistance=4
        labelangle=0
        headlabel=<
            <table bgcolor="white" border="0">
                <tr>
                    <td>b2</td>
                </tr>
            </table>
        >
    ]
    a3 -> c1 [
        labeldistance=5
        labelangle=0
        headlabel=<
            <table bgcolor="white" border="0">
                <tr>
                    <td>b3</td>
                </tr>
            </table>
        >
    ]
}

result:

enter image description here

Dany
  • 4,521
  • 1
  • 15
  • 32
  • thanks.. I'd tried tables, but I didn't know about the use of labelangle and labeldistance. Makes perfect sense... also liked the use of ranksep to move rows apart. – RoyM Feb 28 '19 at 19:37
  • @RoyM ranksep affects the whole graph and you sometimes don't want it. In this case you could just add 'invisible' label to one of the edges. In this example you could `a2 -> c1 [label=" \n \n \n \n" ...` – Dany Mar 01 '19 at 06:46