Grouping output edges from graphviz - graphviz

I'm trying to draw a graph with two kinds of edges, and I want the two kinds of edges to link to each node from opposite sides, as much as possible. I.e. if an edge of type A enters from the left, I want all edges of type B to exit to the right. I know I could specify compass directions, but I'd like graphviz to be able to switch this around to minimize graph clutter.
Is it this, or something similar, possible?

If you don't want to specify compass points, you'll probably not want to use HTML like labels and ports either.
If you're using dot, you still can achieve something similar by using the samehead and the sametail attributes. From the reference:
Edges with the same head and the same
samehead value are aimed at the same
point on the head
This lets you group outgoing and incoming edges. Here's a simple example:
digraph g{
rankdir=LR;
edge[samehead=h1, sametail=t1];
a1->b->c1;
a2->b->c2;
edge[samehead=h2, sametail=t2];
a3->b->c3;
a4->b->c4;
}
This of course is only about grouping heads and tails of edges, and does not guarantee opposite sides for edges of different types.

My current solution is to replace my old nodes with edges, thus creating two nodes - one for each "port" in the graph. I can then my edges between these "port nodes". Eg. instead of
node1 -> node2 [ sametail="b", samehead = "a" ]
I write
node1_a -> node1_b [ dir=none, style=bold ]
node2_a -> node2_b [ dir=none, style=bold ]
node1_a -> node2_b // if I got head and tail right :-)
Although I don't get boxes for my "nodes", this works okay for my purposes.

Related

Make digraph edge arrow follow node pen width

I would like to increase the border width of my nodes, but I find that the arrow heads in digraph edges do not respect the added width. Instead, they sink into the border. Here's my simple graph.
strict digraph {
a [penwidth="10.0"];
b [penwidth="10.0"];
a -> b;
}
How could I either increase the node width safely, or distance the edges further back? Reading through the attribute list, I didn't find a way. The closest was peripheries, but it makes multiple narrow peripheries instead of a thick one, but the edges do stick to the outermost periphery.
This is a known bug: https://forum.graphviz.org/t/allign-nodes-stroke-with-end-of-the-arrows-path-width/462
The only work-around I know is to "move" node b or shorten the edge - described in the bug report.

Controlling edge order in graphviz dot

I can't figure out how to control edge placement with dot. I have created a small example to show my question. This may or may not be a MCVE; in the process of making it Minimal and Verifiable, I may have dropped the Complete. Anyway:
digraph stuff {
rankdir=LR;
a->b->c->b->a
}
$ dot -V
dot - graphviz version 2.38.0 (20140413.2041)
dot barfu.dot -Tpng > barfu.png
gives me this:
But I'd like to have the left-to-right arrows consistently on top, to reflect the normal state transitions. (Actually, it would be preferable to have them be straight lines in the middle, and have the right-to-left ones always curve below.)
I tried changing the line weight, the length, adding groups, setting connector directions, etc. Nothing seems to help, at least in the bigger graph this comes from.
This doesn't work in my larger diagram, so other answers are still most welcome, but it appears that, since graphviz starts with a default top-down graph, with the most important (downward pointing edges) on the left, they do a simple rotation when you make the graph go left to right, which rotates the top of the graph to the left, and thus the most important edges from the left to the bottom. So, of course, this really simple test case can be fixed by making the graph go right-to-left instead of left-to-right.
digraph stuff {
rankdir=RL;
c->b->a->b->c;
}

How to use graphviz to show graph like this

I used word to make this graph, how to make it in dot language? The line style is perpendicular. Thanks very much!
You can use the 'pos' attribute to place your nodes on an imaginary grid:
graph X
{
a [pos="1,1"]
b [pos="2,2"]
c [pos="2,3"]
d [pos="2,4"]
}
and then use the appropriate flag to the layout program to override neato's desire to place your nodes (you may also need to fiddle with the size of your nodes). You probably end up with edges which are not straight. In that case, define invisible nodes for the junction points on your imaginary grid and draw edges from your top node to the invisible ones and from the invisible ones to RIL_Init and so on. If your graphs are big, this will get pretty tedious..still straightforward...and you still get all the output options of graphviz. The need for pos="1,1!" usually comes up too, the bang meaning 'put it exactly there'.

How can I allow nodes to be spaced out to shorten edges in GraphViz?

I have a digraph with 4 ranks. I'm attaching a screenshot. Very zoomed out, but conveys the idea.
What I want is to allow the second rank to space out vertically so that the lines between rank 2 and 3 are closer to horizontal. Those long lines a very hard to follow! I suppose what I'm asking is "how can I prioritise shortening edge length over keeping nodes of the same rank close together?".
I would include the source but it's very straightforward. The relevant bit:
digraph tags { rankdir=RL; overlap=false; splines=false;
Thanks!
You can increase the weight of the edges between ranks 2 and 3 to force these edges to be shorter. Help the solver by reducing the corresponding weights of the rank 1 to 2 edges.
Looking again, I see that you have a cluster around the items in ranks 1 and 2. This causes them to be kept as close together as possible. Removing the cluster will allow a more relaxed layout and help with the appearance. If you need the cluster, you could place invisible nodes between the groups to force them to be more spread out, but you would lose future flexibility in the layout as the hidden nodes could result in unexpected changes in layout.

Graphviz allow edge-node overlap

I would like to use graphviz for a project and am unable to get the behaviour I want. I have a graph that I can draw with graphviz just fine, but I also have a version of the same graph that has some extra edges. I would like the second graph to be drawn with the nodes in the same positions as the first one and the edges in the same positions, but the new edges to be drawn without avoiding any overlap with nodes.
To get a better idea of what I want, imagine a Powerpoint slide with a graph and then on the next slide the same graph with these extra edges that appear on top of the first graph, wihtout modifying the look of the old parts of the graph. That is the effect I want.
I think the effect could be achieved by having some edges ignore any overlapping constraints. I could not figure out how to control the overlap between edges and nodes for particular edges (or even for all edges).
Any ideas?
You can get dot to output another .dot file, with positions assigned to all elements, via dot -Tdot (or maybe dot -Txdot). Add your additional edges to that file, and run it through dot again to produce your second graph.

Resources