Use current node positions and add new nodes in graphviz - graphviz

I (as many others, e.g. Force graphviz to preserve node positions ) need to add new nodes to a graph, leaving the nodes already present unchanged.
Do you know if this could work?
1) I let graphviz draw the first instance of the graph
2) I ask graphviz to report where it placed every node
3) I add some additional nodes, using the coordinates obtained at step 2) as pos option, leaving just the new nodes without a pos attribute, free to be placed where graphviz desires.
Is it possible, or graphviz needs every position set?

mmmm, on second thought I tried it this way:
fdp -Tdot dir.dot -o dir.gv
Now dir.gv contains the pos info for all the nodes; then I used dir.gv to produce the 1st graph:
fdp -Tpng dir.gv -o dir1.png
I then edited dir.gv, adding a single node (without pos attribute), then:
fdp -Tpng dir.gv -o dir2.png
by comparing dir1.png and dir2.png, I see that the 2nd layout is completely unchanged, apart from the new node - that's what I wanted!
(edit)
well, more or less: if I start from this:
and add a single node, it's rather ok:
... but adding a small new cluster of nodes, they end up rather dispersed:

The pos attribute is only usefule when using neato or fdp - from here:
In neato and fdp, pos can be used to set the initial position of a node.
For neato, typically the -n option is needed to make use of the pos values - from this page :
If set, neato assumes nodes have already been positioned and all nodes have a pos attribute giving the positions.
Therefore, this isn't possible. The linked answer may prove helpful in case you can start with the full graph and hide nodes instead of adding new ones.

Related

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

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.

Add a new edge while keeping existing graph fixed

Consider the manually drawn red arrow in this graph:
I want to tell graphviz to draw an arrow like that, although the particular path is not important. The important thing is that the existing graph not change at all. Essentially, I want to instruct graphviz to
Draw a certain graph
Keeping that graph fixed, add a new edge to it
Is this possible?
Yes, it should be possible.
If you have a certain graph (e.g. data.dot) and run this file through dot without specifying an output format, dot will output a dot file with added coordinates (attribute pos for nodes and edges). If you save this output (dot data.dot > data_pos.dot) you can add your new edge to it and you can generate your two output files.
You might have to enlarge the bounding box graph [bb="..."]; for the new edge not to mess with positions tho.

Get graphviz to draw nodes above edges

Is there any way to force graphviz to always draw the nodes above edges even if the edge is drawn over (or preferably under) the node?
So far I have tried ordering them and different layer options but not found a way that works.
You'll want to specify outputorder="edgesfirst". This can be found in the documentation.

Resources