Extension:PChart4mw

Purpose
This PHP Chart for MediaWiki extension (pchart4mw) allows you to visualize your data with charts like line-, bar-, pie-, radar-, scatter- and bubble charts. It uses the (free) PHP Chart library pChart to produce the charts. It allows for 2- or 3-dimensional charts, which are all within the potential of the pChart library. The charts are based on your data from the wiki page.

pchart4mw works, together with the pChart library, fully within your MediaWiki Server environment. The data is processed completely within the server environment.

Use
pchart4mw has a unique tag or function for each chart type it supports. It can be used with its tags or with its parser functions.

The tag method is the traditional way of adding extra functionality to MediaWiki. The parser function method is added to pChart4mw as of version 1.1. Use the parser function method to integrate pchart4mw's charting capabilities with other MediaWiki functions or extensions.

Sample charts
Here are some simple samples of what you can do with pChart for MediaWiki:

Installation and configuration
Got you interested in these samples? Its installation is very straight forward. Here's how to do it:

Installation

 * Install the pChart library
 * The first thing you need is a copy of the pChart library. Download the latest version from the pChart website . Follow the instructions for pChart installation. The location where pChart is installed must be specified later on in LocalSettings.php. Remember this location. Check the system requirements for the pChart library, your PHP installation needs to have GD library with freetype extension enabled.
 * Possible locations for the pChart library are, for example:
 * Option 1: pChart library installed in [documentroot]/pChart/pChart.class
 * Option 2: pChart library installed in $IP/extensions/pChart4mw/pChart/pChart.class (sub-directory of pchart4mw extension)


 * Install this extension
 * Download the pchart4mw extension from the pchart4mw site and save in the directory


 * $IP/extensions/pChart4mw

Configuration
To configure this extension, several parameters need to be set. A few options are needed for the extension to function properly. Other settings are optional:


 * Tell MediaWiki about this extension
 * Add the following line to the file LocalSettings.php
 * require_once( "$IP/extensions/pChart4mw/pChart4mw.php" );


 * Set pChart library location
 * Defines the location where the pChart library is installed. The variable $wgPChart4mwPChartPath contains the absolute path to the directory where the pChart class resides. Add the following line to LocalSettings.php


 * Option 1: pChart library installed in [documentroot]/pchart/pChart.class
 * $wgPChart4mwPChartPath = $_SERVER["DOCUMENT_ROOT"] . "/pChart";
 * Option 2: pChart library installed in $IP/extensions/pChart4mw/pChart/pChart.class (sub-folder of pchart4mw extension)
 * $wgPChart4mwPChartPath = $_SERVER["DOCUMENT_ROOT"] . "/wiki/extensions/pChart4mw/pChart";


 * Set pChart font location (optional)
 * Determines the truetype font file to write text into the graph. This variable contains the absolute path to the .ttf file. The pChart installation contains some font files by default in the Fonts subdirectory. Add the following line to LocalSettings.php:
 * $wgPChart4mwFont = $wgPChart4mwPChartPath . "/Fonts/tahoma.ttf";
 * to use the tahoma.ttf font from the Fonts subdirectory in the pChart directory.


 * Set cache directory (optional)
 * Directory where the created images are saved. The images are saved to this directory when created, and the saved file is loaded on the page where it should be shown. When the cache is enabled, the file is created only once, saving a lot of processing time when a page is loaded frequently. If anything in the chart code is changed, a new file is created. When the cache is disabled, the file is created again every time a page is loaded.
 * The directory must be specified as a subdirectory of the $wgUploadPath</tt> directory. The directory must exist and be writable. By default, the cache directory is $wgUploadPath/pChart4mw</tt> ([wiki]/images/pChart4mw</tt>).
 * Add the following line to LocalSettings.php
 * $wgPChart4mwCacheDir = "pChart4mw";


 * More optional settings
 * For more (optional) configuration options and default settings visit the pchart4mw project site.

How does pchart4mw work?
As a wiki author you create a chart definition within a wiki page. To do this you type simple chart syntax plus the data to be displayed in the chart. pchart4mw processes your chart definition and uses the pChart library to create a chart image. Browsing the wiki page you get your chart image displayed.

Figure 1 gives a simplified overview of the working of pchart4mw. In more detail:
 * A pchart4mw call is initiated from a wiki page written in wiki markup. A call starts with the  <pChartType> </tt> start tag or  {{#pChartType: </tt> function for the graph of your choice. pchart4mw receives a call every time a wiki page with a pchat4mw tag or function is viewed by a user
 * pchart4mw receives the full text from the call between start end end tag
 * From this full text the unique graph image filename is determined (e.g. )
 * pchart4mw processes the chart definition and the data
 * pchart4mw uses the pChart Library to create an image of the chart
 * pchart4mw uses a cache folder, (default images/pchart4mw</tt>), to store the image file.
 * If the graph image already exists in the cache folder, pchart4mw doesn't create it again. If it doesn't exist pchart4mw creates it.
 * The graph image (e.g. ) is then shown on the page.

Maintenance of your site
As described in 'how does pchart4mw work', pchart4mw stores chart images in the cache folder (default ). The filenames of these images are automatically generated based on the full content of the pchart4mw call. This means that every time the content of a call changes the filename of the created image also changes.

A filename is for example:

The consequence is that over time the cache folder becomes populated with unused (orphan) graph images. Periodically the wiki site administrator should do some cleanup in this folder. It is recommended to delete all the files in this directory once in a while. Graph images will be (re)created whenever a page is viewed and pchart4mw discovers the graph image doesn't exist.

Its origin
The creation of this extension was inspired after discovering the excellent PHP Chart library pChart on the internet. The stunning charts this pChart library produces are a great addition in charting functionality for MediaWiki.

The design of pchart4mw is partly inspired by extensions gchart4mw (Google chart for Mediawiki) and gnuplotBasic.

Its development
Its development started early 2009. It was first publicly released in July 2009. As of November 2009 its full documentation was finished on the pchart4mw project site. As of version 1.1 - released in June 2010 - pchart4mw supports parser functions to enable integrating pchart4mw's charting capabilities with other MediaWiki functions or extensions.

This extension is developed and tested with pChart 1.27d, MediaWiki 1.12+ and PHP 5.2 on a Windows machine. It should work just as fine on other versions/platforms, as long as PHP 5.x is used with GD Library and freetype extension enabled.

Its design choices
The design choices made for pchart4mw.
 * Use of pChart library to create the graphs. This extensions options only go as far as what the pChart library provides.
 * No data files, inline data only. pchart4mw only accepts data that is part of the wiki markup.
 * Unique tag and function for every chart type. This helps keep the syntax as simple and uniform as possible.
 * Simple user syntax. The syntax is kept as simple as possible to make this extension usable for a wide variety of users.

Its security
All the data in the wiki page is processed on the MediaWiki server environment by this extension and the installed pChart library. Your data does not have to be sent elsewhere.

Its name
It is called pchart4mw because:
 * It is based on the PHP Chart library (pChart) and it is made for (4) use with MediaWiki (mw) (although this extension could be easily be adjusted for another php based wiki)

More on pchart4mw...
Please note that this page is only a brief introduction to pchart4mw. Visit the pchart4mw project site for more details and full documentation.