Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force node position (x and y) in graphviz

I am trying to force position of nodes. I have x and y coordinates of my nodes and its also directed graph. I can use the rank=same to handle row (y coordinate), but can't figure out how I can handle column (x coordinate).

like image 204
user664947 Avatar asked Mar 17 '11 19:03

user664947


People also ask

How do you order nodes in Graphviz?

If ordering="out" , then the outedges of a node, that is, edges with the node as its tail node, must appear left-to-right in the same order in which they are defined in the input. If ordering="in" , then the inedges of a node must appear left-to-right in the same order in which they are defined in the input.

What is rank in Graphviz?

Ranks and Subgraphs To work out the layout, Graphviz uses a system it calls "ranks". Each node is assigned a higher rank than the highest ranked node that point to it. If your rank direction is set to left to right ( rankdir=LR ), then nodes with a higher rank are placed further to the right.

How do I use a DOT file in Graphviz?

How do I use graphviz to convert this into an image? For windows: dl the msi and install; Find gvedit.exe in your programs list; Open . dot file in question; Click running person on toolbar; Go to graph -> settings ; change Output file type to file type of your liking and press ok..

What language does Graphviz use?

Graphviz consists of a graph description language named the DOT language and a set of tools that can generate and/or process DOT files: dot. a command-line tool to produce layered drawings of directed graphs in a variety of output formats, such as (PostScript, PDF, SVG, annotated text and so on). neato.


2 Answers

You can use pos attribute (https://www.graphviz.org/doc/info/attrs.html#d:pos), e.g.:

xxx [     label = xxx     pos = "0,0!" ]  yyy [     label = yyy     pos = "10,10!" ] 

You will also have to specify neato or fdp layout engine, so that dot command-line would be (for fdp):

dot -Kfdp -n -Tpng -o sample.png sample.dot 
like image 170
Andrey Avatar answered Sep 19 '22 16:09

Andrey


Here is an example I found: https://observablehq.com/@magjac/placing-graphviz-nodes-in-fixed-positions

Essentially the position attribute "pos" can be specified for a node. Only works with neato or fdp layout engines, not dot.

The ! indicates that the position is an input and should not be altered.

like image 38
JP Thomas Avatar answered Sep 21 '22 16:09

JP Thomas