How can I hide the node boundary in graphviz? - 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];
}

Related

When rankdir is LR, why are the nodes in the same rank ordered bottom to top instead of top to bottom?

In the following example, the nodes in the subgraphs are ordered from the bottom to the top instead of from top to bottom. How can that be reversed, so that the start is top-left and the nodes in the subgraphs are ordered from top to bottom (A1-A4 and B1-B4)?
digraph ab
{
rankdir=LR
splines=ortho
ranksep=1
node[shape = record]
subgraph cluster_0
{
label="A"
{
rank = "same"
state0_anchor [label="", style=invis, width=0]
state0_step0 [label="A1"]
state0_step1 [label="A2"]
state0_step2 [label="A3"]
state0_step3 [label="A4"]
}
state0_anchor->state0_step0[style = invis]
state0_step0 -> state0_step1 -> state0_step2 -> state0_step3
}
state0_step3 -> state0_step0 [constraint=false]
state0_step3 -> state1_step0 [constraint=false]
subgraph cluster_state1
{
label="B"
{
rank = "same"
state1_anchor [label="", style=invis, width=0, height=0]
state1_step0 [label="B1"]
state1_step1 [label="B2"]
state1_step2 [label="B3"]
state1_step3 [label="B4"]
}
state1_anchor->state1_step0[style = invis]
state1_step0 -> state1_step1 -> state1_step2 -> state1_step3
}
state1_step3 -> state0_step0 [constraint=false]
state0_anchor -> state1_anchor[style = invis]
start -> state0_step0
}
In your example, when direction of the edges within the subgraphs are reversed, the nodes will be ordered the way you'd like. Something like this:
state0_step3 -> state0_step2 [dir=rev]
state0_step2 -> state0_step1 [dir=rev]
state0_step1 -> state0_step0 [dir=rev]
state0_step0 -> state0_anchor [style = invis]
The same for state1-nodes.
Details about transformations when going LR can be found in https://stackoverflow.com/a/9592856/63733

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 defining more "defaults"

Need draw a complex graph where will be 3 types of edges, and several predefined node-types.
Is possible somewhat define more (e.g. not only one default) "edge type" (or node-type) for the later use?
mean something like:
edge [colorscheme=paired12, color=8, fontsize=11, fontname="Arial narrow"];
edge2 [colorscheme=paired12, color=3, fontsize=11, fontname="Arial narrow", style=bold];
edge3 [colorscheme=paired12, color=5, fontsize=14, fontname="Arial narrow"];
node1 -> node2; /* will use the default edge definition from the above */
node2 -> node3 [edgetype=edge2]; /* will use the second edge definition */
node2 -> node4 [edgetype=edge3]; /* and so on... */
The above, ofc, is not correct - only for explanation...
Using gvpr is simple, if you figure out the basics:
input.dot
digraph test {
node1 -> node2[label="test 1"]; /* will use the default edge definition from the above */
node2 -> node3 [label="test 2", edgetype="edge2"]; /* will use the second edge definition */
node2 -> node4 [label="test 3", edgetype="edge3"]; /* and so on... */
}
filter.gvpr
E {
color="red";
fontsize=11;
fontname="Arial narrow"
}
E[edgetype == "edge2"] {
color="green";
fontsize=11;
fontname="Arial narrow";
style="bold"
}
E[edgetype == "edge3"] {
color="blue";
fontsize=14;
fontname="Arial narrow"
}
With command
gvpr -c -f filter.gvpr -o output.dot input.dot
will produce the output.dot file:
digraph test {
node1 -> node2 [color=red,
fontname="Arial narrow",
fontsize=11,
label="test 1"];
node2 -> node3 [color=green,
edgetype=edge2,
fontname="Arial narrow",
fontsize=11,
label="test 2",
style=bold];
node2 -> node4 [color=blue,
edgetype=edge3,
fontname="Arial narrow",
fontsize=14,
label="test 3"];
}
No, that is not possible.
I often group edge definitions by their type, and redefine the default before each group. For example:
// type 1 edges
edge [colorscheme=paired12, color=8, fontsize=11, fontname="Arial narrow"];
n1 -> n2;
n3 -> n4;
...
// type 2 edges
edge [colorscheme=paired12, color=3, fontsize=11, fontname="Arial narrow", style=bold];
n10 -> n11;
...
// type 3 edges
edge [colorscheme=paired12, color=5, fontsize=14, fontname="Arial narrow"];
...
An other - more complicated - possibility would be to use a tool like gvpr which lets you manipulate a graph, and add edge attributes at that moment.

Graphviz: how to set 'default' arrow style?

Consider this dot language code:
digraph graphname {
subgraph clusterA {
node [shape=plaintext,style=filled];
1 -> 2 [arrowhead=normal,arrowtail=dot];
2 -> 3 -> X2 -> 5;
6;
7;
label = "A";
color=blue
}
}
In the above example, only the 1 -> 2 connection will have the arrowhead=normal,arrowtail=dot style applied; all the other arrows will be of the "default" style.
My question is - how do I set the arrow style (for the entire subgraph - or for the entire graph), without having to copy paste "[arrowhead=normal,arrowtail=dot];" next to each edge connection?
EDIT: Just for reference - the answer from Jesse didn't contain any code; I wrote that snippet and had it in this space here - for unknown reasons, a moderator cut it off from here and pasted it into Jesse's answer.
Use the edge attribute statement, as stated in the DOT Language documentation.
digraph graphname {
subgraph clusterA {
node [shape=plaintext,style=filled];
edge [arrowhead=normal,arrowtail=dot];
1 -> 2 ;
2 -> 3 -> X2 -> 5;
6;
7;
label = "A";
color=blue
}
}
Just like you did for nodes, but using edge, e.g. edge[style=dashed]

Graphviz size/pagesize attribute seemingly ignored

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.

Resources