Graphviz drawing two arrows intead of one - graphviz

I have a strange result trying to make a simple graph using graphviz. Two arrows are drawn between 3 and 4 instead of one. I can't figure out why, if it is a bug or if I've done something wrong. Here is a minimal example, anything I remove makes the problem dissapear:
digraph dia {
newrank=true;
1 -> 2;
subgraph cluster_1 {
label = "1";
3 -> 5;
3 -> 6;
5 -> 6
}
subgraph cluster_2 {
label = "2";
4;
}
3 -> 4;
{rank="same"; 2; 5; 6;}
{rank="same"; 3; 4}
}
It produces the following output:
My actual graph is larger than that, and I need newrank property.
I think I have the lastest version of graphviz...
dot - graphviz version 2.40.1 (20161225.0304)
Thanks for any help !

I also noticed some strange things going on in graphviz when clusters are being used (especially in combination with rank=same. So probably a bug, yes.
In your situation simply adding a port to one of the problematic nodes fixes the problem:
3:e -> 4;

Related

Increase curvature of connecting arcs

Consider:
digraph D {
0[pos="0,0!"]
1[pos="0,5!"]
0 -> 1[label=0.25]
1 -> 0[label=0.50]
}
Rendered under neato engine, this gives:
Is there a way to increase/control the curvature of the connecting arcs so that the rendering is something like the hand-drawn annotations below:
Edited to add: While I don't have to stick with neato, it is important in my application that the node pos coordinate values be upheld.
[there may be better ways, but edges are pretty hard to wrangle]
This solution requires neato -n (see https://graphviz.org/faq/#FaqDotWithNodeCoords) and (https://graphviz.org/docs/attrs/pos/)
Different versions of neato seem to produce different results when previous answer is input. This input file should work with older & newer versions of neato.
digraph D {
// next lines from the Graphviz FAQ
overlap=false
splines=true
0[pos="0,0!"]
1[pos="0,5!"]
// stick an invisible node in the middle, to force the edges out
half [pos="0,2.5!" width=1.1 height=1 style=invis]
0:nw -> 1:sw [label=0.25]
1:se -> 0:ne [label=0.50]
}
Giving:

Graphviz node ordering

I want to have a diagram which has the layout as follwing :
But when i wrote the codes like this:
digraph g {
a->b->c;
{rank=same;b,d,e,f,g,h}
d->g [weight = 1];
d->f [weight = 10];
}
And comes like this:
The dot guide even recommends this:
Edge weights also play a role when nodes are constrained to the same rank.
Edges with non-zero weight between these nodes are aimed across the rank
in the samedirection (left-to-right, or top-to-bottom in a rotated drawing) as far
as possible. This fact may be exploited to adjust node ordering by placing
invisible edges (style="invis") where needed.
I wander why it not work?
add the following line in your graph:
f->g[style=invis];
digraph g {
a->b->c;
{rank=same;b,d,e,f,g,h}
d->g [weight = 0];
d->f [weight = 1];
}
Works as you wish.
But, I also don't know why
d->g [weight = 1];
d->f [weight = 2];
doesn't work.
Maybe it depends on layout type, neato or dot or etc. See https://graphviz.gitlab.io/docs/attrs/weight/
Also
digraph {
a -> b -> c;
d->g
d->f
{rank = same; b;d;e;f;g;h;}
}
Works. Source

Left->Right, Down, Right->Left, Down, Left->Right layout in Graphviz

I have a very long linear (not many branches) flowchart that shows up in graphviz as either too tall to fit on a single page, or too wide (if direction was left to right)
Is there an easy way to have graphviz lay out the graph in such a way that it goes Left to right, then down, then right to left, then down? (I hope this explains it well).
Something like this (drawn in visio)
It's actually quite easy to get exactly what you want:
digraph so
{
node[ shape = square ];
{ rank = same; 1 2 3 }
{ rank = same; 6 5 4 }
{ rank = same; 7 8 }
1 -> 2 -> 3;
3 -> 4;
6 -> 5 -> 4 [ dir = back ];
6 -> 7;
7 -> 8;
}
yields
rank = same makes sure that the boxes defined here stay side by side; without that they would be aligned vertically.
Since the boxes are drawn left to right in the order they are defined, it's necessary to define them the way done above for the 2nd row.
That's also the reason for having the arrows in the middle row pointing backward - in reality the edge goes from 6 to 5 and from 5 to 4.
From here you can start fine tuning - labels in the boxes instead of the numbers, longer edges, colors...

How to prevent edge labels from messing up the layout in graphviz?

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. ...

graphviz dot: how to insert arrows from a node to center of an arrow

I try to create diagrams for MPLUS analyses with dot from the graphviz package. Does anybody have experience with using dot to visualize structural equation models/latent class mixture models? There is especially one feature that I can't figure out how to do beautifully:
I need arrows from nodes to the center of another arrow like
C
|
|
V
A ------------> B
I tried to insert an invisible node at the intersection of the arrows. This, however, results in a "cracked" A--->B arrow because dot does represent it as two independent arrows.
Is this even possible with dot?
Thanks for suggestions and help!
Gregor
Building on spenthil's answer to get rid of the kink:
digraph {
ab[label="", fixedsize="false", width=0, height=0, shape=none];
a -> ab[arrowhead=None];
ab -> b;
c -> ab;
{rank=same; a; ab; b};
}
Output:
An other possibility would be to play with the weight attribute of the edges to straighten out edges.
The following prevents "cracked" arrows. Dot unfortunately introduces a kink between the a -> ab and ab->b edges. Not aware of a layout algorithm that prevents this.
digraph {
a;
ab[label="", fixedsize="false", width=0, height=0, shape=none];
b;
c;
a -> ab[arrowhead=None];
ab -> b;
c -> ab;
}
Output:

Resources