Tuesday, 17 November 2009

Cliques

The problem with graphviz is that it's made by engineers. There are things you can do with it that you probably didn't know, and things you would probably think are obvious, that it doesnt do.

A simple example is links between nodes. Take Leo and I,  if I'm directed torwards leo, the syntax is simple.

"Jason" -> "Leo"

You would similarly think the converse could be written

"Jason" <- "Leo"

But it can't, and neither can

"Jason" <-> "Leo"

both of these will cause graphviz to exit with an error. instead you must use

"Jason" -> "Leo" [dir = both]

which to me makes little or no sense. Flipping the direction of a node should be easy.

My second problem is cliques. If 5 people all collaborate with eachother, then there are 4+3+2+1 edges between them. There is no easy to way to link lots of nodes together in a clique using one line of dot.

Jason -> Leo -> Dan [dir = all]

would seem like a logical argument for this, but it doesnt work. However, you can be cheeky and nest multiple connections.

a {b c d}

means a links to b, c and d.

a{b{c{d}}}

makes edges between all listed nodes, and graphviz will happily render this, but the syntax checkers do not like it, and with good reason, it's hacky, and adding extra attributes/arguements to the edges/nodes would be a nightmare.

Luckily there is yapgvb - a module for python that will generate dot files (or render them to svg,png, etc.), and there is a nice example of how to create a clique in the documentation. This should make it easy to generate cliques in graphviz.

Next up: Database Normalisation, Less is More or Less Better than More?

No comments:

Post a Comment