Extension talk:Gnuplot/From Meta

Font
This is a great extension!

Is it possible to modify the font of the diagram? I tried

set terminal windows transparent 'arial' 10

But there is no effect.

--Lbirn 14:45, 19 January 2006 (UTC)

A general comment: all settings that work for your local gnuplot installation should work for this wiki extension as well.

For tracing this, you could uncomment the line // some cleanup unlink($fname); in Gnuplot.php and try to execute the content of that file in Gnuplot (since this temporary file contains the source code for gnuplot). Check if your settings take effect in a 'normal' execution in gnuplot.

--Ecapessa 10:44, 23 January 2006 (UTC)

No output
after including code according to Installation I can't run. Could someone tell me, what I have to do furthermore?! Testing gnuplot is successful under console!

Possible Solutions
There are a couple of reasons for this - the commonest is that the path to the images directory is not owned by the web server user or does not have permission to access a component of the path. Go through the whole path and make sure the permissions on directories are at least 755. The images directory should be owned by the webserver user.

There is another more complex issue I came across - gnuplot does not have the necessary access under the web server user to access the shared libraries. To see if this is the case, use the diagnotsic output change bellow and look for missing shared library error messages. Fixing this usually requires a root admin to fix the permissions of the library or directoy

"budgetSample.txt" Missing
Missing by design or by accident? It's be nice to see it.

As META-WIKI does not support the upload of files with extensions such as .txt, I have directly inserted the source data for the plot.

--Ecapessa 08:50, 3 February 2006 (UTC)

Troubleshooting
My webserver is on another platform (Linux) than my local test server (Win). I uploaded a Linux binary file to the web server, but it doesn't seem that the GNUplot binary on the remote produces any output. How do I test if the binary is actually working? (The error may be because of my path settings)

--Haraldgroven 15 February 2006

Display gnuplot diagnostic output
Instead of digging through a log file on the server, I wanted to be able to see the gnuplot diagnostics output. I made some minor tweaks to the code by combining stdout & stderr, capturing the output, then displaying it (if there is any output): $cmdlinePlot = wfEscapeShellArg($wgGnuplotCommand) . ' ' . wfEscapeShellArg( $fname ). ' 2>&1';		$shelloutput=shell_exec($cmdlinePlot); if (strlen($shelloutput) > 0) { $shellerror=" command-line: $cmdlinePlot " ."ERROR message: $shelloutput<"."/pre>"; }		else $shellerror="";

// some cleanup unlink($fname); }

return '  '. "$shellerror";

I'd add this directly to the listed code, but I don't want to break stuff for others if the stderr+stdout (2>&1) statement is wrong for some folks.

-- Mark Foster (Fosterm) 3 May 2006

Great Extension - but
I hate things like: `echo plot f\(fx\)` or the possibility to use "system" or "shell".

I suggest to use: $replaces = array("`" => "", "system" => "", "shell" => ""); $gnuplotsrc = strtr($gnuplotsrc, $replaces);

Please comment!

Thank you for the comment! It is a simple but very effective fix. I have adapted the code on the content page. A future cleaner version may replace the whole shell/system command (not only the keyword), but still allow the words shell and system as labels in the plot.

--Ecapessa 09:43, 30 June 2006 (UTC)

Filenames instead of filepaths.
I was using mediawiki to create performance reports and wanted a way to dynamically generate graphs. Gnuplot worked great for this however I noticed one issue. If I uploaded a tab seperated data file and wanted to reference it from gnuplot I had to specify the filesystem path which is dynamically generated (path is generated from a hash) when uploading. This is a pain so I modified the code to allow me to specifiy the filename and have gnuplot dynamically fill in the proper path when it generates the graph.

Sample code before, set output 'budgetExample.png' set xlabel "Month of 2004" set ylabel "Amount [Euro]" plot 'images/0/00/budgetSample_gpl.txt' using 1:2 title 'planned',\ 'images/0/00/budgetSample_gpl.txt' using 1:3 title 'interpolated',\ 'images/0/00/budgetSample_gpl.txt' using 1:4 title 'spent'

Sample code after, set output 'budgetExample.png' set xlabel "Month of 2004" set ylabel "Amount [Euro]" plot 'images/0/00/budgetSample_gpl.txt' using 1:2 title 'planned',\ 'src:budgetSample_gpl.txt' using 1:3 title 'interpolated',\ 'src:budgetSample_gpl.txt' using 1:4 title 'spent' The "src:" tag tells the gnuplot plugin to go looking for the real filesystem path of the specified file. There may have beed a better way to implement this but it works.

Simply modify gnoplot.php to include the following function, function getSourceDataPath ($name) { $h = Image::newFromName($name);

if (!$h->exists) return null; else return $h->getImagePath; } 'AND' modify the function renderGnuplot to look like this. function renderGnuplot( $gnuplotsrc ) { global $wgGnuplotSettings, $wgUploadDirectory, $wgUploadPath; // create directory for storing the plot $gnuplotDir = "/gnuplot/"; $dest = $wgUploadDirectory. $gnuplotDir; if (!is_dir($dest)) { mkdir($dest, 0777); chmod($dest, 0777); }   // get the name of the graph to be produced $name = getOutputName ($gnuplotsrc); $graphname = $dest. $name; $fname = $graphname. ".tmp";

// write the default settings and the input code from wiki into a    // temporary file to be executed by gnuplot, then execute the command if ( ! (file_exists($fname) || file_exists($fname . '.err'))) { $handle = fopen($fname, 'w'); // if terminal and size are not set in the gnuplot source we do it here if (strpos($gnuplotsrc, 'set terminal ') === false) { fwrite($handle, $wgGnuplotSettings->defaultTerminal . "\n"); }       if (strpos($gnuplotsrc, 'set size ') === false) { fwrite($handle, $wgGnuplotSettings->defaultSize . "\n"); }       while (strpos($gnuplotsrc, 'src:') != false) { // Need to find each occurance of src: and replace it with the Complete file path // The file name from the gnuplotsrc $srcStartPosition = strpos ($gnuplotsrc, 'src:') + strlen("src:"); $srcEndPosition = strpos ($gnuplotsrc, ' ', $srcStartPosition); $tmpString = substr($gnuplotsrc, $srcStartPosition, $srcEndPosition-$srcStartPosition-1); $srcFileNamePath = getSourceDataPath($tmpString); $gnuplotsrc = str_replace("src:$tmpString",$srcFileNamePath,$gnuplotsrc); }       fwrite($handle, "\nset output '" . $graphname . "'\n"); // Remove the 'set output' command from the source as we will set it. $gnuplotsrc = deleteOutputLine($gnuplotsrc);

fwrite($handle, $gnuplotsrc . "\n"); fclose($handle);

$cmdlinePlot = wfEscapeShellArg($wgGnuplotSettings->gnuplotCommand) . ' ' . $fname; $output = shell_exec($cmdlinePlot);

// some cleanup unlink($fname); }

return "  " ; } Note: Even if you upload a new data file with the same name you still have to click "edit" and "save page" to produce a new graph. Since gnuplot seems to only get called on edits and not everytime a page is loaded.

Thanks a lot for uploading your code on the discussion page - very convenient. I have adapted the code on the content page as well as in my wiki according to your implementation!

--Ecapessa 09:18, 30 June 2006 (UTC)

Only use this on a VERY trusted network
This extension will open your system up for serious abuse. Gnuplot allows you to specify any input file, and allows users to use system and shell commands. You are looking for trouble using this anywhere unless you trust your users very, very much.

See section Great Extension - but and my comment. --Ecapessa 09:48, 30 June 2006 (UTC)

Gnuplot.cgi file
Has anyone seen a copy of the Gnuplot.cgi file floating around? I have limited options on my shared webhosting, and it appears that command line interface programs do not work for my Mediawiki. Cgi programs work fine because I point to them from the web (see example: Mimetex). --Dwees 16:19, 14 July 2006 (UTC)

Cleanup of old images?
Every time you modify the gnuplot data it creates another PNG file -- even zero-length files on syntax errors -- and they accumulate. It would great if the extension would clean up old and zero-length images.

I know you can specify an image file name, but this doesn't help if you are feeding data to gnuplot from another source (say, the results of a SQL query) and no filename is available.

--Maiden taiwan 17:44, 25 September 2007 (UTC)

Can't find the gnuplot window
On Windows 2003 Server, this extension produces the following message repeatedly in the Apache logs:

Can't find the gnuplot window

What does this mean? I'm getting hanging pgnuplot.exe processes regularly.

-- User:maiden_taiwan

Mac OS X installation/path?
In the path example, it was "C:\\Program files\\xampp\\gnuplot\\bin\\pgnuplot.exe" for Windows. Does anyone know what it is for Mac OS X? -- Kirjapan 08:13, 17 October 2007 (UTC)

"set ouput" not being correctly replaced
I see this line: $gnuplotsrc = preg_replace( '/^set output.*$/m', '', $gnuplotsrc ); However, this means that if I have indentation before "set ouput", then it does not get replaced.

I suggest updating this to '/^\s*set\s+output.*$/m'

--CrazyTerabyte 02:24, 13 August 2008 (UTC)

Gnuplot and Rss
Once the Gnuplot extension is installed, que RSS feed of the wiki are not functioning.

any idea how to work this out??

thanks    --150.214.36.10 16:35, 29 September 2008 (UTC)

Path incorrect?
82.195.46.94 16:16, 4 February 2009 (UTC) For some strange reason, I keep getting the following error:

command-line:"C:\gnuplot\bin\pgnuplot.exe" "C:\wamp\www/images/gnuplot/func_approx.png.tmp" 2>&1 ERROR message:The filename, directory name, or volume label syntax is incorrect.

The paths are correct, and so are the rights on the directories... what am I doing wrong? regards, Chill

Security
It this extension safe for production use on a public wiki? 83.68.75.19 00:07, 10 April 2009 (UTC)
 * No, it is not at all. 83.68.75.19 00:14, 10 April 2009 (UTC)