This turorial is part of the RAP - Rdf API for PHP documentation.
Anton Köstlbacher <email@example.com>
This is a short Tutorial on how to use GraphViz dot within RAP to easily generate visualizations of models in several file formats like png, svg or jpeg.
The visualization tool for RAP V0.9.1 mainly consists of the method
RDFUtil::visualizeGraph(). It prepares a so called dot-file, which is afterwards processed by the dot-application.
GraphViz dot is freely available under the Common Public License. The (binary or ascii) output of the dot-application is directly passed back to the browser. A working demo can be found in the RAP distribution (/rdfapi-php/test/custom_test_viz.php).
The graph visualization features will be included as a standard package into the next RAP release. In order to use them now already, you have to download a current CVS snapshot or download this package and unzip it to your RAP directory.
Before we get started we need to download and install GraphViz dot into a directory on the machine, on which RAP is running. GraphViz dot is available as source code and binaries for several operating systems at http://www.graphviz.org. Additionally we need to set up a directory for temporary files which is read- and writeable by the webserver-software. Take care of security issues, if you are using RAP on a publicly accessible machine!
At first we have to make sure, that the webserver (which runs RAP) can access the GraphViz dot-binary, otherwise we can only generate dot-files and use them for manual input to the Graphviz standalone application. For immidiate generation of images we need to set the following parameters inconstants.php
Here you may find detailed explanations about the STYLE-paramters.
Or you simply try to carefully change the above given values.
The supported file formats can be found here.
Now we are keen on generating our first graph visualization and here we go:
As you see above, there is an alias for
RDFUtil::visualizeGraph() in the model-class, which makes usage really convenient. Note that the code above will instantly return binary data, so we have to set the correct header for the output file:
header('Content-type: image/gif');. If you choose to generate, for example svg, which is a xml-based format, you would need to set the header to
Note: Do not send any headers before. Headers are sent automatically, if there are for example whitespaces before:
<?php. To prevent problems with headers, turn on output_buffering in your php.ini or use output-buffering manually.
This is in fact almost everything you need to know to visualize a model. But we should have a short look at the parameters we can pass to the method:
Adding FALSE as second argument will disable the detection of Namespaces and you get fully qualified URIs as you see below:
The implemented Method in RAP itself can handle very large Models, but visualizing large and/or complex models can take a few minutes, because of the dot-application. The duration depends, as you might assume, on factors like the power of your machine, the size and/or complexity of the model and the chosen output format. I recommend to use XML-based formats like SVG for large models and set an additional header, that forces a 'save as...' window:
You can also get the original dot-file and pass it for example to the gui-version of Graphviz:
In future versions there will eventually be integrated support for alternative visualization engines like Tulip. At present you can use the dot-file and import it manually to your preferred visualizer. Most of the visualizers support the dot-format. See: http://directory.google.com/Top/Science/Math/Combinatorics/Software/Graph_Drawing/