Extension talk:GraphViz/v0.9

tags
I have installed GraphViz on a Debain server using apt.

I seem to have most/all of the executables installed and have put Graphviz.php in the extensions directory. Unfortunately it seems that MediaWiki is not interpreting the tags.

Is there a 'preferred' way to test the extension(s)?

I trust you also added include("extensions/Graphviz.php"); $wgGraphVizSettings->dotCommand = "$DOT_PATH/dot"; to your LocalSettings.php. After that you can test if it works with the code: digraph G{ A -> B } If you see a graph with a blob A connected with an arrow to a blob B then it works.

Some of my experiences: --Coriolan 05:37, 14 Jun 2005 (UTC)
 * 1) The current sources of Graphviz.php are in Wicle's CVS.
 * 2) When compiling the Graphviz from the sources I needed the --with-mylibgd to get dot generate .png files.
 * 3) The graphs seen in IslandSeeds look better because that engine runs on Mac (see } and its follow-up.

Windows
What's the point in this?

if (substr(php_uname, 0, 7) == "Windows") { $ext = "gif"; } else { $ext = "png"; }

.png is used everywhere else in the file, so this actually makes it break! I removed it and changed the $txt line to always use .png.

Also I found it necessary to use $ret = `"{$cmdline}"`; instead of        $ret = `{$cmdline}`; because the default windows install directory for Graphviz is "c:\Program Files\Graphviz..." which contains a space. Without the quotes, windows assumes everything following the space is a parameter, which generates only a "'c:\Program' is not recognized as an internal or external command, operable program or batch file." error.

Thanks for the extension, it looks like it could be very useful once I get the hang of it!

--ProgMania 23:20, 3 September 2005 (UTC)

safe_mode and antialiased rendering
please use popen instead of shell_exec, so that php safe_mode can work. not all of us want to run our servers as loose as a mexican whore.

i've also modified this plugin to use GraphicsMagick to render antialiased graphs from dot's svg output, it works very nice indeed. --207.109.251.117 11:26, 6 November 2005 (UTC)


 * Can you please provide the modified plugin? --202.1.193.10 17:45, 13 January 2006 (UTC)

Some Help Getting Graphviz to Work
I have an unusual set up as in I have a Uniform Server's WAMP ( Windows Apache MySQL PHP ) running from a Thumbdrive. Mediawiki ver 1.5. Graphviz.php extension installed The Graphviz is installed in the psedo drive W:\usr\local\ATT\Graphviz
 * The dot.exe is therefore W:\usr\local\ATT\Graphviz\bin

While adding in elements does have a Dos Prompt window pop-up momentarily, the resulting graph was never generated.

''Has anyone encountered this problem? And found a solution?'' Suggestions?

Deletion of unused images
Hi is it possible to delete all the unused pngs ? i got only 20 images with graphviz, but the creationprocess produced over 400 files...(testing and stuff :) ) Is it possible to delete those ? They mess up my box :-/

Size limit and work-arounds
I'm using the GraphViz extension w/ great delight (hoping to get my company's employees to document some of their formal business processes using the GraphViz extension on the company's MediaWiki-based wiki thing). However, I have been hitting an apparent size limit on the size of the graph you can specify using the GraphViz extension (go figure... there's a size limit on GET request lengths, after all).

So, for a simple work-around, I'm advising my users to split up their graphs into several subgraphs (only slightly nasty-looking, and there's probably some slick way to make it look almost like one connected graph).

For a more complicated work-around, I'm considering making a revised version of the tag(s) (e.g. &lt;dot_graph&gt;) that would "optimize" the graph code for reduced length (only on conversion into raw HTML), doing things like stripping out comments and renaming labeled nodes (to give them a super-short name while still allowing verbose node names in the original Wiki markup).

Just a thought. Nothing's really happening yet, and I thought it would be nice to at least warn people about the length limit (above). Mlibby 17:04, 22 December 2006 (UTC)


 * Maybe I'll include an approach like this, too: http://meta.wikimedia.org/wiki/User_talk:Cygon/Graphviz_Extension#Shorting%20the%20URLs Mlibby 17:14, 22 December 2006 (UTC)

Use with MW1.10
Has anyone been able to make any of the GraphViz extensions work with MediaWiki version 1.10? I have tried both this one and the one at http://www2.hds.utc.fr/~rherault/index.php/Graphviz_Extension, and neither works. Pages show up without content (completely white) as soon as I activate the extension in LocalSettings. Any advice would be gratefully accepted. 160.33.43.231 July 2nd, 2007, 12:00pm PDT

GRAFCET
Peut-on faire des GRAFCET avec ce type d'extension ?82.243.133.6 09:18, 1 August 2007 (UTC)

Improvement
Well, I decided that it might be a good thing to incorporate those issues seen above in a version that works out of the box AND does not require anything but "standard php" compared to those two alternate versions: Alternate Version and Updated alternate Version

This is an update ... for those who do not want to take/require the more complex version or do not have access to its required SPL module.

Known Issues
 * Well this plugin has a few issues with special characters in combination with "named naming". Just don't use them. This is true because Filesystem restrict other characters as URL's. Anyway that filename will only be used for referencing and is not displayed, so you don't have to worry if it is a workaround.

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:/Programme/ATT/Graphviz/bin/dot.exe'; } else { $wgGraphVizSettings->dotCommand = '/usr/local/bin/dot'; } $wgGraphVizSettings->named = 'named'; $wgGraphVizSettings->install = false;

// Media Wiki Plugin Stuff // --- $wgExtensionFunctions[] = "wfGraphVizExtension";

$wgExtensionCredits['parserhook'][] = array( 'name'=>'Graphviz',  'author'=>'CoffMan , MasterOfDesaster ',  'url'=> 'http://www.mediawiki.org/wiki/Extension:GraphViz',  'description'=>'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'=>'0.4', );

function wfGraphVizExtension { global $wgParser; $wgParser->setHook( "graphviz", "renderGraphviz" ); }

function renderGraphviz( $timelinesrc )	// Raw Script data {	global $wgUploadDirectory,	// Storage of the final png & map $wgUploadPath,			// HTML Reference $wgGraphVizSettings;	// Plugin Config

// Prepare Directories $dest = $wgUploadDirectory."/graphviz/"; if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }

$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);

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';

if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".png" ) || file_exists( $src.".err" ) ) ) {		$handle = fopen($src, "w"); fwrite($handle, $timelinesrc); fclose($handle);

$cmdline   = wfEscapeShellArg($wgGraphVizSettings->dotCommand). ' -Tpng  -o '.wfEscapeShellArg($imgn).' '.wfEscapeShellArg($src); $cmdlinemap = wfEscapeShellArg($wgGraphVizSettings->dotCommand). ' -Tcmapx -o '.wfEscapeShellArg($mapn).' '.wfEscapeShellArg($src);

$ret = shell_exec($cmdline); if ($wgGraphVizSettings->install && $ret == "" ) { echo ' Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdline.' '; exit; }

$ret = shell_exec($cmdlinemap); if ($wgGraphVizSettings->install && $ret == "" ) { echo ' Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdlinemap.' '; exit; }

unlink($src); }	@$err=file_get_contents( $src.".err" );

if ( $err != "" ) { $txt = ' '.$err.' '; } else { @$map = file_get_contents( $mapn ); $map = preg_replace('##',' ',$map); $map = str_replace(' ','',$map);

$txt = ''.$map.' '. '<img src="'.$wgUploadPath.'/graphviz/'.$storagename.'.png"'. ' usemap="#'.$storagename.'" />'; }	return $txt; } ?>

Fixed Special Char problem
Well here is a manual patch.

Make Named Files Umlaut-safe
Look for: function renderGraphviz( $timelinesrc )

Replace these lines: $storagename = urldecode($_GET['title']).'---'; $storagename = str_replace("&",'_amp_',$storagename); $storagename = str_replace("#",'_shrp_',$storagename); $storagename = str_replace("/",'_sd_',$storagename); $storagename = str_replace("\\",'_sd_',$storagename); With that line $storagename = str_replace("%",'_perc_',urlencode($_GET['title'])).'---';

Then replace this block: } else { $storagename .= trim(                       str_replace("\n",'', str_replace("\\",'/',                                       substr($timelinesrc, 0, strpos($timelinesrc,'{') )                                ) )               );        } With that one } else { // 'named' $storagename .= str_replace("%",'_perc_',			urlencode( trim(					str_replace("\n",'', str_replace("\\",'/',							substr($timelinesrc, 0, strpos($timelinesrc,'{'))						) )				)			)		);	}

A typo
There is also a type in the above listet file: if ( $wgGraphVizSettings->named == 'named' | ! ( file_exists( $src.".png" ) || file_exists( $src.".err" ) ) )

Should be that: if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".png" ) || file_exists( $src.".err" ) ) )


 * Fixed. (This appears to be not related to ) --Alvin-cs 12:19, 17 November 2007 (UTC)

On Updating
The update will work without noticing. Old (and unchanged) pages will stay the same and reference old images, a graph that is updated will automatically create a file in the new naming shema. If you worry about diskspace ... you can easily detect old files and new files.
 * Old files contain: _amp_, _shrp_, _sd_ instead of &, \ and /
 * New files: Replacing "_perc_" -> with "%" makes them valid urls.
 * Independent files: Usually don't have any of those things.


 * Had problem with ':' (COLON) in file names under windows. This happens when the article is not

in the default namespace. What about adding the following line: $storagename = str_replace(":",'_colon_',$storagename); around line 113? --195.206.74.130 13:08, 7 February 2008 (UTC)