← Home

Visualising Project Dependencies using GraphViz Diagrams

I’ve been working on defining a set of projects with my team which will provide a plan of how we can reach some business goals. There are dependencies between the projects, in that some of them have to be completed before others can start (sequential), while others can run alongside each other (parallel).

What I wanted to do was create a narrative of how we could get to business goals and what steps we’d need to pass along the way. I guess Project Managers might call these “Milestones”.

Drawing this kind of stuff out in a tool like Google Drawings or Visio can be a bit of pain, because as you think of new things, you have to adjust the diagram around which makes you stop thinking about what you’re doing while you drag a load of boxes around a screen so I’ve just started using [0] to do this instead.

Although the syntax looks gnarly when you see a full-blown example with all the styling, it’s straightforward enough to use, and feels a bit like using [1] (which I use all the time).

There’s no need to have big chains of dependencies, you can just chain together a couple of items at a time, GraphViz can work out that A->B->C is equal to A->B;B->C; etc.

Here’s a minimal example of a dot file (“driving.gv”) where the goal is to buy a car.

digraph G {
  "Find Driving Instructor" -> "Book Lessons" -> "Learn To Drive" -> "Book Practical Test" -> "Pass Practical Test";
  "Study for Theory Test" -> "Book Theory Test" -> "Pass Theory Test" -> "Book Practical Test";
  "Pass Practical Test" -> "Buy Car" -> "Buy Insurance" -> "Pay Tax" -> "Drive Somewhere Nice";
  "Decide Which Car To Buy" -> "Buy Car" 
}

The layout is created automatically by the tool, so adding new relationships between items can result in a completely different layout. You can also switch the orientation of the diagram from “top to bottom” (default) to “left to right” by setting the rankdir attribute to “LR”, which makes it look a bit like a timeline.

My workflow is to update the GraphView.gv text file and then run the command line (many text editors have tools within them that let you run external commands from within them). In another window, I have a preview of the output open, set to reload when changes happened.

The command line to produce “driving.png” from the input “driving.gv” file is below but there are many output options, such as postscript or TIFF.

"C:\Program Files (x86)\Graphviz2.38\bin\dot.exe" -Tpng -odriving.png driving.gv

The default styling is something you see a lot of in papers and books, but with a bit of colour selection and styling you can make something that fits better into a presentation.

digraph G {
  /* Set graph background attributes */
  style=filled;
  bgcolor="#548881";
  rankdir=LR; /* Comment out if you want it to be oriented top to bottom */
  /* Set default shape to be a box rather than an ellipse */
  node [shape=box, fontsize=11, fontname="Calibri Bold", color="#2E5F58", style=filled, fillcolor="#2E5F58", fontcolor="#ffffff"];
  /* Style the arrows, because I think that the arrow head is too big by default */
  edge [color="#9DC8C2", arrowsize=0.5];
  /* Tasks */
  "Find Driving\n Instructor" -> "Book Lessons" -> "Learn To Drive" -> "Book Practical\n Test" -> "Pass Practical\n Test";
  "Study for Theory\n Test" -> "Book Theory\n Test" -> "Pass Theory\n Test" -> "Book Practical\n Test";
  "Pass Practical\n Test" -> "Buy Car" -> "Buy\n Insurance" -> "Pay Tax" -> "Drive Somewhere\n Nice";
  "Decide Which\n Car To Buy" -> "Buy Car" 
}

I put this colour palette together using [2]

One GraphViz feature I liked is that it’s possible to apply hyperlinks to the nodes (boxes on the diagrams) and get GraphViz to output clickable HTML imagemaps from the tool. I’ve used this feature on a wiki to link nodes on the overview to other pages which describe projects in more detail. There’s an example of how to get this running at [3]

The documentation is a bit abstract until you read the guides, so I’d recommend having a quick read of [4] and get hacking on some examples.