assassin
assassin

Reputation: 21189

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!

Upvotes: 13

Views: 1165

Answers (2)

Realz Slaw
Realz Slaw

Reputation: 3298

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.

Upvotes: 1

Lasse Christiansen
Lasse Christiansen

Reputation: 10325

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.

Upvotes: 4

Related Questions