SVGGraph 3.5
Published
SVGGraph 3.5 does the stuff that I was trying to do when I ended up adding support for shadows. I'm hoping this is a change that people will find quite useful.
Colour filters
The main change is the addition of support for colour filters. What this means is that you can choose a colour and modify it using a filter to get a different shade or hue. This is not easy to explain, so here's an example:
These bars are all using the main colour “red”, but with different colour filters applied. In this case the “hue” filter is used to change the colour quite a lot. The actual array of colours used is shown below.
$colours = [
'red',
'red/hue(30)',
'red/hue(60)',
'red/hue(90)',
'red/hue(120)',
'red/hue(150)',
'red/hue(180)',
'red/hue(210)',
];
The bar edge is also a modified version of the colour the bar is filled with.
This is achieved by adding a “brightness” filter to the
“fillColour” value in the stroke_colour
option:
// whatever colour the bar is filled with, but less bright
$settings['stroke_colour'] = 'fillColour/brightness(-20%)';
More details and examples of how filters can be used is on the colours, gradients and patterns page. At the moment the only filters supported are “saturation”, “brightness” and “hue”, but I would be happy to add more if anyone has any requests.
What does this have to do with shadows?
Nothing at all, really. I had hoped that I could make colour filters work by
using the SVG <filter>
element, but it turned out that it
is not really capable of doing what I want (at least not without drawing
everything very differently). But while I was trying to make colour filters
work using <filter>
I got a decent shadow effect working and
thought it was worth keeping.
The colour filters in version 3.5 actually work by converting the main colour
to RGB or HSL and modifying the components. No SVG trickery is involved, which
is actually a good thing because it means it should work when output to PDF or
anything else that might struggle with <filter>
.
Other changes
There are a few other updates in this version. One of them is visible on the
example graph above - the grid_colour
option now supports using
gradients and patterns, and I have tried to add support for gradients and
patterns in as many places as seemed sensible. If you need them somewhere that it
doesn't work, get in touch with me and I'll see if I can help.
Apart from that I've also added “fillColour” and “fill”
support in more places too. The most useful places are probably the
best_fit_colour
and best_fit_project_colour
options,
though it is also available in the box and whisker graph's median_colour
option.
There are two new options in this version for more control over what appears
in the legend, legend_unique_fields
and legend_entries_callback
.
The first of these is a simple option for de-duplication of legend entries, but
the callback option allows you to rearrange, rename and remove entries from the
legend. See the
legend_entries_callback
and legend_unique_fields
entries in the options index for details.
Anything else?
Someone suggested adding source links for all the example graphs in the SVGGraph pages. That was a really good idea, so now all the graphs that have reasonably readable source code have a “View source” link underneath. That includes the one at the top of this article, but I haven't gone through and updated the graphs in previous news items. It took me quite a while to add all those that I have done, so I hope someone finds them useful.
The new version of SVGGraph is available from the downloads page, or from GitHub / Packagist with Composer.