Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the coordinates from layout from graphviz?

I have been working with pygraph on some project. I completed this example, it works fine.

Now, the problem is the following: the graph is drawn in a picture format (gif). What I need is to get the actual coordinates for each node for the graph layout shown on the gif image. How do I do this? I've been trying and trying, but couldn't find solution to this problem. I thought the the problem's solution would be somehow with manipulating one of the two following lines:

gv.layout(gvv,'dot')
gv.render(gvv,'png','europe.png')

Thanks in advance!

like image 335
Belphegor Avatar asked Dec 18 '12 17:12

Belphegor


1 Answers

You can add the layout information into the graph with :

gv.render(gvv)

and then find out the position of a node getting its attribute pos :

n_france = gv.findnode(gvv, "France")
pos = gv.getv(n_france, "pos")

Then depending on what you want to do, you might need to convert dot coordinates into png image coordinates. You can get useful information from here :

http://www.graphviz.org/faq/#FaqCoordTransformation

It explains in great details the computation from the graph-units to image pixels.

Hope that this is what you are looking for.

like image 54
Anne Avatar answered Sep 29 '22 23:09

Anne