12

I try to use dot for drawing a graph, and I have the following problem

graph

The label for node b overlaps with the edge from a to b. Is there a way to move this label somehow to avoid this?

This is the code I use to generate the image (using dot)

digraph A {
  rankdir=LR;
  center=true; margin=0.3; 
  nodesep=1.5; ranksep=0.5;

  node [shape=point,  height=".2", width=".2"];

  a [xlabel="a"];
  b [xlabel="b"];
  c [xlabel="c"];
  a -> b -> c;
  a -> c;
}

This happens quite often and it's annoying (same here, but with edges):

enter image description here

I understand that this is caused by the fact that xlabels are put after all the things were laid out, but I was wondering if it's possible to help it a bit - i.e. say it where the label needs to be placed.

Alexey Grigorev
  • 2,415
  • 28
  • 47

1 Answers1

6

You can't do this -- you want to provide position information for the xlabel, but graphviz does not currently (2016-01-25) allow this. There is an open feature request in the graphviz bug tracker for this ability; it is described as:

this is basically a feature request for allowing the user to provide position information for xlabels. For xlabels attached to nodes, the coordinates should be relative to the node position. A similar feature could hold for head and tail labels for edges. I suppose xlabels for edges could be based on the "center" of the edge.

mtd
  • 2,224
  • 19
  • 21
  • 1
    It is currently possible to position everything as mentioned at http://stackoverflow.com/a/40869078/895245 with `neato -n2`, but then you *have* to place everything explicitly, which is a pain, and half defeats the purpose of graphviz... – Ciro Santilli OurBigBook.com Dec 27 '16 at 10:14
  • 1
    Indeed, that almost entirely defeats the purpose of graphviz. It's like saying "you can get from New York to Los Angeles with this broken car, you just have to carry the car yourself". – mtd Dec 31 '16 at 11:31