SVGGraph 3.7

Published

SVGGraph 3.7 has a few more useful updates in it, improving some existing functions and adding some more features.

Average lines

This has been on the to-do list for a long time, mainly because I thought it would already be quite simple to do using the shape options. Not as simple as adding the new show_average option to your SVGGraph settings though. I have actually implemented these average lines using guidelines, which means a whole load of styling options are available without much extra work.

Average lines example

The example shows the first two average lines drawn behind the graph and the third on top of it. It's probably not a good idea to mix them on a 3D graph because the distance between the horizontal lines doesn't reflect the actual values, but it does show how the two types of line are drawn.

Average lines are supported by all the grid-based graph types, including radar graphs. Radar graphs didn't support guidelines at all until now and they still don't support all the options that guidelines have, but it should be good enough for the average lines.

The show_average option turns the lines on, and the options for styling the lines all start with average_ - they mostly coincide with the guideline options, except there are average_title_ options for the text and a callback option for including the average value in the title.

Background shadow and graph subtitle

Someone asked me for these recently, and since they were fairly simple I added them in straight away. The back_shadow option turns the shadow on and sets its size, back_shadow_opacity sets its opacity and back_shadow_blur blurs the shadow. Blurred shadows are implemented using an SVG filter, so make sure whatever you expect to render the SVG in can cope with that.

The graph_subtitle option shows text under the main graph_title text. The default font size means it is smaller, but there are options to change the font size, colour, and the spacing between the main title and subtitle. The subtitle is only displayed when there is a main title, so you can't show a subtitle by itself.

Both of these new features have been used for the example graph above.

Y-axis calculations

There is a new option, axis_tightness_y, that can be used to enable an alternative algorithm for calculating the divisions and ends of the Y axis. The default value of the option is 1 for the old algorithm, and a value of 0 enables the new method.

The name of the option comes from the way the new algorithm doesn't try to fit the ends of the axis as tightly to the data. I didn't use it for the example graph above, but if I had then the Y axis would have had 200 at the top instead of the 160 it has now.

I haven't yet decided if I think the new algorithm provides a better looking graph or not. I'm not planning to change the default anyway, since that would change a lot of existing graphs. I chose the name and data types for this option to allow for some more adjustments in the future.

More colour support

The colour filters added in version 3.5 are very handy, and I found myself wanting to use them in the colour range functions as well. So I've updated the colourRangeHexRGB and colourRangeHexHSL functions to support all the different types of colour specifications, not just hex format. This is demonstrated in the example graph above, where the function calls look like this:

$graph->colourRangeHexHSL(0, 'red/saturation(180%)/brightness(150%)', 'red/saturation(60%)');
$graph->colourRangeHexHSL(1, 'green/saturation(180%)/brightness(150%)', 'green/saturation(60%)');
$graph->colourRangeHexHSL(2, 'blue/saturation(180%)/brightness(150%)', 'blue/saturation(60%)');

A small part of me wants to rename these functions now that they don't quite do what they say they do, but if I started listening to small parts of myself I'd end up locked away somewhere quiet.

Other changes

I've updated the way that the axis_label_position option works to support "left", "right", "top" and "bottom" as positions as well as the numeric values. Using one of these strings aligns the text with the end of the axis, whereas a numeric value positions the centre point of the text.

I've fixed a bug in radar graphs, where the reverse option was not reversing the direction of the X-axis. I've also split the best-fit code out into its own class files to allow me to work on alternative algorithms.

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

« Previous: JPEG Saver 5.11 Next: JPEG Saver 5.12 »