Using flowcharts to display legal procedures

Displaying procedures using a textual description, as is often done in law, can become unclear when the procedures are complex. Flowcharts can help to display such procedures more clearly.

Creating a flowchart in Word (© 2019 Lucid Software Inc.)

Applications such as Microsoft Word allow you to make flowcharts by dragging and dropping lines and boxes as desired. This can be intuitive, but it may not be the best approach for more complex cases, where it can be challenging to create the correct representation of the procedure in a flowchart on the first try.

Graphviz is a package that allows you to use the DOT language to create and render graphs. It may not seem intuitive, to those accustomed to working with “what you see is what you get” (WYSIWYG) applications, to use text instead of working with the graphical representation directly. But the advantage of describing your flowchart using a textual representation is that it allows for quick changes to the way nodes are connected. This can be done without having to adjust the layout of the graph yourself, which can be a huge time saver!

The simple two nodes and one edge were created using the following code:

# Add a node (nodeName, nodeLabel)
graph.node('A', 'Node A')
graph.node('B', 'Node B')
# Add an edge (to, from, label)
graph.edge('A', 'B', 'Edge')

Essentially you create nodes with names ‘A’ and ‘B’ with labels ‘Node A’ and ‘Node B’. The third line connects the nodes using their names and the edge itself get the label ‘Edge’.

You’ll want to try this for yourself, but evidently you don’t want the hassle of installing different applications to make this work. Luckily you won’t have to as this you can try it in your browser without installing anything! The following example will demonstrate the ease with which a graph can be created using Graphviz.

Instructions

  • Open this link (it takes some time to load)
  • Click on flowchart-grviz.ipynb
  • Run the code by pressing the Run button
    • Step 1 installs the required packages, this takes some time, which is indicated by the [*] on the left of the code.
    • Step 2 generates the graph, the description of the graph can be adapted to your own needs after you have finished reading this!

Graphs can be made directly in the DOT language, but is is also possible to use libraries available for different languages including R, python and Javascript. These libraries work all work more or less the same as they translate the input in the respective language into a DOT language representation.

Below is the code (Python) and its resulting output for those who are in too much of a hurry to try the example right now.

# load the Graphviz library
from graphviz import Digraph

# create a directional graph
dot = Digraph(comment='How to create flowcharts using graphviz')

# create the necessary nodes
dot.node('A', 'Select a procedure')
dot.node('B', 'Create the important nodes')
dot.node('C', 'Connect the nodes using edges')
dot.node('D', 'Check and correct?')
dot.node('E', 'Export a figure')

#connect the nodes using edges (lines)
dot.edges(['AB', 'BC', 'CD', 'DB', 'DC', 'DE'])

# display the resulting graph
dot

Running this code results in a figure containing the graph as show below.

Simple flowchart on how to create flowcharts

Happy graphing!

See the Graphviz documentation for additional features and explanations.

Leave a Reply

Your email address will not be published. Required fields are marked *