Animating GraphViz dot files: Parsing Parliamentary Processes, Sort Of…

[Re: the original title of, and my description of, the graph visualisations in this post, Michael suggests I don’t really have a clue what they represent. He’s not wrong… ]

A couple of reminders of things past in my feeds yesterday: first up, a reminder of the Workbench reproducible data scraping and cleaning (and built in tutorial…) application in a really useful review by Jon Udell: A beautiful power tool to scrape, clean, and combine data. It’s moved on a fair bit in terms of complexity since I first noted it following a prompt from Owen Stephens several years ago (Linear Cell Based Data Cleaning and Analysis Workflows With Workbench). At the time, as I remember it, it let you use pandas code and SQLite databases as part of the workflow, which also led me to tweet at some point about how it would be interesting to see a pyoliteWASM powered in-browser version, but the latest code repo seems to show all manner of complicated Kubernetes stuff required for deployment (and no simple docker-compose route that I can see) so maybe it’s too complex for a simple WASM backend now (though reverting to an earlier release might still work for a POC?).

Something I’m noticing more is that code projects are making Kubernetes edployment recipes are available. This is great for scaling, but a barrier to folk who just want to try things out or use them at small scale. Maybe in a year or two, folk will commonly be running K8s on the desktop, but I still find it a faff and a hassle and another blocker to sharing things with others. It’d be some much easier to just be able to run docker-compose up.

Secondly, via a tweet from Michael/@fantasticlife, a query about using mapio/GraphvizAnim, “a tool to create simple animated graph visualizations [form GraphViz graphs] aimed mainly at teaching purposes”. It seems like I’d spotted this before, but offhand don’t recall using it for anything, so now seemed like a good opportunity to give it a spin…

For some time, Michael, Anya et al have been attempting to teach parliamentary procedure to machines, a frankly bewildering project into Gormenghastian rituals of the UK Parliament that I’ve been following on and off via the best weeknotes series ever (if you ever want to tune into a never ending tale of everyday parliamentary geeks, I heartily recommend it. It’s funny too…).

It seems that all manner of things can, and do, happen as part of everyday parlimentary processes and the models are… see for yourself.

Anyway, Michael had a thing — [parse code here]— so I grabbed a coffee (how I do miss interesting folk asking interesting “any idea how to…?” off-the-cuff things… Tinkering’s when I’m at my happiest!) and had a play. Here it is:

Here’s what it does, based on a quick hack around the original GraphVizAnim demo [MyBinder demo]:

Create an animation object, add nodes and edges to it with an animation step between each, and you can create a simple slider powered walk through the construction of the graph. In its current form, it’s perhaps not overly useful, but it provides a starting point for something practical to talk around to work out what might be useful.

As an aside, this is exactly another of those things that I think folk should be able to do when we say everybody should learn to code… Maybe 15 mins worth of effort from a cold start but an example to work from?

Another 2 mins just now from cribbing another demo (I spotted an animated gif in the repo and wonderred what had generated it…), and we can create an animated gif…

# Create an image frame for each step...
graphs = ga.graphs()
files = render( graphs, 'process', 'png' )

# Then an animated gif for each frame
from gvanim import Animation, render, gif
gif( files, 'process', 50 )

# And display the image
from IPython.display import Image

Here’s the result (again, not brilliant, but something to work from):

Animated gif of a Parliamentary process parse tree generated using GraphvizAnim

Now I’m wondering… is there a narrated form of one of these steps anywhere (or even just a written narration of a couple of the steps?) that we could use as a crib for generating a “dot2text” templater that would take a dot file and generate a human readable version of it (to the extent that you can: a) narrate the steps in a graph with closed loops in a sensible (readable) way; b) make sense of parliamentary jargon anyway….?)

Author: Tony Hirst

I'm a Senior Lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...

%d bloggers like this: