Extension:Graphviz (Dynamic Cache)

From MediaWiki.org
Jump to navigation Jump to search
Wikimedia-logo-meta.png

This page was moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.

GraphViz is a multi-platform suite used to transform textual representations of graphs into raster or vector based image formats. If you don't explicitely layout your graphs, GraphViz will automatically determine the best way to arrange the graph's elements so that nothing overlaps -- with surprisingly good results. The textual represenation of such a graph can be extremely simple, so it is perfectly suited to illustrate all kinds of dependencies and processes in a wiki.

This extension integrates the GraphViz suite into MediaWiki, allowing you to easily display and edit graphs in your MediaWiki installation. You might even favor using GraphViz through MediaWiki, because you can easily illustrate stuff to anyone who has a working web-browser available. And who doesn't, these days ;-)

My primary motivation for writing this extension was that I was unhappy about another GraphViz extension I've found, which stored any graph that was ever drawn on the server for all time to come. This extension instead only caches the last n graphs. However, this requires the html <img> tag to point to a php script for requesting the rendered graph image, so it can be re-rendered if it was dropped from the cache.

Features[edit]

  • Easy deployment
  • Access to the full GraphViz suite: dot, neato, twopi circo, fdp
  • Efficient and configurable caching
  • Ability to place clickable links within graphs

Installation[edit]

Installation of this extension is quite simple. However, it requires write access to a new folder where it manage its cached graphs and image maps. Yeah, the method used to rasterize graphs on demand is quite effective, but not really the cleanest thing there is ;-)

  • Install the GraphViz suite, if you haven't already
  • Copy the php file into your MediaWiki extensions directory and make sure that the proper rights are set (the file should be in the group your webserver runs in and have read/execute permissions set)
  • Create a directory graphviz below the extensions directory and grant the webserver group read/write permissions
  • Append the line include("extensions/GraphvizExtension.php"); to the end of LocalSettings.php in your MediaWiki main directory.

Microsoft Windows(tm) users might need to perform the following additional step:

  • Edit GraphvizExtension.php and adjust the path to the graphviz suite at the top of the file. I never tried to use a path with spaces in it, so you might have more success simply adding the Graphviz\bin directory to your search paths

Usage[edit]

Usage is quite simple. You only have to use one of the tags provided by this extension:

  • <dot_graph>
  • <neato_graph>
  • <twopi_graph>
  • <circo_graph>
  • <fdp_graph>

Then just write your GraphViz code between the opening and closing tag and my extension handles the rest. To obtain in-depth information on the GraphViz language, visit the GraphViz Homepage. Here's an example, taken from a graph available there.

<dot_graph>
digraph finite_state_machine {
	rankdir=LR;
	size="8,5"
	node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
	node [shape = circle];
	LR_0 -> LR_2 [ label = "SS(B)" ];
	LR_0 -> LR_1 [ label = "SS(S)" ];
	LR_1 -> LR_3 [ label = "S($end)" ];
	LR_2 -> LR_6 [ label = "SS(b)" ];
	LR_2 -> LR_5 [ label = "SS(a)" ];
	LR_2 -> LR_4 [ label = "S(A)" ];
	LR_5 -> LR_7 [ label = "S(b)" ];
	LR_5 -> LR_5 [ label = "S(a)" ];
	LR_6 -> LR_6 [ label = "S(b)" ];
	LR_6 -> LR_5 [ label = "S(a)" ];
	LR_7 -> LR_8 [ label = "S(b)" ];
	LR_7 -> LR_5 [ label = "S(a)" ];
	LR_8 -> LR_6 [ label = "S(b)" ];
	LR_8 -> LR_5 [ label = "S(a)" ];
}
</dot_graph>

This piece of code would generate a nice looking graph if my extension was installed. To see the actual graph, follow the link below to my personal wiki.

Download[edit]

Since I've discontinued my personal wiki, there's no download at the moment. I might decide to put the code online again on my new page at a later time, but for the moment, I'm sorry.

See also[edit]

Extension:GraphViz