Graphviz, changing the size of edge - graphviz

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]

Related

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.

Edge labels writing over edge arrows in 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
]
}

Is it possible to place a label midway of an edge in graphviz?

Is is possible to make a graph like this:
Where the label is in the path of an edge between two nodes.
The closest you get, as far as I know, is rather than trying to fiddle around with edge lables, using text only nodes:
digraph so
{
// standard nodes
node[ shape = box ];
A[ label = "Animal" ];
B[ label = "Elephant" ];
// fake label nodes
node[ shape = none ];
a[ label = " large" ];
// get them connected
edge[ arrowhead = none ];
A -> a -> B;
}
This gives you
This is not optimal as it gives you layout problems - the distance between your "real" nodes is probably larger than you want, and you would have to introduce empty nodes for edges without labels. But at least it comes close to the picture you have posted.

equal widths for boxes in graphviz

Is it possible to get two boxes to be as wide as the widest one.
digraph G {
node[shape=box];
"A long description of a node" -> "short description";
}
Will produce:
But I want the two boxes' size to be aligned.
You can control the (minimum) size of the box with the width and height parameters:
digraph G {
node[shape=box, width = 2.5, height = .75 ];
"A long description of a node" -> "short description";
}
yields

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 ;
}
}

Resources