Edge label placement

Hello (and greetings to the forum as it’s my first post),

I started to tinker last week with Graphviz and I find the language quite clear (though the documentation is not always straightforward).

In a graph I’d like to create a “Caption” subgraph, as partially shown below.

[dot verbose=true]

digraph test {
  label="Caption"

  {
    rank="same"
    B,C,D
  }
  A → B[label=“A\ndepends\non B”]
  B → C[label=“Unordered\nconstraint”, dir=“both”, arrowhead=“onormal”, arrowtail=“onormal”, style=“dashed”]
  A → C → D[color=“red”]
  D → A[label=“Def. loop”, color=“red”]
}

[/dot]

For clarity, is it possible to move the A → B label outwards (i.e. to the left) ?

Cheers !

Yann

Welcome.
Graphviz is indeed complex. Here are my go to’s for documentation:

Here is a proposed fix to your label issue: change that one label to an xlabel (xlabel | Graphviz). It seems to satisfy your request.

digraph test {
  label="Caption"

  {
    rank="same"
    B,C,D
  }
  A -> B[xlabel="A\ndepends\non B"]   // changed label to xlabel
  B -> C[label="Unordered\nconstraint", dir="both", arrowhead="onormal", arrowtail="onormal", style="dashed"]
  A -> C -> D[color="red"]
  D -> A[label="Def. loop", color="red"]
}

Giving:

Thanks for your help and the documents!

I missed xlabel, this is indeed useful. However, it becomes messier if I use it with concentrate=true:

[dot, verbose=true]

digraph test {
  label=“Caption”
  concentrate=true

  {
    rank=“same”
    B,C,D
  }
  A → B[xlabel=“A\ndepends\non B”]   // changed label to xlabel
  B → C[label=“Unordered\nconstraint”, dir=“both”, arrowhead=“onormal”, arrowtail=“onormal”, style=“dashed”]
  A → C → D[color=“red”]
  D → A[label=“Def. loop”, color=“red”]
  B -> D[label="Requirement", style="bold", color="forestgreen"]
}

[/dot]

Same question applies to the example above. Is it possible to move the “Requirement” upwards or tweak the position manually?

I tried to fiddle with xlp and related attributes but it doesn’t seem to help.

Ok, I found a workaround that gives a satisfactory result, by manually specifying some ports:

[dot verbose=true]

digraph test {
  label="Caption"
  concentrate=true
  {
    rank="same"
    B,C,D
  }
  // Added explicit ports on some nodes
  A:n -> B[label="A\ndepends\non B"]
  B -> C[label="Unordered\nconstraint", dir="both", arrowhead="onormal", arrowtail="onormal", style="dashed"]
  A:nw -> C[color="red"]
  C:n -> D:n[color="red"]
  D -> A[label="Def. loop", color="red"]
  B -> D[label="Requirement", style="bold", color="forestgreen"]
}

[\dot]

(btw I don’t know why the graph isn’t rendered, hence the multiple tries/edits/post deletions, sorry)

Ok, for whatever reason, the graph is not rendering the same way it was when I posted the message…

First, the nodes on 1st line were ordered : C B D (I was happily surprised by this graphviz proposal)

Thus the green arrow was a straight one, and the A->B label was less ambiguous as the D->A label is already on the far right.

But now the nodes are ordered B C D again, which is quite messier with specified ports… Did I miss something ?

For now I corrected it by working on the C → B connexion, which changes the rank and improves the restult. But I don’t think I changed it before, which is strange.

Here’s the current code:

[dot, verbose=true]

digraph test {
  label=“Caption”
  concentrate=true

  {
    rank=“same”
    B,C,D
  }

  A:n → B[label=“A\ndepends\non B”]
  C → B[label=“Unordered\nconstraint”, dir=“both”, arrowhead=“onormal”, arrowtail=“onormal”, style=“dashed”]
  A:nw → C[color=“red”]
  C:n → D:n[color=“red”]
  D → A[label=“Def. loop”, color=“red”]
  B → D[label=“Requirement”, style=“bold”, color=“forestgreen”]
}

[/dot]

Also in my memory the C → D arrow I was getting in my previous result was curvier, avoiding the C → B label. Is there a way to correct this ?

Thanks !

Yann

PS : I think I know now why my previous graph is not rendered on the forum, possibly due to the comment. But I can’t edit anymore.

Here is a (maybe) fix to make the edge “curvier”. But note that dot produces unsatisfactory results for many variations on this theme.

digraph test {
  label="Caption"
  concentrate=true

  {
    rank="same"
    B,C,D
  }

  A:n -> B[label="A\ndepends\non B"]
  C -> B[label="Unordered\nconstraint", dir="both", arrowhead="onormal", arrowtail="onormal", style="dashed"]
  A:nw -> C[color="red"]
  C:ne -> D:nw [color=red label="  " ]  // trying to make the visible version "curvier"
  C:n-> D:n [color="invis" ]
  D -> A[label="Def. loop", color="red"]
  B -> D[label="Requirement", style="bold", color="forestgreen"]
}

Giving:

Here are three forum entries about edges & edge labels. With luck, they should help you place your edges and labels more to your liking.