Graphviz Filter
Graphviz Filter is a fun little filter that treats input text as Graphviz DOT syntax, converts it using Graphviz tools to the requested format(s) and embeds it in HTML. It's useful to quickly create graphs dynamically from within Drupal nodes. A particularly exciting application is to create an input format consisting of PHP code followed by Graphviz Filter, thereby allowing one to write code that outputs a DOT file, which is then rendered to HTML. For example, one could create a visual taxonomy tree with nodes hanging from the terms, and each visual node would be clickable (using the URL Graphviz attribute) to point to the actual Drupal node. Stuff like that!
NOTE: The following documentation applies to the latest stable release, not the development branch. The latter may contain new features and even change existing ones.
REQUIRES
* Graphviz tools on the system PATH
* PEAR::Image_GraphViz
* PHP >= 5.2.0 (for function array_fill_keys() unless many people request me to support earlier 5.x versions)
USAGE
Enable the module, then add the Graphviz Filter to whatever input format you like. Enclose the DOT syntax within [graphviz]...[/graphviz] tags. In order to control the output, use the following arguments in the DOT comments:
@directed = TRUE or FALSE depending on whether you want a directed graph or an undirected one. By default, will use `dot` for the first case and `neato` for the second.
@command = which Graphviz algorithm should be explicitly used, e.g. dot, neato, twopi, etc.
@formats = comma-separated list of desired output formats that are supported by Graphviz.
@title = tooltip for image-based output formats.
@imagemap (image formats only) = TRUE or FALSE depending on whether you want to create a client-side image map. Needed when you specify URLs on vertices or edges.
@zgrviewer (SVG format only) = TRUE or FALSE depending on whether you want to display SVG output using the ZGRViewer Java applet. In this case, you should download the latest ZGRViewer package from Sourceforge and copy the zgrviewer-XX.jar and zvtm-XX.jar files over to this module's folder, making sure to rename them as zgrviewer.jar and zvtm.jar.
EXAMPLE
Put this in the body of a node whose input format is PHP code followed by Graphviz Filter:
<?php global $user ?>
[graphviz]
/*
* @formats = svg, png, gif
*
*/
digraph G {
fontname = "Bitstream Vera Sans"
fontsize = 8
node [
fontname = "Bitstream Vera Sans"
fontsize = 8
shape = "record"
]
edge [
fontname = "Bitstream Vera Sans"
fontsize = 8
]
User [
label = "{<?php echo $user->name ?>|+ name : string\l+ age : int\l|+ hello() : void\l}"
URL = "http://www.drupal.org"
]
}
[/graphviz]FREQUENTLY ASKED QUESTIONS
Q. How can I render a graph for [buddies, taxonomies, etc.] using this module?
A. Right now the module acts as a filter for nodes. In order to display any of the graphs you have in mind, you can use the following recipe:
1. Write a PHP function that generates a DOT script dynamically from the data you want to display, like the user relationships. The DOT syntax is pretty simple and you should be able to get meaningful output within an hour.
2. Create an input format made up of filters "PHP evaluator" followed by "Graphviz (DOT) syntax".
3. Create a page or story, select the input format that you just created, and call the function that you wrote. Upon submission, the node will render the Graphviz script. Of course, you can also write that function inside the page directly.
3a. Alternatively, you can write a module that exposes a menu item to render your graph. In the callback that implements the menu item, you would call the Drupal function check_markup() with the name of the Graphviz input format and the DOT script that you generated. Upon return you'd get the markup of the graph which you can embed in your own HTML.
A. Use the following recipe:
1. Use the PEAR Wiki Filter module.
2. Create an input format made up of filters "PEAR Wiki Filter" followed by "Graphviz (DOT) syntax".
3. Configure the PEAR Wiki Filter section of the new input format such that the "Ignore regexp" field is set to
/\[graphviz\](.*?)\[\/graphviz\]/siYou can now type Wiki syntax in which you embed any number of [graphviz]..[/graphviz] blocks.
IMPLEMENTATION DETAILS
* Stores generated output in files/graphviz. Ensures uniqueness of filenames by naming them with md5 of input text.
* Uses two new hooks to allow new formats to be handled:
- hook_graphviz_formats() returns an array of formats that the module can embed in HTML.
- hook_graphviz_render($inpath, $outpath, $format, $args) returns HTML script that is sent as output of the filter. $inpath is input DOT file, $outpath is generated file, $format is the format being handled, and $args is the array of arguments found in the DOT comments.
Happy visualization!
Releases
| Official releases | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 5.x-1.1 | 2008-Jun-11 | 8.81 KB | Download · Release notes | Recommended for 5.x | |
| Development snapshots | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 6.x-1.x-dev | 2008-Aug-09 | 9.86 KB | Download · Release notes | Development snapshot | |
| 5.x-1.x-dev | 2008-Sep-20 | 9.87 KB | Download · Release notes | Development snapshot | |
