logo4 Evolution is progress—                          
progress is creativity.        
vline

Graphviz with Django and Creole

view blog view wiki view wiki view wiki

This page describes just another creole macro which renders graphviz instructions from a creole page into an image.

The macro is included by the instruction.

<<dot>>
digraph G {Hello->World}
<</dot>>

As with mathplot there are optional parameters.

  • title that defines the title and alt attributes of the <img> tag
  • show_source is False by default. If True the content of the graph source is displayed

Here is the simple test example.

G Hello Hello World World Hello->World

Rendering a dot macro is a two tier process.

  1. When the creole markup language is translated the macro gives the HTML code of an <img> tag and the graph source is stored temporarily into the database. The key to that database is the src attribute of the <img> tag.
  2. When rendering the image the graph source is taken from the database and stored temporarily into a file, rendered to a png image file. Both temporary files are removed after the procedure returned the image to the server.
G cluster0 User cluster1 Django cluster2 Database a Browser request page b HTML with IMG tag a->b c Browser request image d Render image c->d e Browser display all b->c g Graph definition source b->g d->e f Creole markup source f->b g->d

The Creole Macro

The graph source is taken from the macro's body and stored with a unique key into the database.

[Error: Wrong macro arguments: "py" for macro 'code' (maybe wrong macro tag syntax?)]

The Graphviz View

The vie translates the graphviz source into a png image and returns the image as a HttpResponse object. As the the translation is accomplished by a system call to the dot routine, the files have to be stored temporarily. That process require 3 external prerequisites.

  1. The installation of graphviz
  2. The command to launch the dot routine settings.GRAPHVIZ_DOT_CMD. (On a linux platform you can use the "whereis dot" command to locate it.)
  3. A temporary directory should exist somewhere settings.GRAPHVIZ_TMP_DIR. Write permissions have to be granted to the server.

For convenience i stored the latter two parameters in my setting.

[Error: Wrong macro arguments: "py" for macro 'code' (maybe wrong macro tag syntax?)]

And this is the view code.

[Error: Wrong macro arguments: "py" for macro 'code' (maybe wrong macro tag syntax?)]

Tags: Software

 
   

(c) Mato Nagel, Weißwasser 2004-2019, Disclaimer