Graphviz size/pagesize attribute seemingly ignored - graphviz

How does one set the size of the output image in GraphViz via the DOT format?
I'm using QuickGraph and this technique to render a GraphViz. As in the example below, I'm trying to set the maximum size of the rendering. I've tried lots of variations on size (interpreted as inches or as pixels) and pagesize, both, each. Doesn't matter. The only thing that has an effect is resolution.
I can't tell if it's some mode that I don't have set (i.e. mode = "fixedsize"), if it's bad syntax coming out of QuickGraph or if it's a bug in GraphViz. I doubt the second and third heavily, but I'm just throwing it out there.
digraph G {
size="(20,20)", resolution=72, bgcolor="#C6CFD532"
0 [fontcolor="#2F4F4FFF", style=filled, label="Resource A('A')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
1 [fontcolor="#2F4F4FFF", style=filled, label="Resource B('B')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
2 [fontcolor="#2F4F4FFF", style=filled, label="Resource C('C')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
3 [fontcolor="#2F4F4FFF", style=filled, label="Resource D('D')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
4 [fontcolor="#2F4F4FFF", style=filled, label="Resource E('E')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
5 [fontcolor="#2F4F4FFF", style=filled, label="Resource F('F')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
6 [fontcolor="#FFFAF0FF", style=filled, label="Resource G('G')", color="#762226FF", fillcolor="#93473BFF"];
7 [fontcolor="#2F4F4FFF", style=filled, label="Resource H('H')", color="#9FAE8DFF", fillcolor="#C4D6B6FF"];
0 -> 1 [];
0 -> 2 [];
1 -> 2 [];
1 -> 3 [];
2 -> 3 [];
2 -> 4 [];
2 -> 5 [];
2 -> 6 [];
3 -> 7 [];
3 -> 1 [];
4 -> 5 [];
4 -> 6 [];
6 -> 4 [];
}

My dot considers size="(20,20)", a syntax error preferring
size="20,20"; resolution=72; bgcolor="#C6CFD532";
and the DOT specification seems to bear this out.

Related

Draw a program dependence graph with graphviz

I'm trying to draw a PDG, but when I add the data dependencies it gets malformed.
What I have
When I only draw the control dependencies the graph looks fine:
digraph {
4[label="4. int x=1"];
5[label="5. int y=2"];
6[label="6. while(x>0)"];
8[label="8. x=(y+x)"];
10[label="10. z=x+y"];
ENTRY -> 4[rank=same, splines=line];
ENTRY -> 5[rank=same, splines=line];
ENTRY -> 6[rank=same, splines=line];
ENTRY -> 10[rank=same, splines=line];
6 -> 8[splines=line];
}
When I try to add the data dependencies the graph gets malformed:
digraph {
4[label="4. int x=1"];
5[label="5. int y=2"];
6[label="6. while(x>0)"];
8[label="8. x=(y+x)"];
10[label="10. z=x+y"];
ENTRY -> 4[rank=same, splines=line];
ENTRY -> 5[rank=same, splines=line];
ENTRY -> 6[rank=same, splines=line];
ENTRY -> 10[rank=same, splines=line];
6 -> 8[splines=line];
4 -> 6[style=dashed, splines=curved, color=red];
8 -> 6[style=dashed, splines=curved, color=red];
4 -> 8[style=dashed, splines=curved, color=red];
5 -> 8[style=dashed, splines=curved, color=red];
4 -> 10[style=dashed, splines=curved, color=red];
5 -> 10[style=dashed, splines=curved, color=red];
8 -> 10[style=dashed, splines=curved, color=red];
}
I tried to add the attribute "splines=line" to draw straight lines (control dep.), but it doesnt't worked like expected. I also experimented with the attribute "weight" and "rank"...
Can someone give me a hint? Is it possible to set an order for the nodes?
Like:
Entry = first row and first element
Node 4 = second row and first element
...
Node 8 = third row and first element
Expected
Using rank = same properly, plus invisible edges to keep the order of the nodes in the middle should help:
digraph so
{
splines=true;
4[label="4. int x=1"];
5[label="5. int y=2"];
6[label="6. while(x>0)"];
8[label="8. x=(y+x)"];
10[label="10. z=x+y"];
{ rank = same; 4 5 6 10 }
ENTRY -> { 4 5 6 10 }
6 -> 8;
edge[style=dashed, color=red];
{ 4 8 } -> 6;
{ 4 5 } -> 8;
{ 4 5 8 } -> 10;
// keep graphViz from re-ordering these nodes:
4 -> 5 -> 6 -> 10[ style = invis ];
}
yields

How to prevent the subgraph cluster alignment order from being reversed?

If I have a graphviz dot script like this:
digraph g {
node [style=rounded, shape=box]
subgraph cluster1 {
style="invis"
1 -> 2 -> 3 -> 4 -> 5
}
subgraph cluster2 {
style="invis"
6 -> 7
7 -> 8 -> 11
7 -> 9 -> 11
7 -> 10 -> 11
}
edge[constraint=false];
splines="ortho"
5 -> 6 [weight=0]
}
I get an output that looks like this (what I want):
However, if the labels in some of the nodes at the end become too long, the arrangement gets reversed like this:
digraph g {
node [style=rounded, shape=box]
8 [label="very long label"]
9 [label="very long label"]
10 [label="very long label"]
subgraph cluster1 {
style="invis"
1 -> 2 -> 3 -> 4 -> 5
}
subgraph cluster2 {
style="invis"
6 -> 7
7 -> 8 -> 11
7 -> 9 -> 11
7 -> 10 -> 11
}
edge[constraint=false];
splines="ortho"
5 -> 6 [weight=0]
}
How can I prevent this and force the original ordering method to occur?
You will have to define your long labels after having defined the other; graphviz draws the nodes in the order the are defined.
digraph g {
node [style=rounded, shape=box]
subgraph cluster1 {
style="invis"
1 -> 2 -> 3 -> 4 -> 5
}
subgraph cluster2 {
style="invis"
6 -> 7
7 -> 8 -> 11
7 -> 9 -> 11
7 -> 10 -> 11
}
8 [label="very long label"]
9 [label="very long label"]
10 [label="very long label"]
edge[constraint=false];
splines="ortho"
5 -> 6 [weight=0]
}
yields

GraphViz temporal ordering of nodes

I'm new to graphviz and have generated a graph that contains temporal constraints. That is, the order of nodes from left to right matters, but only locally. Here's the ruleset I'm trying to enforce:
1) Only and all 'box'-shaped nodes should be at the bottom of the graph. These represent terminal nodes.
2) Any rule at a 'doublecircle'-shaped node has temporal constraints (i.e. ordering matters).
Here's an attempt of enforcing these rules:
digraph G {
0 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
1 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
2 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
3 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
4 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
5 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
6 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
7 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
8 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
9 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
9 -> 0 [penwidth=3, weight=3]
9 -> 2 [penwidth=3, weight=3]
{
rank=same;
0->2[color=white]
rankdir=LR;
}
10 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
10 -> 9 [penwidth=3, weight=3]
10 -> 5 [penwidth=3, weight=3]
{
rank=same;
9->5[color=white]
rankdir=LR;
}
11 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
11 -> 4 [penwidth=3, weight=3]
11 -> 10 [penwidth=3, weight=3]
{
rank=same;
4->10[color=white]
rankdir=LR;
}
12 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
12 -> 10 [penwidth=3, weight=3]
12 -> 11 [penwidth=3, weight=3]
{
rank=same;
10->11[color=white]
rankdir=LR;
}
13 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
13 -> 4 [penwidth=3, weight=3]
13 -> 9 [penwidth=3, weight=3]
{
rank=same;
4->9[color=white]
rankdir=LR;
}
14 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
14 -> 26 [penwidth=3, weight=3]
14 -> 8 [penwidth=3, weight=3]
{
rank=same;
26->8[color=white]
rankdir=LR;
}
15 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
15 -> 12 [penwidth=3, weight=3]
15 -> 13 [penwidth=3, weight=3]
{
rank=same;
12->13[color=white]
rankdir=LR;
}
26 [shape=circle, fillcolor=palegreen1, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
26 -> 12[label = "0.50", penwidth=2.0, weight=3 ]
26 -> 15[label = "0.50", penwidth=2.0, weight=3 ]
}
From the ruleset, node 9 should have 0 as the left child and 2 as the right child, and so forth. This graph also does not enforce that all 'box;-shaped nodes should be at the bottom of the graph. Is it possible to build such a graph with GraphViz?
Thanks!
I'm not entirely sure how you would like this graph to look, but I have made an attempt. All boxes are at the bottom, this is done using a cluster subgraph (you can change the styling if you do not like the box). To prevent the edges from "special" edges (white in your code, red in mine because the background is also white) from interfering with the ordering, I specified a constraint = false on those edges. Let me know if this helps.
The code:
digraph G {
subgraph clusterSquares {
rank = same
node [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
0; 1; 2; 3; 4; 5; 6; 7; 8;
}
{
node [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
edge [penwidth=3, weight=3]
9 -> { 0; 2; }
10 -> { 5; 9; }
11 -> { 4; 10 }
12 -> { 10; 11; }
13 -> { 4; 9; }
14 -> { 26; 8; }
15 -> { 12; 13; }
26 -> { 12; 15; }
}
{
edge [color = red, constraint = false]
0 -> 2
9 -> 5
4 -> 10
10 -> 11
4 -> 9
26 -> 8
13 -> 13
}
}
The resulting image:

Graphviz .dot node ordering

I'm building a epsilon NFA to recognize a regular expression using the canonical construction. I'm using subgraphs to group various parts of the regular expression. The * operator is giving me particular trouble since dot has decided to move the order of the nodes around. I've tried adding edge weights to force particular edges to be short to keep the order of the edges in line but that does not seem to be working.
What I would like to do is force the nodes in a subgraph in to be placed in a particular order so that the output graph is recognizable as a particular type of (well known) construction. In the example below I would like edges 3, 4, 5 and 6 placed in that order, however the dot places them in the order 6, 3, 4, 5. Any pointers appreciated.
Note that the current weight parameter produces no difference than no weight parameter at all.
I have the following
digraph G {
rankdir = LR;
node [shape = none];
0 [label = "start"];
node [shape = circle];
1 [label = "q1"];
2 [label = "q2"];
3 [label = "q3"];
4 [label = "q4"];
5 [label = "q5"];
node [shape = doublecircle];
6 [label = "q6"];
subgraph re1 {
rank = same;
edge[label = "0"];
1 -> 2;
};
subgraph re2 {
rank = same;
edge[label = "ε"];
3 -> 4 [weight = 10];
edge[label = "1"];
4 -> 5 [weight = 10];
edge[label = "ε"];
5 -> 6 [weight = 10];
5 -> 4 [weight = 1];
6 -> 3 [weight = 1];
};
edge[color=black];
0 -> 1
edge[label = "ε"];
2 -> 3;
}
Here's how I'd write that graph:
First of all, to me this is a graph which goes from top to bottom, not left to right, therefore I removed the rankdir=LR and added rank=same only for nodes 0/1 and nodes 2/3.
I removed all the weights
Most importantly, I added constraint=false to the edges going against the direction of the graph - the one going from node 4 to node 5, and the one from node 6 to node 3.
Here the source:
digraph G {
0 [label = "start", shape = none];
node [shape = circle];
1 [label = "q1"];
2 [label = "q2"];
3 [label = "q3"];
4 [label = "q4"];
5 [label = "q5"];
6 [label = "q6", shape = doublecircle];
{rank = same; 0 -> 1; }
1 -> 2 [label = "0"];
{rank = same; 2 -> 3 [label = "ε"]; }
4 -> 5 [label = "1"];
edge [label = "ε"];
3 -> 4;
5 -> 6;
5 -> 4 [constraint = false];
6 -> 3 [constraint = false];
}
And here's the result:
Now if you want to, you could keep rankdir=LR, just take the markup you posted, remove the weights and add constraint=false to the same edges as I did, it works, too.

How can I hide the node boundary in graphviz?

I am drawing a graph with graphviz. Even though I have penwidth=0 for the nodes, I still see the node boundary. How do I get rid of the node boundary?
My annotation in dot is something like this:
strict graph {
graph [bgcolor=white];
0 [fillcolor=red,
style=filled,
shape=octagon,
penwidht=0,
fontsize=10,
fixedsize=True,
width=0.5,
height=0.5,
type=3];
2 [shape=octagon,
style=filled,
fillcolor=gray,
penwidth=0];
0 -- 2 [penwidth=0.5,
color=gray];
}
This works for me:
node [shape=plaintext]
Source: https://renenyffenegger.ch/notes/tools/Graphviz/examples/index
The issue is you have a typo.
penwidht should be penwidth
strict graph {
graph [bgcolor=white];
0 [fillcolor=red,
style=filled,
shape=octagon,
penwidth=0,
fontsize=10,
fixedsize=True,
width=0.5,
height=0.5,
type=3];
2 [shape=octagon,
style=filled,
fillcolor=gray,
penwidth=0];
0 -- 2 [penwidth=0.5,
color=gray];
}
setlinewidth works for me:
strict graph {
graph [bgcolor=white];
0 [fillcolor=red,
style="filled,setlinewidth(0)",
shape=octagon,
penwidht=0,
fontsize=10,
fixedsize=True,
width=0.5,
height=0.5,
type=3];
2 [shape=octagon,
style=filled,
fillcolor=gray,
penwidth=0];
0 -- 2 [penwidth=0.5,
color=gray];
}

Resources