Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force nodes to overlap by a specified amount in the dot language (graphviz)

I am a newbie to the dot layout in graphviz. I am trying to specify a graph in the dot language, and I want certain sets of nodes to be forced to overlapped by a certain amount (say 70% of their area or something with that effect). I know I can force the x and y positions of nodes and thus induce overlap, but in this case, I am writing a C# program that given certain input spits out the relevant dot script for the graph, so the number of nodes, etc are not hardcoded and so I can't come up with a scheme to hard-code x and y positions of all nodes. Any help in this will be greatly appreciated!

Thanks a lot!

like image 575
assassin Avatar asked Aug 18 '12 19:08

assassin


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.

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


2 Answers

As @ninjalj points out, one of the neat things about graphviz is, that it allows you to represents graphs nicely and get rid of "flaws" or "imperfections" like overlaps - e.g. by using attributes such as overlap and overlap_scaling.

However, you point out that:

I know I can force the x and y positions of nodes and thus induce overlap, but in this case, I am writing a C# program that given certain input spits out the relevant dot script for the graph, so the number of nodes, etc are not hardcoded and so I can't come up with a scheme to hard-code x and y positions of all nodes.

So, as I see it, what you say is that you know that when you are given a certain input, you are going to generate a certain graph - in other words, you know the number of nodes ( and clusters ) as a function of the input. This makes me think that @Daniel Kinsman's suggestion might be the way to go for you - that is, implementing your own DOT layout engine for that particular purpose.

I do not say that this is simple, however, it is not impossible and the logic needed of course greatly depends on the goal of your application.

But before doing any implementation, I think you should have a look at the cluster functionality already built into graphviz ( which @Daniel Kinsman also points out ) and think about if it really is worth the extra effort to do a custom DOT layout engine implementation or if the cluster functionality might be sufficient for you.

like image 88
Lasse Christiansen Avatar answered Oct 05 '22 12:10

Lasse Christiansen


This might be of use: You can use graphviz's dot output format, which outputs the nodes and their explicit layed-out positions. Then you can read it back in, and alter their sizes. It is hard to tell if this would help your specific need without some demonstration images of what exactly you want. Also this might not be the best solution. Just thought I'd add it to the arsenal of tools you can use.

like image 30
Realz Slaw Avatar answered Oct 05 '22 12:10

Realz Slaw