Friday, May 24, 2013

Using Notepad++ to render Graphviz figures

Graphviz is a really neat tool to quickly draw (un)directed graphs of various kinds. I really like the way one can just stick together the nodes by elementary text commands.
On Windows you can use "gvedit.exe", but I don't like how the input text files and the graphics are displayed and just recently I encountered an issue where it would not render my *.gv files even they are valid (they rendered using the command line tools). Seemed to be an file encoding issue.
Since a colleague of mine (who does not like using the command line) asked me to setup the "rendering system" on her PC, I was looking for and found a feasible setup:
  • Notepad++ - to edit the source files
  • NppExec Plugin - to call the command line tools and render the graphics
  • SumatraPDF - to display the rendered PDF file
Here's how to do it:
  • Download & Install
    • Graphviz
    • Notepad++
    • SumatraPDF (of course you may use a different PDF viewer, just make sure it is able to update the preview when the pdf file changes)
  • Goto Plugins -> Plugin Manager -> Show Plugin Manager
  • Install the NppExec plugin
  • Configure the NppExec plugin (Reference)
    • Press F6 (run command) and enter the following script (all in 1 line)
      dot "$(FULL_CURRENT_PATH)" -Tpdf -o "$(CURRENT_DIRECTORY)\$(NAME_PART).pdf"
      It calls "dot" from the Graphviz tools (which should be in your system PATH), passes your current Notepad++ file and renders a *.pdf file. You find a full list of available output formats in the documentation.
    • Save it as "dot" script
  • Update / render the graphics with Ctrl+F6 (run previous command again)
  • SumatraPDF will immediately update the graphics so you don't need to close and reopen the generated file.

3 comments:

  1. Thank you! gvedit.exe was giving me trouble. :)
    Cheers!

    ReplyDelete
  2. Even better: Add a second line pointing to your Sumatra installation and it will open the pdf file or if already open it will reload the file and remember the previous zoom! The following shows the first line from above and my new second line:

    dot "$(FULL_CURRENT_PATH)" -Tpdf -o "$(CURRENT_DIRECTORY)\$(NAME_PART).pdf"
    npp_run cmd /c C:\Users\YOU\AppData\Local\SumatraPDF\SumatraPDF.exe "$(CURRENT_DIRECTORY)\$(NAME_PART).pdf"

    where

    "C:\Users\YOU\AppData\Local\SumatraPDF\SumatraPDF.exe"

    is the path to your install of Sumatra.

    ReplyDelete
  3. Sorry about the formatting. Any gaps above should just be single spaces.

    ReplyDelete