Graphviz (using neato) ignores label positions when control points are not defined for edges.
I can brute force my way to positioning the labels, but I’m doing this in ignorance of the real problem.
Is there a way to stop graphviz overwriting lp, xlp in edges that do not have the curve control points pre-defined?
Why isn’t lp working on nodes?
I can position edge labels only if I position nodes and edges, and define edge curves
# manual_edge.dot
digraph G {
A [label = "A" xlabel="a" pos="0,100" lp="200,100!" xlp="300,100!" ]
B [label = "B" xlabel="b" pos="100,0" lp="200,0!" xlp="300,0!" ]
A -> B
[pos="0,100 0,0 0,0 100,0" ]
[label = "A->B" xlabel="a->b" lp="200,50!" xlp="300,50!" ]
}
EDIT : could somebody with more edit privileges please uncomment this?
![label positioning when edge curve is defined|465x192]
(upload://b7Mm4tA2ZtJ3XFhHxlnKx8EvB0t.png)
Defining positions is easy enough, defining curves is a bit painful.
If I don’t do it - the edge label positions don’t work:
# edge.dot
digraph G {
A [label = "A" xlabel="a" pos="0,100" lp="200,100!" xlp="300,100!" ]
B [label = "B" xlabel="b" pos="100,0" lp="200,0!" xlp="300,0!" ]
A -> B
[label = "A->B" xlabel="a->b" lp="200,50!" xlp="300,50!" ]
}
When I export the dot output I can see that when I don’t define the edge curves, my label positions are being overwritten
$ dot -Tdot -Kneato -n2 -o ./output.dot ./edge.dot
A -> B [label="A->B",
lp="30.532,60.968",
pos="e,84.997,15.003 15.188,84.812 31.877,68.123 58.839,41.161 77.877,22.123",
xlabel="a->b",
xlp="33.032,45.968"];
to work around this behaviour, I’m putting my values in nonsense attributes that survive processing and using regex to clean up the file before passing it back to neato:
...
[label = "A->B" xlabel="a->b" zzzzl="200,50!" zzzzxl="300,50!" ]
...
...
A -> B [label="A->B",
lp="30.532,60.968",
pos="e,84.997,15.003 15.188,84.812 31.877,68.123 58.839,41.161 77.877,22.123",
xlabel="a->b",
xlp="33.032,45.968",
zzzzl="200,50!",
zzzzxl="300,50!"];
...
After converting zzzzl to lp, and zzzzzxl to xlp diagram works.
This is because when attributes are set multiple time the last value is used
dot -Tpng -Kneato -n2 -O ./output.dot
This gets me what I want, but it’s a bit longwinded.
Is there a way to stop graphviz overwriting lp, xlp in edges?
Why isn’t lp working on nodes?
question also posted on stackoverflow at:
…stackoverflow.com/questions/69491641/graphviz-edge-label-position-graphviz-ignoring-label-positions-when-control-po
I’m not allowed to say thank you on S.O, so I’ll say it here, thanks for taking the time to look at my question.