SVGGraph 3.0.1

Published

SVGGraph 3.0.1 is a bugfix release, but there are a lot of changes in it. Sometimes you just have to rip up the floorboards to kill that annoying insect.*

2,75px s'il vous plaƮt

The bug that caused all these changes is a very simple one: PHP automatically converts numbers to strings using its current locale. This makes perfect sense, but it meant that running SVGGraph in a locale that uses a comma instead of a full-stop for the decimal separator produced garbled SVG output. SVG always uses a full-stop for its decimal separator, with commas or spaces used for separating values.

To fix this, there are four new classes for the different areas where things can go wrong. Number and Attribute are low-level classes for SVG number values and element attributes. Transform is a class for managing rotation, translation and any other transforms, and PathData is a class for SVG path elements, which use strings of numbers and command characters to represent lines, curves and angles.

Apart from these SVG values, numbers inserted into the Javascript that SVGGraph uses must also use a full-stop for the decimals separator. To fix that, many of the Javascript functions that SVGGraph outputs have been moved into templates in a new subdirectory - so you must have this directory present if you want to use crosshairs, tooltips, fading, etc. SVGGraph will complain loudly if it wants to use a template and cannot find it.

This all seems a bit much

Why not just wrap the whole of SVGGraph in a big setlocale(LC_ALL, 'C'); and forget all about it? That was my first thought, and I think it would probably work in most cases. But the manual page for setlocale has a big warning box on it that says that the locale is set per-process and not per-thread. What that means is that setting the locale in one script also sets the locale in other server threads, so if I had tried to fix it that way SVGGraph could be:

None of these are very appealing, and the idea of decimal points flip-flopping between commas and full-stops at random points in a script's execution is a bit worrying. My advice: don't convert numbers to strings until you need to output them.

In any case, the new version of SVGGraph is available from the downloads page, or from GitHub / Packagist with Composer.

* I've never ripped up the floorboards to kill an insect, and I don't really think it is a good idea. If you have a problem with insects in your home, contact a professional exterminator and maybe they will spray them or something.

« Previous: SVGGraph 3.0 Next: JPEG Saver 5.3 »

This site uses cookies - details here.