Fun with Edge Labels!

Here are three ways to make edge labels “fit” (position) better - closer to the edge. Unfortunately, there is no way to rotate any text - make it vertical - but there still ways to have fun:

  1. print the text characters one-character-on-a-line. Two examples:
13 -- 14 [label="a\ne\ni\no\nu"]
and  
 	52 -- 53   [label="A    
 	E    
 	I    
 	O"]    

Giving:

  1. produce an image file of rotated text and use that image as the label,
    like so:
graph straight {
  splines=false
  node[shape=circle style=filled fillcolor=pink]
  edge [fontname=Courier]  // somewhat arbitrary
  subgraph clusterI {
  //
  // how these images were created (ImageMagick)
  // for a in 0 90 270;do convert -pointsize 22 -trim +repage -rotate -$a label:"Good Data" goodData$a.png;done
  //
  label="Using Images"
  100 -- 101 [shape=plain label=<<TABLE BORDER="0" CELLBORDER="0"><TR><TD><IMG SRC="goodData270.png"/></TD></TR></TABLE>>];
  102 -- 103 [shape=plain label=<<TABLE BORDER="0" CELLBORDER="0"><TR><TD><IMG SRC="goodData90.png"/></TD></TR></TABLE>>];
  104 -- 105 [shape=plain label=<<TABLE BORDER="0" CELLBORDER="0"><TR><TD><IMG SRC="goodData0.png"/></TD></TR></TABLE>>];
  }
}

giving:
vertEdgesB

  1. use a GVPR postprocessor (A GVPR program to improve Graphviz edge labels · GitHub) to either
  • move the label on-top-of the edge
  • move the label anywhere you want, relative to the label’s current position

An example:

graph straight {
  splines=false
  edge [label="\T" labelOverlay=true color=purple]
  node [shape=rect style=filled fillcolor=lightblue]
   a1 -- b1
   c1 -- d1  [labelOverlay="15%" label=high]
   e1 -- f1  [label2node=true labelOverlay="75%" label=low]
   g1:sw -- h1:nw  
   g1:s -- h1:n  [labelOverlay="20%"]
   g1:se -- h1:ne  
   j1 -- k1  [ label2node=true]
  node[shape=square style=filled fillcolor=lightgreen]
  {rank=sink
  edge [fontcolor=red]
  Aaa -- B3  [labelOverlay="33%"]
  C98 -- D3  [labelOverlay="80%" label2node=true]
  Eee -- F6  [label="adjust me" labelAdjust="45,-25"]
  G12 -- H3  [label2node=true]
  node [shape=plain fontcolor=blue style=""]
  Lxx -- M123
  Noo -- Ooo [label2node=true]
  node [shape=oval fontcolor=blue style=""]
  P  -- Q
  }

   node[shape=circle style=filled fillcolor=pink]
   edge [label2node=true label="aeiou" labelOverlay="78%"]
   10 -- {11 12}
   10 -- 13 [labelOverlay="38%"]    
   10 -- 14 [labelOverlay="62%"]    
   edge [label="three"]
   node [shape=Mrecord]
   13 --  21
   edge [labelOverlay="55%" label="T\nh\nr\ne\ne\n \n33"] 13 -- 22
   edge [labelOverlay="60%"] 13 -- 23
}

Giving:

5 Likes

Sure there is. You simply use sideways unicode equivalents:

graph {
  13 -- 14 [label="ᗉ\nᗶ\n𝈱\nᗝ\nШ"];
}

hello.dot

More seriously though, nice write up! This is very useful info!

1 Like

Is there a locations where we collect these gems?

Here it is:

Super cool. Thanks!

+1 for Dvorak.