Extension:SemanticSVGPrinter

What can this extension do?
This extension adds an extra result format to Semantic Mediawiki, to create a SVG image representing the results. I wrote it to create maps as the one to the right (showing worldwide export of pears).

This extension was made for http://säsongsmat.nu, and work pretty well there. It might or might not work for you.

I'm not a programmer, so this code could probably be improved a lot. Feel free to modify it, but please share the result of your work with the rest of us!

Usage
SemanticSVGPrinter needs a template SVG to work from (in the exmpale image a blank world map). The areas are colored using lower case class names, so each area should have a class name that can be shown in a query.

The first column (or a value derived from it using |keyquery={propertyname} will be matched against id:s of areas in the SVG. For each column the value, if numerical, will be used to fill the corresponding area. Colors are taken from the column labels, or from a default list. If more than one column on the same row contains a value, only the last column will be drawn. If more than one row has the same name, values will be added together.

In this example (assuming a blank world map as SVG template) Afhanistan and Belgium will be light blue, and Benin will be dark blue, Sweden will be red:
 * Query


 * Result

| Green   | b90000 | Afghanistan |      14 |        | Belgium    |       11 |        | Benin      |      380 |        | Sweden     |          |      1 |

Installation
Download the extension (see info box) and unpack it to your extensions directory. To install this extension, add the following to LocalSettings.php: Where $ssmTemporaryDirectory is a otherwise empty directory (NB: files here will be deleted!). Your web server (e.g. www or www-data) must have read-write permissions to this dir.

Query parameters

 * svgtemplate: A tmeplate SVG, with class names for the fields you want to fill
 * svgname: Output file name. NB: Will be overwritten if it exists!!! This is probably what you want, as you want the maps to be up to date, but please be careful!
 * svgimagedescription: Text for the file description page (not fully working, see to do list below)
 * svgkeyquery: Extra query to make from the first column, to get the class name. Probably only useful when working with Semantic Internal Objects.
 * svgmode: Make color from percent of total ('total'), percent of highest number ('max') or as a percent value betwen 0 and 1 ('fraction') or 0 and 100 ('percent')
 * amplify: Amplify all value, so that light colors are more visible. Useful for large datasets, such as a world map (the export map in the upper right corner has an amplify-value of 5.

Bugs and to do's

 * Files in temp directory will all get uploaded and deleted. Upload only those with an "filenamn.uploadme" text file.
 * All images get the same page description if more than one is uploaded at the same time. Put file descriptions in individual files to prevent this (same as above).
 * Variables passed will contain UNIQ / QINU messages. How do we get around this? Currently very ugly solution with preg_replace
 * use MW temp dir
 * Support multiple columns on the same row, using e.g. striped fields?
 * Error handling in various places
 * Server locale need to be correctly set for non ascii characters to show in file description. Maybe this would not be the case if putting descs in file?
 * Templates in file page descrition will be substed. This is probably not the wanted behaviour
 * Create robot user in runJobs.php, and use --user=
 * Something is wrong with how we use the params, for the last param not to be null all params above has to be set. That does not make sense.
 * i18n

Changelog

 * 0.1 - First version