Graphviz: reducing margin on skewed polygon node - graphviz

I want to use a skewed polygon (aka parallelogram) on Graphviz, the problem is there is too much space between parallelogram border and it's text.
digraph G {
poly1[margin=0, width=0, height=0, shape=polygon, label="This is a polygon\nwithout skew"]
poly2[margin=0, width=0, height=0, shape=polygon, label="This is a polygon\nwith skew", skew=0.3]
}
This is the result of previous code:
As you can see, as soon I set a skew value (ìn this case skew=0.3) the polygon's interior margin increases a lot. Setting margin=0, width=0 and height=0 does not solve the issue.
Is there a way to remove the polygon's interior margin?

There's a way, but it ain't pretty:
digraph G {
poly1[margin=0, width=0, height=0, shape=polygon, label="This is a polygon\nwithout skew"]
poly2[margin=0, width=1.8, height=0.46, shape=polygon, fixedsize=true, label="This is a polygon\nwith skew", skew=0.3]
}
Adding fixedsize=true and specifying the node's width and height (by trial and error) yields this:

Related

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 can I align two (disconnected) nodes in GraphViz?

Suppose I have the GraphViz graph:
digraph G {
a->b->d;
c->d;
}
How can I make a and c be aligned vertically, i.e. appear at the same height?
You can align them using grouping and a group-scope attribute:
digraph G {
{rank = same; a; c;}
a->b->d;
c->d;
}
Note that if your rankdir value is different, this alignment will not be vertical: e.g. if rankdir=LR then a and c will be horizontally aligned to the same position - with the arrows pointing rightwards.

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: how to reduce the top and bottom margins of a node?

How can I reduce the top and bottom margins of these Graphviz nodes? I am specifying "0.05, 0.0 as the margins to each node, with fontsize = 8.
digraph { rankdir = LR
node [shape=box margin=0 width=0 height=0]
asdf [label="asdf\nasdf"]
qwer [label="qwerqwer"]
asdf -> qwer
}
Nodes have a default minimum size (width and height), so if you reduce margins beyond a certain point, it has no effect. At least, this is how it works with box (rectangular) nodes and some of the other simple shapes.
width and height actually specify the minimum width and height, not the actual width and height (unless you also specify that sizes are fixed). So to get smaller margins, you can just use very small width and height values, and the shapes will still be stretched to fit the labels.
With defaults:
digraph {
node [shape=box]
a -> "longer name"
"longer name" -> "taller\nname"
}
Smaller:
digraph {
node [shape=box,width=0.1,height=0.1]
a -> "longer name"
"longer name" -> "taller\nname"
}
You can also set the margin itself if you want it smaller:
digraph {
node [shape=box,width=0.1,height=0.1,margin=0.01]
a -> "longer name"
"longer name" -> "taller\nname"
}

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