See the line on the leftmost side of this image.
This isn't a perfect example because the lines don't end on a node, but imagine that there is a node on the bottom left corner of the image. Normally in graphviz if I have a graph like this:
digraph G {
a->c
b->c
}
Then I get two separate lines going into c. Is it possible to have these two lines join before they reach c?
Yes, it is possible to have two lines join before they reach c but, as far as I can see, it requires inserting an invisible node to do it. e.g.:
digraph G {
x [style=invis, height=0, label=""]
a->x [dir=none]
b->x [dir=none]
x->c
}
... which gives:
Related
In this graph the bottom edge is not drawn symmetrical to the top edge:
digraph G {
A:ne -> A:nw;
A:sw -> A:se;
}
I want it to look more like a "fat snowman" with the edge A:sw -> A:se; looping below the node. Is there a way?
Short answer no - or not easily.
Loops seem to be placed from the rankdir direction. If rankdir is TB (down), loops seem to be placed "up".
It you're willing to work at it, you can run your graph twice, once with rankdir=TB, once with rankdir=BT - both times with -Tdot. Then you'd have to replace the offending edge with the equivalent edge from the other graph. [I hope this makes some sense]
Here is a tweaked version of your graph run with different values of rankdir:
digraph G {
A:ne -> A:nw;
A:sw -> A:se;
dummy [style=invis]
dummy -> A [style=invis]
}
In the attached figure, the nodes are arranged in a circle around the node. Is there a (possibly generic) way to arrange the nodes only in the lower semi-circle, without having to provide fixed coordinates for the nodes?
Edit: Would like to achieve something like shown in the image attached below. As one can see - all the nodes are arranged in the lower semi-circular region (this figure was made using CMap Tools).
The code is trivial, but pasting it anyway.
digraph semicircle {
rankdir="TD"
graph [nodesep="0.1", ranksep="0.3", center=true]
mindist="0.4"
S [label="Root", style="filled", fillcolor="greenyellow", shape="box"]
subgraph cluster1 {
rank="same"
A; B; C; D;
S -> {A, B, C, D};
} }
using dot/circo : graphviz version 2.40.1
I noted that circo placed nodes counter-clockwise, starting at 3 o'clock.
I added enough invisible nodes to fill the 2 through 10 o'clock positions.
To make the inter-nodal distances even more uniform I added:
node [shape=square style=rounded]
The result I got is this:
Try this:
digraph semicircle {
rankdir="TD"
graph [nodesep="0.1", ranksep="0.3", center=true, root=S]
mindist="0.4"
S [label="Root", style="filled", fillcolor="greenyellow", shape="box"]
subgraph cluster1 {
rank="same"
A
z1[style=invis label=""]
z2[style=invis label=""]
B; C; D;
S -> A
S -> z1,z2 [style=invis]
S -> { B, C, D};
}
}
I have a .dot digraph which shows a graph as I want (depicting relationship between some tables). I want to add redundant edges to the graph (to represent redundant relationships in the database which exist only to write queries less effortly). These redundat edges, which will be written in a "dotted" style, must not change the deployment of nodes in the graph.
In other words, there's edges which must affect the node positions to print the graph pretty, and other edges which must to be added after the node positions are already computed (which will be styled differently --light gray, dotted, etc; to show that they're not main edges).
Is there options in Graphviz to specify "extra" edges?
Use constraint=false and color=gray on those additional edges.
digraph G {
a -> b -> c -> d;
d -> a [constraint=false,color=gray]
a -> z -> x -> d;
}
Play with that on http://graphviz.it/#/rhlWBZsz
I have a simple vertical graph that looks nice and symmetrical without any labels using the following code:
digraph test_alignment
{
{rank=same; a -> b;}
a -> c;
b -> c;
c -> d;
d -> e;
d -> f;
{rank=same; e -> f;}
}
I'd like to label the edge between A and B as well as the one between E and F, using the same string for each label. I'm expecting the same output, except with longer A->B and E->F edges bearing the same label.
Unfortunately, as soon as I add a label to one of these edges, the general layout looks slightly askew (the result is similar if I add a label to the E->F edge):
digraph test_alignment
{
{rank=same; a -> b [label="Label"];}
a -> c;
b -> c;
c -> d;
d -> e;
d -> f;
{rank=same; e -> f;}
}
I'm very new to graphviz and, following many questions on Stack Overflow, I have been experimenting with different combinations of rank and constraint, I tried using clusters to see if it would keep the top and bottom part properly aligned independently, and tried using a mix of dot, ccomp, gvpack and neato that produced similar results.
It always seems to boil down to the fact adding a label to the edge between nodes with the same rank affects how these nodes are positioned in a way I don't yet understand.
Am I missing something trivial, or am I attempting something I shouldn't instead of letting dot do its thing?
I'm using dot - graphviz version 2.36.0 (20140111.2315) and the linked pictures were produced with dot only (though I obtained similar results when using :
dot test_alignment.dot -Tpng -O
You may try to use the xlabel attribute, together with forcelabels if necessary. From the description:
... For edges, the label will be placed near the center of the edge. This
can be useful in dot to avoid the occasional problem when the use of
edge labels distorts the layout. ...
I was trying to write my own little algorithm for graph layout that only creates a node layout but does not define edge routes. When I use Graphviz to turn the resulting dot file into a graph, the edges are straight lines that cross the nodes and even overlap each other. Is there a way to use Graphviz to layout the edges as nicely as the dot algorithm does, but have the nodes in predetermined fixed positions?
You can see the effect for instance on the following graph:
digraph test {
"a" [pos="0.0,0.0"];
"b" [pos="50.0,50.0"];
"c" [pos="100.0,100.0"];
"a" -> "b";
"a" -> "c";
"b" -> "c";
}
When drawn with dot -Knop -Tpng -otest.png test.dotty the line between a and c crosses b. What I want is that all nodes keep their positions, but the line between a and c goes around b.
Just add:
splines=true;
to your graph - result is: