Extension:GraphViz

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
GraphViz

Release status: stable

GraphViz Logo.png
Implementation Tag
Description Provides an online graph renderer
Author(s)
Latest version 1.4.1 (2014-10-21)
Database changes No
Composer mediawiki/graph-viz
License GPL
Download
Example #Examples
Parameters

$wgGraphVizSettings

Hooks used
ParserFirstCallInit

PageContentSave
PageContentSaveComplete
OutputPageParserOutput
ArticleDeleteComplete
EditPageGetPreviewText
EditPageGetPreviewContent

Translate the GraphViz extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

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:

Installation[edit | edit source]

With Composer[edit | edit source]

From MediaWiki version 1.22 onwards, 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. MediaWiki versions prior to 1.22 can use Composer via Extension:ExtensionInstaller.

Once you have Composer properly installed, go to your MediaWiki installation directory and run:

  • composer require mediawiki/graph-viz '*' for the latest stable version or
  • composer require mediawiki/graph-viz 'dev-master' for the latest development version

For future updates call composer update or composer update mediawiki/graph-viz.

Without Composer[edit | edit source]

  1. Download the GraphViz extension archive from GIT and extract it into your MediaWiki "/extensions/GraphViz" directory.
  2. Update LocalSettings.php to include the following:
    • require_once("$IP/extensions/GraphViz/GraphViz.php");

Common[edit | edit source]

  1. Update LocalSettings.php to include the following:
    • require_once("$IP/extensions/ImageMap/ImageMap.php");
  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 aptitude install graphviz graphviz-dev
  • 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[edit | edit source]

Set configuration parameters in LocalSettings.php only if the defaults do not suit your environment. For each parameter, add the line $wgGraphVizSettings->Parameter="value" in your LocalSettings.php after the line include("extensions/Graphviz.php");

Parameter Platform Default Value Description
execPath Windows C:/Program Files/Graphviz/bin/ path to the Graphviz executables (dot.exe, circo.exe, fpdp.exe, neato.exe, twopi.exe)
execPath Unix/linux /usr/bin path to the Graphviz executables (dot, circo, fdp, neato, twopi)
mscgenPath all <none> path to the mscgen executable
defaultImageType all png default output image type if none is specified on the "format" attribute of an individual graph

Drawing Graphs[edit | edit source]

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[edit | edit source]

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.

Attribute Tag Description Value
format graphviz specifies the graph image output format gif, jpg, jpeg, png, svg*
format mscgen specifies the message sequence chart image output format png, svg*
uniquifier graphviz needed to display graphs of the same name on the same page (rare) text (appended to the graph name)
uniquifier mscgen needed to display multiple message sequence charts on the same page (common) text (used as message sequence chart name)
renderer graphviz see "layout commands" in the Graphviz documentation dot, neato, fdp, sfdp, circo, twopi
  • svg requires additional configuration.

Multiple Graphs Per Page[edit | edit source]

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

First Graph Second 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 Chart Second Message Sequence Chart
<mscgen uniquifier="NAME">
msc {...
}
</mscgen>
<mscgen uniquifier="ANOTHERNAME">
msc {...
}
</mscgen>

Links[edit | edit source]

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.

Restrictions[edit | edit source]

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[edit | edit source]

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

Example 1[edit | edit source]

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

Example 2[edit | edit source]

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[edit | edit source]

w:Mollusca w:Neomeniomorpha w:Caudofoveata w:Testaria w:Polyplacophora w:Conchifera w:Tryblidiida w:Ganglioneura w:Bivalvia w:Gastropoda w:Scaphopoda w:Cephalopoda
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[edit | edit source]

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[edit | edit source]

See RELEASE-NOTES.md.

Dependencies[edit | edit source]

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

The following extensions depend on the GraphViz extension:

See also[edit | edit source]

Language: English  • русский