I recently came across the need to draw some diagrams illustrating relations between entities (are there any other...?). Long story short, there were some redundancies which made my laziness sensor itch. Thus I wrote some lines of perl as a scratch. From scratch.

The problem

I recently came across visualizing some relationships. Since I decided to go for graphviz (and their dot tool) for visualization instead of arranging bubbles with text all by myself, I quickly found myself writing a file like this:

digraph foo {
	Alice -> Bob [ label="A" ]
	Alice -> Carol [ label="A" ]
	Alice -> David [ label="A" ]
	Alice -> Eve [ label="A"]
	Bob -> Francesca [ label="B" ]
	David -> Francesca [label="B" ]
	Eve -> Guiseppe
	Eve -> Hirad
	Eve -> Irene
	Eve -> Julius
	Eve -> Karol
}
... and so on. Easy to see, there is pretty much redundancy. It's not as bad as doing XML pushups, but it's gettin near that degree of frustration.

The solution

That was when I started to use a shortened notation:

Alice -[A]-> Bob | Carol | David | Eve
Bob | David -[B]-> Francesca
Eve -> Guiseppe | Hirad | Irene | Julius | Karol
Now that's nice in more than one dimension. It's not only notably shorter (and thus faster to write), it also can be changed with much less pain as one has not to go through all the redundant parts. Oh, and it does use quotation marks as one always should do (but I'm too lazy to do that on a regular base, too). However, feeding the above shortened graphviz to the shorttolongdot.pl-script (I don't have it with catchy program names) yields the following result:
[ad001@glas ~]$ perl shorttolongdot.pl  < shortnotation.txt
digraph nameless {
        "Alice" -> "Bob" [ label="A" ]
        "Alice" -> "Carol" [ label="A" ]
        "Alice" -> "David" [ label="A" ]
        "Alice" -> "Eve" [ label="A" ]
        "Bob" -> "Francesca" [ label="B" ]
        "David" -> "Francesca" [ label="B" ]
        "Eve" -> "Guiseppe"
        "Eve" -> "Hirad"
        "Eve" -> "Irene"
        "Eve" -> "Julius"
        "Eve" -> "Karol"
}
.. which then again may be fed to an instance of dot (if you don't have one installed on your local machine, try out http://www.webgraphviz.com/).

Download, License

The shorttolongdot.pl script is licensed under BSD license and can be found at down/shorttolongdot.pl. Lay back, have fun, enjoy -- and run responsibly. Yet again, not a masterpiece of responsible programming.

Stichworte:


Impressum