Ubuntu 12.04 - Graphviz Viewer & Thumbnailer for Nautilus



This article is outdated.
Please follow Ubuntu - Graphviz Previewer & Thumbnailer for Nautilus instead.

Graphviz (Graph Visualization Software) is a package of open-source tools initiated by AT&T Labs Research for drawing graphs specified in DOT language scripts. It consists of a graph description language named the DOT language and a set of tools that can generate and/or process DOT files.

Under Ubuntu and Debian, you get a set of command line tools but no GUI (Graphical User Interface) for Gnome Shell.

Hopefully, a graph visualizer implemented in Java is available with ZGRViewer project. It is based upon the Zoomable Visual Transformation Machine. It is specifically aimed at displaying graphs expressed using the DOT language by using GraphViz binaries.

ZGRViewer is designed to handle large graphs, and offers a Zoomable User Interface, which enables smooth zooming and easy navigation in the visualized structure.

This article explains how to install Graphwiz & ZGRViewer and to declare interaction with Gnome Shell. You'll then be able to :

  • launch ZGRViewer from the Graphics menu
  • double-click on a DOT file to launch ZGRViewer
  • see your graphviz DOT files thumbnails inside Nautilus

This has been tested on Ubuntu Precise 12.04 LTS Amd64 and Gnome Shell 3.4. It should work on any distribution running Gnome Shell.

1. Install ZGRViewer

Under Ubuntu, GraphViz is easily available from the graphviz package.

To resize icons, we also need to install imagemagick package that will provide convert tool.

# sudo apt-get install graphviz imagemagick

ZGRViewer is not provided in the Ubuntu repositories. You need to download and install it from sourceforge.

As it is using Java, you have to make sure that Open JDK is installed.

# java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

If Java is not installed, just install it.

# sudo apt-get install default-jre

You then need to download and install latest ZGRViewer stable version from ZGRViewer download page.

At the time of this article, version 0.9.0 was not working. I used version 0.8.2 which was totally ok.

Installation will be done under /opt/zgrviewer.

The launch script will be duplicated under to set default path to /opt/zgrviewer.

# wget
# sudo unzip -d /opt zgrviewer-*.zip
# sed 's/^ZGRV_HOME=./ZGRV_HOME=\/opt\/zgrviewer/' /opt/zgrviewer/ | sudo tee /opt/zgrviewer/
# sudo chmod +x /opt/zgrviewer/
# rm zgrviewer-*.zip

2. Add Icon to Current Theme

To make it simple, I've used the icon from Graphviz home site for association with ZGRViewer and DOT files.

Icon has to be placed in an active theme's directory. Under Gnome Shell, the gnome theme is used with every theme. So, Graphviz icon will be installed under gnome default theme.

Once you've placed the new icon, you need to regenerate your theme cache file.

# sudo wget -O /usr/share/icons/gnome/256x256/mimetypes/text-vnd.graphviz.png
# sudo gtk-update-icon-cache --force /usr/share/icons/gnome/
gtk-update-icon-cache: Cache file created successfully.

3. Declare ZGRViewer as Graphviz Viewer

Next step is to setup a full Nautilus interaction for Graphviz .dot files.

The expected behaviour is simple :

  • DOT files are shown in Nautilus with Graphviz icon
  • When you double-click on a DOT file, it opens ZGRViewer with the file as parameter.

This can be done in 2 steps :

  1. create a .desktop file to declare the action
  2. create a file association for this action

Action to open Graphviz DOT files will be handled by /usr/share/applications/graphviz.desktop.


[Desktop Entry]
Exec=/opt/zgrviewer/ %f
Name=GraphViz ZGRViewer

Graphviz DOT files are having the mime type text/vnd.graphviz. We can now associate graphviz.desktop with this mime type.

# sudo wget -O /usr/share/applications/graphviz.desktop
# sudo chmod +x /usr/share/applications/graphviz.desktop
# xdg-mime default graphviz.desktop text/vnd.graphviz

4. Nautilus Thumbnails for Graphviz Files

4.1. Declare Thumbnailer

Instead of having a generic Graphviz icon for the DOT files, you can setup Nautilus to generate a thumbnail of the graph.

To do that, Nautilus is using a 'thumbnailer' associated to the mime type of the file. This program (or script) is in charge of generating the thumbnail in a PNG format with a given height.

The following script is a Nautilus 'thumbnailer' for Graphviz DOT files :


#!/usr/bin/env bash
# --------------------------------------------
# Thumbnailer for Graphviz .DOT files
# Procedure :
# Depends on :
#   * dot (graphviz package)
#   * pngtopnm, pnmtopng and pnmscalefixed (netpbm package)
# Parameters :
#   $1 - path of graphviz file
#   $2 - path of generated thumbnail
#   $3 - height of thumbnail in pixels
# Revision history :
#   04/08/2013, V1.0 - Creation by N. Bernaerts
#   25/04/2015, V1.1 - Convert to bash
#   07/10/2017, V1.2 - Conversion to URI and speedup with netpbm
#   15/12/2018, V1.3 - Rework for bubblewrap compatibility
# -------------------------------------------

# check tools availability
command -v dot >/dev/null 2>&1 || { echo "[error] dot missing"; exit 1; }
command -v pngtopnm >/dev/null 2>&1 || { echo "[error] pngtopnm missing"; exit 1; }
command -v pnmtopng >/dev/null 2>&1 || { echo "[error] pnmtopng missing"; exit 1; }
command -v pnmscalefixed >/dev/null 2>&1 || { echo "[error] pnmscalefixed missing"; exit 1; }

# check params
[ "$3" = "" ] && { echo "[error] 3 params are needed : file file-thumb thumb-size"; exit 1; }

# get parameters

# generation
dot -Tpng "${FILE_LOCAL}" | pngtopnm - | pnmscalefixed -xysize ${SIZE} ${SIZE} - | pnmtopng -downscale -compression 0 - > "${FILE_THUMB}"

To allow Nautilus to use this thumbnailer for DOT files, we need to declare this script as the thumbnailer for the mime type of DOT files (text/vnd.graphviz).

This declaration is done via the file /usr/share/thumbnailers/apk.thumbnailer.


[Thumbnailer Entry]
Exec=/bin/bash /usr/local/sbin/graphviz-thumbnailer %i %o %s

These files can be installed with these commands :

# sudo wget -O /usr/local/sbin/graphviz-thumbnailer
# sudo chmod +x /usr/local/sbin/graphviz-thumbnailer
# sudo wget -O /usr/share/thumbnailers/graphviz.thumbnailer

4.2. Restart Nautilus

You can now restart nautilus to reload its complete environment.

# nautilus -q

Your Graphviz files will now appear as thumbnails in Nautilus.


Everything is now ready :

  • ZGRViewer should be available from the Graphics menu
  • Your DOT files should appear in Nautilus with a preview thumbnail
  • A double-click on a DOT file should launch ZGRViewer


Hope it helps.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus