Extension talk:GraphViz/v0.9

New "improved improved" version of the GraphViz-Extension
Dear Users of the GraphViz-Extension,

I am a student assistant at the FZI, a German research center. We're using the Graphviz-Extension(s) for some of our own projects.

Actually the problem is that it is not that easy to use a GraphViz Extension, because there are many different versions and improvements circulating around on mediawiki.org: some for windows and others for linux, some work out of the box and others don't, some support different renderers and others have automatic clean-up. I think you know what I mean.

So I'm currently combining the various GraphViz Extensions into one functional and up to date Extension. This means that I try to get the best out of each extension and I think that the result is a very good "improved improved" GraphViz-Extension.

My question is now if you'd mind if I was refreshing the Extension-Page (Extension:GraphViz) on MediaWiki as well. I'd like to clean up the old parts and the Discussion-Page so that there is space for some instructions.

If this is a problem, I will create another "Graphviz"-Extension, but I think that this would not help to get rid of the current chaos.

You can have a look at my current code and the corresponding page here: User:Hummel-riegel/GraphViz

Of course I'll try to name all the actual and previous contributors like the FDL/GPL-Licences specify. And as this is a wiki feel free to add some stuff if you want to.

Thanks for your response in advance, Yours sincerely

Thomas Hummel    --Hummel-riegel 13:28, 1 November 2010 (UTC)

Does this work on MW 1.12+?
If anyone has gotten this working on MW 1.12+, please post. I've tried nearly everything (the original Graphviz.php, the 'updated' one, and various combinations of the fixes supplied on this page) and MW1.13.2 never processes the element. I also tried the newest Graphviz 2.20, and the oldest one I could find (1.14). This is on windows. For paths I have tried backslash, two backslashes, and forward slash, as well as pointing at the Graphviz in Program Files or copying it to the wiki extensions directory. I'm inclined to believe this won't work on newer wikis.

Hi, i'm running graphviz under windows with MW 1.13.4. without problems. I use the latest graphviz extension and also the latest dot. --Ozz 09:50, 10 February 2009 (UTC)

I realized this was due to a change in how plugins are 'activated' in recent MW's. The documentation says 1.12+ but I found the old way worked on 1.12.0 but not 1.13.2. Here is my final working version for Windows (based off the updated plugin):

dotCommand *   Describes where your actual dot executable remains. * *    Windows Default: C:/Programme/ATT/Graphviz/bin/dot.exe *   Other Platform : /usr/local/bin/dot * *  $wgGraphVizSettings->named *   Describes the way graph-files are named. * *    named: name of your graph and its type determine its filename *   md5  : name of your graph is based on a md5 hash of its source. *   sha1 : name of your graph is based on a SHA1 hash of its source. * *    Default : named * *  $wgGraphVizSettings->install *   Gets you an errormessage if something fails, but maybe ruins your *   wiki's look. This message is in English, always. * *    Default : false * * Improvements * - Selects defaults for Windows or Unix-like automatically. * - should runs out of the box * - Creates PNG + MAP File * - additional storage modes (see discussion below) *  - Meaningful filename *  - Hash based filename *  - Configurable (name/md5/sha1) * * Storage Modes: * MD5: * + don't worry about graphnames * + pretty fast hash * - permanent cleanup necesary (manually or scripted) * - md5 is buggy - possibility that 2 graphs have the same hash but *  are not the same * SHA1: * + don't worry about graphnames * + no hash-bug as md5 * - permanent cleanup necessary (manually or scripted) * - not so fast as md5 * Named: * + Graphs have a name, now it's used * + no permanent cleanup necessary. * - Naming Conflicts *  a) if you have multiple graphs of the same name in the same  *      article, you will only get 1 picture - independently if they're  *            the same or not.  *   b) possible naming conflicts in obscure cases (that should not happen) *     Read code for possibilities / exploits *  */ class GraphVizSettings { public $dotCommand, $named, $install; }; $wgGraphVizSettings = new GraphVizSettings; // Config // -- if ( ! (stristr (PHP_OS, 'WIN' ) === FALSE) ) { $wgGraphVizSettings->dotCommand = 'C:/Program Files/Graphviz2.20/bin/dot'; } else { $wgGraphVizSettings->dotCommand = '/usr/local/bin/dot'; } $wgGraphVizSettings->named = 'named'; $wgGraphVizSettings->install = false; // Media Wiki Plugin Stuff // --- //$wgExtensionFunctions[] = "wfGraphVizExtension"; if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'wfGraphVizExtension'; } else { // Otherwise do things the old fashioned way $wgExtensionFunctions[] = 'wfGraphVizExtension'; } $wgExtensionCredits['parserhook'][] = array(  'name'=&gt;'Graphviz',   'author'=&gt;'CoffMan &lt;http://wickle.com&gt;, MasterOfDesaster &lt;mailto://arno.venner@gmail.com&gt;',   'url'=&gt; 'http://www.mediawiki.org/wiki/Extension:GraphViz',   'description'=&gt;'Graphviz (http://www.graphviz.org) is a program/language that allows the creation of numerous types of graphs.  This extension allows the embedding of graphviz markup in MediaWiki pages and generates inline images to display.',   'version'=&gt;'0.4' ); function wfGraphVizExtension { global $wgParser; $wgParser->setHook( "graphviz", "renderGraphviz" ); return true; } function renderGraphviz( $timelinesrc, $params, &$parser )     // Raw Script data {      global $wgUploadDirectory,     // Storage of the final png & map $wgUploadPath,                 // HTML Reference $wgGraphVizSettings;     // Plugin Config $parser->disableCache; $output = ""; //$output = "&lt;pre&gt;Called render&lt;/pre&gt;"; // Prepare Directories $dest = $wgUploadDirectory."/graphviz/"; if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); } $output .= "&lt;pre&gt;Dir=$dest&lt;/pre&gt;"; $storagename = urldecode($_GET['title']).'---'; $storagename = str_replace("&",'_amp_',$storagename); $storagename = str_replace("#",'_shrp_',$storagename); $storagename = str_replace("/",'_sd_',$storagename); $storagename = str_replace("\\",'_sd_',$storagename); $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named); $output .= "&lt;pre&gt;dotCommand=".$wgGraphVizSettings->dotCommand ."&lt;/pre&gt;"; $output .= "&lt;pre&gt;named=".$wgGraphVizSettings->named ."&lt;/pre&gt;"; if($wgGraphVizSettings->named == 'md5') { $storagename .= md5($timelinesrc); } else if ($wgGraphVizSettings->named == 'sha1') { $storagename .= sha1($timelinesrc); } else { $storagename .= trim(                  str_replace("\n",'', str_replace("\\",'/',                              substr($timelinesrc, 0, strpos($timelinesrc,'{') ))      )); }      $src = $dest. $storagename; $imgn = $dest. $storagename. '.png'; $mapn = $dest. $storagename. '.map'; $output .= "&lt;pre&gt;Src=$src&lt;/pre&gt;"; if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".png" ) || file_exists($src.".err"))) {            $handle = fopen($src, "w"); $ret2 = fwrite($handle, $timelinesrc); $ret3=fclose($handle); $output.="&lt;pre&gt;Opened and closed $src, handle=$handle, timeelinesrc=$timelinesrc, ret2=$ret2, ret3=$ret3&lt;/pre&gt;"; $cmdline   = wfEscapeShellArg($wgGraphVizSettings->dotCommand).' -Tpng   -o '.wfEscapeShellArg($imgn).' '.wfEscapeShellArg($src); $cmdlinemap = wfEscapeShellArg($wgGraphVizSettings->dotCommand).' -Tcmapx -o '.wfEscapeShellArg($mapn).' '.wfEscapeShellArg($src); //$ret = shell_exec($cmdline); $WshShell = new COM("WScript.Shell"); $WshShell->Exec($cmdline); $WshShell->Exec($cmdlinemap); $output.="&lt;pre&gt;Ran cmd line. ret=$ret cmd=$cmdline&lt;/pre&gt;"; if ($wgGraphVizSettings->install && $ret == "" ) { //echo '&lt;div id="toc"&gt;&lt;tt&gt;Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdline.'&lt;/tt&gt;&lt;/div&gt;'; $output.= '&lt;div id="toc"&gt;&lt;tt&gt;Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdline.'&lt;/tt&gt;&lt;/div&gt;'; exit; }            //$ret = shell_exec($cmdlinemap); if ($wgGraphVizSettings->install && $ret == "" ) { echo '&lt;div id="toc"&gt;&lt;tt&gt;Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdlinemap.'&lt;/tt&gt;&lt;/div&gt;'; exit; }            //unlink($src); }      @$err=file_get_contents( $src.".err" ); if ( $err != "" ) { $txt = '&lt;div id="toc"&gt;&lt;tt&gt;'.$err.'&lt;/tt&gt;&lt;/div&gt;'; } else { @$map = file_get_contents( $mapn ); $map = preg_replace('#&lt;ma(.*)&gt;#',' ',$map); $map = str_replace('&lt;/map&gt;','',$map); $txt = '&lt;map name="'.$storagename.'"&gt;'.$map.'&lt;/map&gt;'. '&lt;img src="'.$wgUploadPath.'/graphviz/'.$storagename.'.png"'. ' usemap="#'.$storagename.'" /&gt;'; }      $txt .= $output;//"&lt;pre&gt;MOOOO&lt;/pre&gt;"; return $txt; } ?>

Fix for Darwin
auto-detection fails for Darwin (because it matches "WIN"). Fix:

if ( stristr(PHP_OS, 'WIN' ) && !stristr(PHP_OS, 'Darwin') ) { $wgGraphVizSettings->dotCommand = 'C:/Programme/ATT/Graphviz/bin/dot.exe'; } else { $wgGraphVizSettings->dotCommand = '/usr/local/bin/dot'; }

Problems with mediawiki 1.16 (ubuntu 8.10) - dot command not found
I'm currently using the svn version of mediawiki, which is currently at 1.16. Although I have correctly set the location of dot,I keep getting the error:

Solution: This problem arises only when you set the because it gives and error when dot output is an empty string "", which is exactly the case of a succesful execution. To fix this we must look at the dot command return value rather than its stdout/stderr output.

--Drunken sapo 14:26, 22 June 2009 (UTC)

Do away with serverfiles
I have img_auth.php installed on the wiki, hence could not use this extension directly. Don't really want to touch permissions, so I did as suggested here and embedded the graphviz output inside the response html. Just threw together some code to verify this (missing all the error handling and what not, but works fine on sample graphs); feel free to reuse whatever you see fit as I am definitely still missing much functionality. --Vopap 03:56, 23 September 2009 (UTC)

Display Examples
I tried to display the example graphics that get produced by the examples on this page, but it seemed to just display the text even though I took it out of the 'code' tag. Any reason this would happen? Daviddoria 18:05, 1 November 2009 (UTC)

Bug in extreme fast redrawings
In case of redrawing the same graphic very fastly, the new graphviz call gets stuck. In the process list, the CMD and graphviz call does not get cleaned, because the created file is locked by the previous call.

A work around is to unlink the bare file ($fname) and the $fname.map before opening the handle to $fname: if (file_exists($fname)) unlink($fname); if (file_exists($fname.'.map')) unlink($fname.'.map');

This should solve the issue, but it needs to be tested thoroughly.

Custom Shapes
Is there any trick to getting a custom shape (image) rendered in the graphs? I have uploaded a "stick figure" image to my mediawiki, and can see it if I include the markup in page bodies, but it is not rendered when I include that markup in my graphviz code --srl100 11:18, 14 April 2010 (UTC)

e.g.

graph G { subgraph clusterMain { subgraph clusterActor1 { color=white; label="actor1"; actor1 ; }       system [shape=circle]; actor1 -- system; } }

Update 15 April 2010, by srl100...

It turns out that I needed to include the relative path to the image, in the (hashed) images directory structure.

graph G { subgraph clusterMain { subgraph clusterActor1 { color=white; label="actor1"; actor1 [image="images/a/aa/Stick.png" shape=none label=""]; }       system [shape=circle]; actor1 -- system; } }


 * I think you have to hack this feature into the extension by yourself. Perhaps this can help you on the way: --Danwe 21:39, 16 April 2010 (UTC)

Category pages and graphviz
The extension cannot work on category pages unless you include the following at line 117:

... $storagename = str_replace("\\",'_sd_',$storagename); $storagename = str_replace(":",'_colon_',$storagename); #<-- added... $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named); ...

Text inside nodes is pruned
In the Hello World example (and in other examples too), the text inside the nodes is pruned at the bottom.

I assume it is a problem in GraphViz, but I wonder if anyone has found a workaround?

Yeah I'm having this problem too. Using underscores to get round it atm, but it's not ideal

Install Instructions - path to graphviz
Using MediaWiki v1.16.2 I got an error while following Installation instructions. I changed line (LocalSettings.php) to include("$IP/extensions/Graphviz/Graphviz.php");

Also. I was using Ubuntu 10.10 with lampp and pictures in graphviz folder was 0 bytes size. To solve this problem:

What version of MediaWiki is required?
Hi, what version(s) of MediaWiki is required for this extension? I saw the reference to "The documentation says 1.12+" but can't see any documentation. We are currently on 1.5.3, I'm guessing that is too old?

bugs and filenames
Hi! I'm Extension:Collaboration Diagram developer, I really impressed by the description of new Graphviz extension and tried to update. However here are some problems that took place on my Debian:
 * 1) By default the extension does nothing except displaying the message: string(5) . It's caused by the line 293 in the source code.
 * 2) After fixing that I started to get error messages about too long filenames. The extension uses strange method of naming when  - it generates filenames like PAGENAME---GRAPHNAME and replaces all '%' to _perc_ . Sure thing it provoked errors on my Russian wiki, where all letters are replaced to codes after calling urlencode function.
 * 3) If I set $wgGraphVizSettings->named = 'md5'; I get filenames like PAGENAME---md5(GRAPHNAME)

Idea: why not hashing with md5 or sha1 both PAGENAME and GRAPHNAME? And probably it would be better to set $wgGraphVizSettings->named = 'md5' by default because otherwise it will cause problems on non-English wikis. --Katkov Yury 19:29, 7 June 2011 (UTC)

jeroendedauw has put this into svn. Thanks! (r89857 -Diff) --Hummel-riegel 12:00, 11 June 2011 (UTC)

Problems with SVG
It doesn't seem that SVG output format work. after settings up the following: $wgGraphVizSettings->outputType = "svg"; $wgGraphVizSettings->info = true; $wgAllowTitlesInSVG = true; $wgSVGConverter = 'ImageMagick'; $wgFileExtensions[] = 'svg'; $wgAllowExternalImages = true; I'm still not able to see the pictures of my graphs, although they have being generated by the extension. Any other SVG files that I upload to the wiki displayed correctly because ImageMagick generates thumbnails for them.

So for commonly uploaded SVGs on a page the following html is produced:

However graphviz extension generates for svg filetype the same code as for other fileformats: x

In Manual:Image_Administration they say that it's forbidden to include svg images directly in a wikipage, so that was the source of the bug.

UPDATE

I have fixed it by generating pngs with SvgHandler class and now with the help of Hokstad I can draw graphs like that



Where can I send the patches with that? I think it could be really handy.

--Katkov Yury 20:20, 7 June 2011 (UTC)

If you don't want to put it in svn yourself (or have no access like me ;-)) the best way would be to fill a bug on https://bugzilla.wikimedia.org/enter_bug.cgi?product=MediaWiki%20extensions.

--Hummel-riegel 11:58, 11 June 2011 (UTC)

Problem with Font / Charset
Hi, I have a problem with Graphviz on my wiki. The dot command is found and I can create Graphs, but instead of letters I only see rectangles. Here is a picture of what my graph looks like: http://tinypic.com/r/w8vlhi/7 (Uploadet 20.07.2011)

I hope someone can give my some hints of how to fix this :D

Thanks

Niklas

Automatically adding Wiki links
I am generating graphs representing sutuctures in my Wiki using Extension:DPL to generate a set of GraphViz dot commands. I am including the generation of the Graphviz commands to add URLs to each node so I can link back to the original pages in the Wiki. However this is a tedious process. I would like Extension:GraphViz to do this for me, i.e. scan the input commands before writing them out to a file and replace Foo -> Bar with Foo -> Bar Foo [URL=”Foo”] Bar [URL=”Bar”]

Is there any interest in this? --Teskeyn 15:10, 26 July 2011 (UTC)
 * Hi, I think this is an interesting idea. At the moment I don't have any time to do work here, but as everybody could submit a patch, someone could do this.

In my opinion a good and easy solution would be a parameter, to activate or deactivate the replacement process. Not everybody wants to have the Nodes linked to the pages. A more complex solution would be checking if the name of the page exists. But I'm not sure if this is necessary. --Hummel-riegel 16:24, 26 July 2011 (UTC)
 * Teskeyn, I would very much love to know how you got DPL and GraphViz to play nice with each other - somehow I cannot get DPL output to be rendered correctly by GraphViz other than C&P it into the source code myself :/ I'd appreciate any hint!

As for your replacement: Why don't you just generate the missing lines for the URL parameter like this?

--Dnowak 16:24, 20 Sep 2011 CET

failed to open stream: No such file or directory
Hey all, I have just installed graphviz and this extension, but kept seeing the following error message when I tried to put an example graph in my Sandbox:

Warning: file_get_contents(/path/to/wiki/images/graphviz/Sandbox---digraph+example.map): failed to open stream: No such file or directory in /path/to/wiki/extensions/GraphViz/GraphViz.php on line 420

The reason here was, the path to my Graphviz installation was wrong (I put /usr/bin/dot/ but correct was /usr/bin/ ). After changing this, the error dissappered. --Kebap 16:39, 6 September 2011 (UTC)

Why don't we keep pruning simple?
I think all the different ways of storing the generated graph image files are a huge overkill.

Why don't you just use a modified 'named' method. Name each file with the article name and a count or if you must, the graph name and a count. This means if you have several graphs with the same name on one page (which is quite likely if you use templates to generate graphs), you just add a incremented number to the name.

Now we only have to take care of orphaned files, not needed anymore. Preventing that, we just get all files prefixed with the current article name and delete them when the page has been edited/purged (graph re-rendering) or moved/deleted. Of course we can add a caching mechanism, save the graph source with the image and check before rendering again whether the new source is equal to the new source, in that case we don't do anything. Special case would be if the number of graphs with same name changes on a page, in this case the easiest would be to prune all graphs with that name of that page.

Am I missing anything here, wouldn't it be that simple really? --Danwe 09:26, 26 September 2011 (UTC)

Maintainers?
Is this extension still being maintained? It appears that it could be very useful, especially when combined with Extension:Semantic Result Formats. Badon 06:33, 26 November 2011 (UTC)


 * Jeroen has maintained it for some time but he has no big plans about developing this extension. I have a project Extension:CollaborationDiagram that uses GraphViz, so I will probably occasionally contribute something here (like SVG support, shadows and gradients). I think without funding or really huge graphviz fans this extension will remain frozen. Katkov Yury 22:21, 28 November 2011 (UTC)


 * I am using GraphViz extension extensively in my wiki, having templates generating huge graphs with SMW, Loops and Variables extensions. I have already fixed some things but didn't release them yet. I am thinking about re-writing the whole thing, solving the image caching issue and prettifying the extension design. Can't say when that's going to happen right now since I am rather busy with other extensions at the moment. --Danwe 17:00, 29 November 2011 (UTC)

Running graphviz on web host
Hello, I'm trying to figure out how to properly install & use Graphviz. My wiki is installed a web host, which is running PEAR module Image_GraphViz 1.1.0 stable. In that case, where would the dot binary typically be for $wgGraphVizSettings->execPath? I'm at a loss as to how to properly configure this.Patelmm79 22:07, 20 January 2012 (UTC)

same here
Hello, I seem to have the same problem as the User before. My Mediawiki is installed on an external server, I manage the files via ftp. I followed the installation instruction and noticed that the extension was probably made for installation on local PC or workstation. The installation path of GraphViz extension ist clear, I can add that. But when it comes to the installation execution path of graphviz it makes no sense to store "C:\xxx". Is it possible to run graphviz-extension on a webhost? Any help would be great, thanks, Jessy

Long filename with non-English letters
Patch Fix it:

This works for me --Pastakhov (talk) 08:16, 20 June 2012 (UTC)

Shape shorthand
I made some changes to our implementation to support a shorthand/alias for shapes. The implementation is not very robust in that it relies on a basic find and replace but works out pretty well.

The "type=" shorthand syntax will get replaced with the expanded definition and can look like this:

Add this line:

Right after the rewriteWikiUrls line like so:

Add the following method to the end of the GraphViz.php file. Of course, change the $search and $replace pairs as necessary to support the style that you are trying to achieve. In this case, we were trying to mimic an existing style and nomenclature.

Possible enhancements: The $search and $replace pairs could be brought out to LocalSettings.php and modified there instead of having to modify the source.

Mattsmith321 (talk) 15:53, 1 September 2012 (UTC)

Registering and listing pagelinks
I made some changes to the extension to support listing the links below the diagram and registering the links with wiki. I originally worked through the issues at MediaWiki + Graphviz + Image maps + Pagelinks but I will now provide ongoing updates/fixes here.

Note that my solution doesn't fully support all of the capabilities of the current GraphViz extension as there is functionality we do not need and I do not want to support. Here are the assumptions / limitations of this solution:
 * Does not support MscGen: We only have a need for Graphviz.
 * Does not support imageAtrributes: We wanted to control the format and presentation and it seemed like there were inconsistencies in the imageAttributes implementation that would then cause further support issues.
 * Does not support wikilinks: While it would be nice to provide consistent link usage through wiki and the Graphviz extension, the reality is that Graphviz is a completely different markup environment. While the current extension 'supports' wikilinks, the implementation is a little weak and leaves areas for confusion. Example: Wikilinks support giving the link an optional description but Graphviz already uses the node label for the description. So then you end up ignoring the wikilink description and telling users that 'Yes, we support wikilinks but don't use the description part' So since we aren't really using wikilinks correctly, just implement a regular link implementation and try to avoid the confusion entirely.

Here is what the output looks like:



Here are the changes that were made

Comment out this line:

Replace this block of code:

With this code (note that the str_replace of the xml tag in the code below is what is causing the syntaxhighlight tag to not highlight as expected): ';

Mattsmith321 (talk) 15:17, 1 September 2012 (UTC)

No dot executable found
I would like to install this extension to my mediawiki which is on my computer. However, when I installed the GraphViz into my computer, my wiki could not found the dot.exe Is it because of this line? any help is appreciated, thank you.

--Shinghinyeung (talk) 12:48, 11 September 2012 (UTC)

Fatal error
Fatal error: Class 'COM' not found in C:\wiki2\extensions\Graphviz\GraphViz.php on line 377

It was working fine when the server (XAMPP) was running on a Windows XP system, but I've moved it to a Windows 7 system and now this error pops up. --Korby (talk) 12:07, 18 October 2012 (UTC)


 * You need dot-net in php.ini
 * I had the same issue. It worked fine on one machine and it didn't work on another.
 * You must install vcredist_x86 from Microsoft as suggested by the xampp-installer.
 * Then you have to add extension=php_com_dotnet.dll to your php.ini

--Mosero (talk) 19:25, 20 February 2013 (UTC)

Cannot find the file specified
If you get the error:

Unexpected non-MediaWiki exception encountered, of type "com_exception" exception 'com_exception' with message 'Source: WshShell.Exec Description: The system cannot find the file specified. ' in C:\wamp\www\wiki\extensions\GraphViz\GraphViz.php:378

Chances are you are missing the final slash at the end of your $wgGraphVizSettings->execPath in LocalSettings.php. —The preceding unsigned comment was added by Mykro (talk • contribs) 07:10, 1 March 2013‎

save as pdf
if I print as PDF the graph disappear. how to generate it also in pdf ?

thanks —The preceding unsigned comment was added by 178.250.203.114 (talk • contribs) 12:56, 30 April 2013‎

== Bug 54221: Support for text/syntax/markup driven or WYSIWYG editable charts, diagrams, graphs, flowcharts etc. (Identify, develop, review and deploy extension on Wikimedia wikis to add) ==

FYI. --Nemo 12:19, 17 September 2013 (UTC)