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

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

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 (dot) control edge routing

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]
}

Add extra edges to a digraph in Graphviz

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

Draw an aligned edge

Considering the following graph:
digraph {
node[shape=square style=filled];
A [color=olivedrab4 fillcolor=olivedrab3];
B [color=orange3 fillcolor=orange];
C [color=royalblue4 fillcolor=royalblue];
D [color=orangered3 fillcolor=orangered];
edge[arrowhead=none];
node[shape=circle];
u -> v -> w -> {x y}
A -> u;
B -> v;
C -> y;
D -> x;
edge[arrowhead=normal];
splines=true;
sep=1;
A -> D [len=100];
A -> C [len=100];
}
which neato renders like this:
is it possible to draw the edges from A to D (and A to C) in a way that the spline is aligned to the path A-u-v-w-x-D (and A-u-v-w-y-C respectively)?
Background: I'd like to draw overlays, situated above underlay network topologies.
Digging around in the source code i found the pathplan library (which seems to be used by at least neato).
To quote from lib/pathplan/README:
Our plan is to clean up the
internal interfaces (where data structures are copied and converted
so we could glue in some older code). We also changed the spline
fitter router so that the output spline is not forced to hit all the
points of the input path. We plan to extend the library interface to
let the caller determine which path points must be hit.
That sounds somewhat like what i want...

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