Simple linear arrangement in graphviz
Asked Answered
C

2

7

I want to generate simple linear arrangements like this:

graph I'd love to recreate with graphviz

I think I am making this way too hard. I tried just hard coding the positions, but it is a little more complicated because I want splined edges.

I don't particularly care if the edges are above or below, but specifying that would be a nice feature.

Cornflakes answered 7/4, 2011 at 17:56 Comment(0)
F
8

That's one of those things one may think it must be simple to do with graphviz, but in fact it's not.

Graphviz is made to minimize edge crossing, therefore it would never lay edges out as in those pictures. That's not what graphviz was made for.

But I agree it would be nice to have an option to turn off edge optimization.

You may create something like this:

rankdir=LR;
ranksep=0;
edge[style=invis];
node[shape=none, width=0.3, height=0, margin=0.02];
4->7->5->1->8->3->6->2;

edge[style=solid, constraint=false];
1:s->2:s->3:s->4:s->5:s->6:s->7:s->8:s

resulting in

graphviz output

As soon as you start using north and south ports, graphviz will try to minimize edge crossings and lead some of the edges between the nodes:

rankdir=LR;
ranksep=0.05;
edge[style=invis];
node[shape=none, width=0.3, height=0, fontsize=12, margin=0.02];
4->7->5->1->8->3->6->2;

edge[style=solid, weight=0];
1:n->2:n;
2:s->3:s->4:s;
4:n->5:n->6:n;
6:s->7:s;
7:n->8:n;

an other graphviz output

If anybody has a better approximation, please post it, I'd be interested.

Fatality answered 7/4, 2011 at 20:45 Comment(0)
D
0

Let me propose using IPE. This is a graphics editor that works on top of LateX, that is, everything you draw is rendered by some LaTeX engine of your choice (by default, pdflatex). This is free software.

Once installed, you can use one of the plugins I made for the program, which I called ipe.embedviz. With this, you can draw a linear arrangement of a graph (specified as a list of edges) by inputting the permutation. You can also draw circular and bipartite embeddings (check the wiki here). Follow the instructions in the readme of the github repo to install it.

After using the ipelet to draw whatever you want, you can edit the result however you want. The drawing can be saved as a PDf which can be used in any LaTeX document using the \includegraphics{} command.

Dolorisdolorita answered 12/8, 2023 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.