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
Related
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.
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.
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"
}
I have a huge graph with atleast 100 nodes tightly connected in graphviz. I am looking for ways that can automate the edge colors coming out of any given node such that the colors are unique. I have close to 30 edges coming out of each node. Thank you !!
Do you need something that takes a dot file and produces a new colorized dot file? Or do you have some program or script that is generating your dot file? (In what language?)
I am a fan of picking random medium intensity colors for nodes (or clusters), and making the node background a lighter version of that color and making the exiting edges a darker version of that color.
For example, in java I have two utility methods like these.
public static Color hashColor(Object value) {
if (value == null) {
return Color.WHITE.darker();
} else {
int r = 0xff - (Math.abs(1 + value.hashCode()) % 0xce);
int g = 0xff - (Math.abs(1 + value.hashCode()) % 0xdd);
int b = 0xff - (Math.abs(1 + value.hashCode()) % 0xec);
return new Color(r, g, b);
}
}
/**
* #return a hex Color string in the format #rrggbb.
*/
public static String encodeColor(Color color) {
return "#" + String.format("%06x", color.getRGB() & 0xffffff);
}
I had a similar problem, where I had loads of nodes coming out of 1 node.
I used sfdp (dot couldn't handle the number of nodes) with the -Goverlap=prism option, which spaced things out nicely.
You have here a list of all colors accepted by GraphViz: http://www.graphviz.org/doc/info/colors.html
If you generate a graph from a program of your own, a simple way to have unique colors is to put all those colors in a list, and to pick one from this list when you have a new edge. Something like this pseudo-code:
List colors = {red, blue, green, ...};
for edge in edges:
write(edge.source +
" -> " +
edge.sink +
" [color=\"" +
color.next() +
"\"];\n"
);
A cleaner way to do so would be to define a color from its RGB code. You can do this this way:
digraph G
{
A -> B
[
color="#AABBCC"
]
}
Now all you have to do is to generate for all your edges a hexadecimal number between #000000 and #FFFFFF. Color formats are presented here in the documentation: http://www.graphviz.org/doc/info/attrs.html#k:color
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]