Edge labels writing over edge arrows in Graphviz - graphviz

For my decision tree I need to place edge label nodes next to the nodes in GraphViz for readability, and i have tried to use taillabel but it writes over the edge arrow.
For example the following code:
digraph workflow
{
checkit -> doit [taillabel ="y";];
checkit -> dontdoit [taillabel="n";];
}
renders like this (I use GVedit : Graphviz 2.38.0, Graphvizversion 1.02) :
How can I ensure that edge labels such as 'y' do not write over the edge arrow ?

You can use labelangle and labeldistance attribute to control the precise position of taillabel or headlabel:
digraph workflow {
checkit -> doit [
taillabel ="y"
labeldistance=2
labelangle=330
]
checkit -> dontdoit [
taillabel="n"
labeldistance=2
labelangle=25
]
}

Related

Add space between 2 connected nodes

I would like to add a little more horizontal space between the 2 nodes so the edge labels appear associated to their node (instead of in the middle of the edge):
The graphviz source:
digraph {
rankdir="LR";
node [shape=cylinder]
clone
initial
clone -> initial [headlabel="origin",taillabel="clone"]
}
Expected:
I tried using nodesep but it seems to only work when there are no edges.
nodesep was a good try, but your ranking is LR, so ranksep is the way to go
digraph {
rankdir="LR";
ranksep=1.2 // rank-to-rank in inches
node [shape=cylinder]
clone
initial
clone -> initial [headlabel="origin",taillabel="clone"]
}
Giving:

Change distance between edges in dot

Is there a way to control the spacing between edges in dot, similar to the nodesep attribute in the other graphviz layout engines? I would like to keep using dot as the layout engine.
By edges I mean either multi-edges or multi-coloured edges, like in the following example. I would like to decrease the space between the a->b edges or increase the space between the c->d edges.
digraph G {
nodesep = "0.15"
a -> b [dir=none color="red"]
a -> b [dir=none color="blue"]
a -> b [dir=none color="green"]
c -> d [dir=none color="green:red:blue"]
}
In dot, the nodesep attribute does not have the desired effect.
Assuming a white background, add white (invisible) lines to change the apparent spacing:
digraph G {
nodesep = "0.15"
c -> d [dir=none color="green:white:white:white:red:white:white:white:blue"]
}
Giving:
There seems to be a bug in that code, only one leg is thicker (penwidth).
So, this solution used ports:
digraph G {
// nodesep = "0.15"
splines=false
edge[penwidth=7]
a:sw -> b:nw [dir=none color="red"]
a -> b [dir=none color="blue"]
a:se -> b:ne [dir=none color="green"]
c -> d [dir=none color="green:white:white:white:red:white:white:white:blue"]
}
Giving:
The best solution I've found is to add transparent edges. That way, this solution works regardless of background colour. Since the edges are transparent, overlap is not a problem and all the coloured edges have the same width.
digraph G {
c -> d [
dir=none
penwidth=5
color="red:transparent:transparent:green:transparent:transparent:blue"
]
}
Produces:
This works for an arbitrary number of edges, and the spacing can be controlled by changing the number of transparent edges between each coloured edge.

How to have multiple label one above and one below the edges in graphviz?

I've the following output currently I want to place a label below the edge between p and z in the figure.Is it possible to do in graphviz I've tried using xlabels but it doesn't work.
Current Code:
digraph GPG{
node [shape=box];
subgraph cluster0{
node[shape=circle];
0[label=0,style=invis];
}
subgraph cluster1{
node[shape=circle];
1[label=1,style=invis];
p->z [label="2 | 1",minlen=1];
{
rank = same;
p;z;
}
}
subgraph cluster2{
node[shape=circle];
2[label=2,style=invis];
}
0->1
1->2
}
I want a label below edge p->z as well above the edge.Is it possible in graphviz?
Kind of ugly, but:
digraph overunder{
splines=false
{ rank=same
a -> b [label=" over " ]
a -> b [label="under" penwidth=0.0 dir=none]
}
}
Produces:
You may have to add the non-breaking space characters (see above) because Graphviz seems to position labels based on the length of the text - longer labels are placed above shorter labels.

graphviz/dot: can the distance between two nodes be set individually?

I'm trying to use dot (version 2.28.0) in order to make a flow chart of my source code. For that, I would like the graph to consist of subgraphs where each of these subgraphs represents a source file in the code base. At the top of each subgraph, there should be the file name as a node in a visually easily distinguishable fashion (i.e. bold, white text on dark blue background). Below the file name node should be the nodes representing the flow of routines in that file in the order they are being called.
My problem now is that I would like the distance between "filename nodes" and "routine nodes" to be smaller than the distance between individual "routine nodes", plus, there should be no arrow between.
I tried to use the minlen attribute for the edge connecting the "filename node" to the first "routine node", but when I set that to a value below 1.0, the two nodes come out next to each other rather than stacked.
Is there any way to make the first two nodes be closer to each other than the other two, yet top/bottom oriented?
digraph "prog.c"
{
edge [fontname="FreeSans",fontsize="12",labelfontname="FreeSans",labelfontsize="10"];
node [fontname="FreeSans",fontsize="14",shape=record,height=0.2];
compound=true;
subgraph cluster_main {
Node1_0 [label="main.c", shape=folder, fontcolor="white", style=filled, fillcolor="#00008b"];
Node1_1 [label="routine1()"];
Node1_2 [label="routine2()"];
edge [color="transparent", minlen="0.5"]; // stacking not ok
// edge [color="transparent", minlen="1.0"]; // stacking ok
Node1_0 -> Node1_1 ;
edge [color="black", minlen="1.0"];
Node1_1 -> Node1_2 ;
}
}
Edit: I should have commented out the line which lead to the undesired result rather than the one leading to the desired result (I had planned to attach two pngs for clarification, but I'm not allowed to do so as a newbie); so here is the code I would actually want to modify in a way that the first two nodes have a different (smaller) distance to each than the last two.
digraph "prog.c"
{
edge [fontname="FreeSans",fontsize="12",labelfontname="FreeSans",labelfontsize="10"];
node [fontname="FreeSans",fontsize="14",shape=record,height=0.2];
compound=true;
subgraph cluster_main {
Node1_0 [label="main.c", shape=folder, fontcolor="white", style=filled, fillcolor="#00008b"];
Node1_1 [label="routine1()"];
Node1_2 [label="routine2()"];
//edge [color="transparent", minlen="0.5"]; // stacking not ok
edge [color="transparent", minlen="1.0"]; // stacking ok
Node1_0 -> Node1_1 ;
edge [color="black", minlen="1.0"];
Node1_1 -> Node1_2 ;
}
}
There are a couple of "graph" properties that can control what you need.
pad, ranksep, nodesep
Also, I increased your node size, but only for my own ease of use...
digraph "prog.c"
{
graph [pad=".75", ranksep="0.25", nodesep="0.25"];
node [fontname="FreeSans",fontsize="14",shape=record,width=2, height=.5];
edge [fontname="FreeSans",fontsize="12",labelfontname="FreeSans",labelfontsize="10"];
compound=true;
subgraph cluster_main {
Node1_0 [label="main.c", shape=folder, fontcolor="white", style=filled, fillcolor="#00008b"];
Node1_1 [label="routine1()"];
Node1_2 [label="routine2()"];
edge [color="transparent", minlen="0.5"]; // stacking not ok
// edge [color="transparent", minlen="1.0"]; // stacking ok
Node1_0 -> Node1_1 ;
edge [color="black", minlen="1.0"];
Node1_1 -> Node1_2 ;
}
}

Graphviz, changing the size of edge

How to change the size of edge in dot (graphviz)?
I would like to make some edges "bolded".
I wanted to supplement shuvalov's answer. penwidth is indeed the correct command. Additionally, in shuvalov's answer penwidth is both a node and an edge property--also correct.
The distinction i wanted to make:
penwidth, when used as a node
property (e.g., "NodeA" [penwidth =
5]) affects the border line weight
for that node
penwidth, when used as a edge
property affects the line weight of
the edge (default value is "1",
specifying penwidth=2 will make the
edge appear in bold type
if you want to change the line weight
of an edge, you do not need to change
penwidth for the two nodes
connected by that edge (as shuvalev's
answer might suggest)
for a directed graph (the edges have
a direction) you might also wish to change the
size/weight of the arrowhead and
arrowtail, along with the edge
weight, so that all three remain
proportional
the length of an edge can be changed
by setting the weight property, as
elsewhere, the default value is 1.0;
increasing that value increases the
cost of stretching this edge during
rendering (i.e., the drawing
algorithm applies a higher penalty to
solutions in which this edge is
longer); notice that the edge from 1
to 4 is shorter than the edge from 1
to 2.
The following code should illustrate all of this. The rendered graph is shown below the code.
digraph {
/* declare the node & style them */
"Node 1" [shape=diamond, penwidth=3, style=filled, fillcolor="#FCD975"];
"Node 2" [style=filled,fillcolor="#9ACEEB" ];
"Node 3" [shape=diamond, style=filled, fillcolor="#FCD975" ];
"Node 4" [style=filled, fillcolor="#9ACEEB" ]
/* declare the edges & style them */
"Node 1" -> "Node 2" [dir=none, weight=1, penwidth=3] ;
"Node 1" -> "Node 3" [dir=none, color="#9ACEEB"] ;
"Node 1" -> "Node 4" [arrowsize=.5, weight=2.]
}
try this:
"NodeA" [ penwidth = 5]
"NodeB" [ penwidth = 5]
NodeA->NodeB [ penwidth = 3]

Resources