MediaWiki extensions manual
GraphViz
Release status: unmaintained
Implementation Tag
Description Provides an online graph renderer
Author(s)
Latest version 3.1.0 (2018-03-13)
MediaWiki 1.29.x - 1.32.x only
PHP 5.4+
Composer mediawiki/graph-viz
License GNU General Public License 2.0 or later
Download
README
RELEASE-NOTES
Example
Parameters
  • $wgGraphVizDefaultImageType
  • $wgGraphVizExecPath
  • $wgGraphVizMscgenPath
Hooks used
  • ArticleDeleteComplete
  • PageContentSave
  • ParserFirstCallInit
  • RejectParserCacheValue
  • UserGetReservedNames
Quarterly downloads 29 (Ranked 141st)
Translate the GraphViz extension if it is available at translatewiki.net
Issues Open tasks · Report a bug

The GraphViz extension lets you create and display graphs as in-line images on wiki pages using tools from the open-source Graphviz and Mscgen projects:

Compatibility

MediaWikiGraphVizSemantic Result Formats
1.27.x - 1.28.x2.x.x2.5.x
1.27.x - 1.28.x2.x.x3.0.x
1.29.x - 1.32.x3.x.x3.0.x
1.33+Not compatible, use the Diagrams or External Data extension

see http://wiki.bitplan.com/index.php/GraphViz_MediaWiki_extension and http://wiki.bitplan.com/index.php/Diagrams for current discussion about replacing this extension with a somewhat compatible solution.

Installation

From the MediaWiki Extension Distributor

Download from Special:ExtensionDistributor/GraphViz

With Composer

GraphViz should be installed using built-in Composer support. The package name is mediawiki/graph-viz. For instructions on how to install Composer see MediaWiki's user manual for Composer.

Once you have Composer properly installed, go to your MediaWiki installation directory and add the extension to your to your composer.local.json:

{
  "require": {
    "mediawiki/graph-viz": "^3.1"
  }
}

And then run:

composer update

Without Composer

  1. Download the GraphViz extension archive from GIT and extract it into your MediaWiki "/extensions/GraphViz" directory.

Common

  1. Update LocalSettings.php to include the following:
    wfLoadExtension( 'GraphViz' );
    
  2. Visit your wiki's Special:Version page and verify that the correct version of the GraphViz extension is installed.
  3. Install one of the external tools "Graphviz" or "Mscgen".
    1. Windows: Get your copy here: http://www.graphviz.org/Download.php or here http://www.mcternan.me.uk/mscgen/
    2. Unix: Same links as for windows but normally it should be pre-installed (at least graphviz - search for dot) or can be found in the package manager.
    3. Ubuntu/Debian:
      sudo apt-get install graphviz
      
      and
      sudo apt-get install mscgen
      
  • Make sure that write permissions for the "$IP/images" directory are granted.
  • Make sure that internet users get read/execute access on your executables if you use server installations (especially under Windows).

Configuration

Set configuration parameters in LocalSettings.php only if the defaults do not suit your environment.

Configuration variables
Variable namePlatformDefault ValueDescriptionVersion
$wgGraphVizExecPath WindowsC:/Program Files/Graphviz/bin/Path of the directory containing the Graphviz executables (dot.exe, circo.exe, fpdp.exe, neato.exe, twopi.exe)all
Unix/linux/usr/bin/Path of the directory containing the Graphviz executables (dot, circo, fdp, neato, twopi)all
$wgGraphVizMscgenPathall<none>Path to the mscgen executableall
$wgGraphVizDefaultImageTypeallpngDefault output image type if none is specified on the "format" attribute of an individual graph>= 1.0

Note: Under Linux, shell commands such as the Graphviz and mscgen executables are invoked with the limits given by $wgMaxShellTime, $wgMaxShellMemory and $wgMaxShellFileSize. If graphs or message sequence charts do not render then you may need to tune these settings for your installation.

Drawing Graphs

You may define a graph in the dot language and enclose it in graphviz tags as follows:

<graphviz>
dot-language
</graphviz>

You may define a message sequence chart in the mscgen language and enclose it in mscgen tags as follows:

<mscgen>
mscgen-language
</mscgen>

When the wiki page is saved (or when you click "Show preview" after editing) an image is produced that corresponds to the DOT or mscgen text and it is shown in-line on the page. The image is also uploaded so it may be included in other pages directly.

See the #Examples for some basic graphs.

Graph Tag Attributes

Graph tag attributes may be supplied with either graphviz or mscgen as follows:

<graphviz attr1="value1" attr2="value2" ... attrN="valueN">
dot-language
<graphviz/>
<mscgen attr1="value1" attr2="value2" ... attrN="valueN">
mscgen-language
<mscgen/>

The following extended image syntax attributes are supported as graph tag attributes: type, border, location, alignment, size, link, alt, caption.

AttributeTagDescriptionValueVersion
formatgraphvizspecifies the graph image output formatgif, jpg, jpeg, png, svg*all
formatmscgenspecifies the message sequence chart image output formatpng, svg*all
uniquifiergraphvizneeded to display graphs of the same name on the same page (rare)text (appended to the graph name)>=1.0
uniquifiermscgenneeded to display multiple message sequence charts on the same page (common)text (used as message sequence chart name)>=1.0
renderergraphvizsee "layout commands" in the Graphviz documentationdot, neato, fdp, sfdp, circo, twopiall
preparsegraphvizreplace magic words before invoking the graphviz rendererdynamic>=1.5.0
preparsemscgenreplace magic words before invoking the mscgen commanddynamic>=1.5.0

The option preparse="dynamic" makes it also possible to use GraphViz and templates and import these into a MediaWiki site. Changes to the original template will then be passed on. No preparse option will lead to two images, in case of a change to the original, of which the older version will always be imported should the template be called.

  • svg requires additional configuration.

Multiple Graphs Per Page

For graphviz, use unique names for each graph to display multiple graphs on the same page.

First GraphSecond Graph
<graphviz>
graph NAME {...
}
</graphviz>
<graphviz>
graph ANOTHERNAME {...
}
</graphviz>

For mscgen, use the "uniquifier" tag attribute to display multiple message sequence charts on the same page.

First Message Sequence ChartSecond Message Sequence Chart
<mscgen uniquifier="NAME">
msc {...
}
</mscgen>
<mscgen uniquifier="ANOTHERNAME">
msc {...
}
</mscgen>

Graphs in the DOT and mscgen languages may include URLs. These follow the pattern URL="link" where "link" is governed by the ImageMap syntax:

"All links are given in either the form [[Page title]] or [[Page title|description]]. In the latter case, the part after the pipe becomes the title attribute of the link—in most browsers, it will pop up as a tooltip when the user hovers over it; the part after the pipe also becomes the alt text for the link. If no explicit link description is given, the page title is used."

Additionally, external links are supported with or without square brackets. Specify external links without square brackets in order to honor DOT tooltip attributes (e.g. URL="http://mediawiki.org", tooltip="MediaWiki"). The MediaWiki "external link with different label" form is also supported (e.g. [http://mediawiki.org MediaWiki]).

Remark:

The link format is different from the format used in earlier versions. ( < 1.0).

See #Example 3 for an example with links.

Finding graphs and message sequence charts

Pages with graphs or message sequence charts will have the "graphviz" page property set. Using Special:PagesWithProp, you can find pages that have graphs or message sequence charts. (Example query for the English Wikipedia.)

Restrictions

This extension imposes the following restrictions on the DOT language input:

  • Any image attribute values are required to be the names of uploaded files.
  • Any IMG SRC attribute values in HTML-like labels are required to be the names of uploaded files.
  • The imagepath attribute is not allowed.
  • The shapefile attribute is not allowed.
  • The fontpath attribute is not allowed.

Examples

In addition to the examples below, here is a nice flickr gallery of graphviz-rendered graphs.

Example 1

Graph for example no. 1
<graphviz border='frame' format='png' caption='Graph for example no. 1'>
digraph example1 {Hello->World}
</graphviz>

Example 2

Graph for example no. 2
<graphviz renderer="neato" caption="Graph for example no. 2">
graph example2 {
  run -- intr;
  intr -- runbl;
  runbl -- run;
  run -- kernel;
  kernel -- zombie;
  kernel -- sleep;
  kernel -- runmem;
  sleep -- swap;
  swap -- runswap;
  runswap -- new;
  runswap -- runmem;
  new -- runmem;
  sleep -- runmem;
}
</graphviz>

Example 3

Graph for example no. 3 (contains Wiki-Links)
<graphviz caption="Graph for example no. 3 (contains Wiki-Links)" alt="phylogenetic tree" format="png">
digraph example3 {
  node [shape=plaintext];
  Mollusca [URL="[[w:Mollusca]]"];
  Neomeniomorpha [URL="[[w:Neomeniomorpha]]"];
  X1 [shape=point,label=""];
  Caudofoveata [URL="[[w:Caudofoveata]]"];
  Testaria [URL="[[w:Testaria]]"];
  Polyplacophora [URL="[[w:Polyplacophora]]"];
  Conchifera [URL="[[w:Conchifera]]"];
  Tryblidiida [URL="[[w:Tryblidiida]]"];
  Ganglioneura [URL="[[w:Ganglioneura]]"];
  Bivalvia [URL="[[w:Bivalvia]]"];
  X2 [shape=point,label=""];
  X3 [shape=point,label=""];
  Scaphopoda [URL="[[w:Scaphopoda]]"];
  Cephalopoda [URL="[[w:Cephalopoda]]"];
  Gastropoda [URL="[[w:Gastropoda]]"];
  Mollusca->X1->Testaria->Conchifera->Ganglioneura->X2->Gastropoda
  Mollusca->Neomeniomorpha
  X1->Caudofoveata
  Testaria->Polyplacophora
  Conchifera->Tryblidiida
  Ganglioneura ->Bivalvia
  X2->X3->Cephalopoda
  X3->Scaphopoda
}
</graphviz>

Example 4

Message sequence chart for example no. 4
<mscgen caption="Message sequence chart for example no. 4">
msc {
  a,b,c;

  a->b  [label="ab()"];
  b->c  [label="bc(TRUE)"];
  c=>c  [label="process(1)"];
  c=>c  [label="process(2)"];
  ...;
  c=>c  [label="process(n)"];
  c=>c  [label="process(END)"];
  a<<=c [label="callback()"];
  ---   [label="If more to run", ID="*"];
  a->a  [label="next()"];
  a->c  [label="ac()"];
  b<-c  [label="cb(TRUE)"];
  b->b  [label="stalled(...)"];
  a<-b  [label="ab() = FALSE"];
}
</mscgen>

Contributions and history

See RELEASE-NOTES.md.

Dependencies

The GraphViz extension depends on Extension:ImageMap as of version 1.0.

The following extensions depend on the GraphViz extension:

See also

This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.