-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure background patterns to aid color vision deficient viewers #1323
Comments
@ashiguruma we do not yet have this. It would be great if you could submit a PR for the v2.0 version. |
I should add that this would work in v1 by setting the fillColor to a This may work as well in v2, but requires some testing. |
Thanks for the pointer. Using
Will investigate the error in v2 and a possible background colour solution. |
The v2 error comes when no hover colour is specified. We use a library to try and mix the fill colour, which doesn't work with a pattern object. I'll put some thought into a nice way to handle this. Setting the background colour is difficult. What if you:
|
Your idea worked well with The code required to achieve the effect is a little bulky. Will need to write some kind of helper to create multiple pattern fills and highlight states. Will take a look at |
I added some documentation on this at http://www.chartjs.org/docs/#getting-started-colors |
I updated the fiddle for v2: https://jsfiddle.net/b0g6d8zL/1/ |
What about checking for a setHoverStyle: function(arc) {
var dataset = this.chart.data.datasets[arc._datasetIndex];
var index = arc._index;
var backgroundColor = (arc._model.backgroundColor instanceof CanvasPattern) ? arc._model.backgroundColor : helpers.color(arc._model.backgroundColor).saturate(0.5).darken(0.1).rgbString();
arc._model.backgroundColor = arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, backgroundColor);
arc._model.borderColor = arc.custom && arc.custom.hoverBorderColor ? arc.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(arc._model.borderColor).saturate(0.5).darken(0.1).rgbString());
arc._model.borderWidth = arc.custom && arc.custom.hoverBorderWidth ? arc.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, arc._model.borderWidth);
}, I agree it would be nice to have the pattern generation taken care of by an external library. |
Yeah, that's a good idea. Should make a helper function because it will be used in all controllers |
When a hover background isn't specified in the config for a chart a modified version of the default color is used. If the background color is a CanvasPattern object an error is triggered. With this change the default background color will no longer be modified if it is a CanvasPattern.
I've added a helper method and some tests. If you're happy with the format and naming I'll add this to other chart types. |
@ashiguruma looking good. The one thing I would caution would be that it shouldn't necessarily be hover background specific (someone could set a pattern for a line stroke for instance) so the helper might need a rename |
also, heads up that this will become a lot simpler once #2491 is merged since I'm trying to consolidate all of the hover style functions |
Patterns could be used for style attributes other than background e.g. stroke. Updates chartjs#1323
Good point. I've renamed the method. In light of #2491 should I hold off updating all chart types? |
No, you can go ahead and update them all. I'll take care of any merging due to 2491 |
Updated all chart types to use the helper.getHoverColor. Pattern fills can now be specified for both fill and line portions of a chart. Updates chartjs#1323
Done. Will take a look at how to simplify pattern generation with a library/plugin. |
@ashiguruma looks good. can you PR it? |
The core.helpers file was failing linting checks as the global CanvasPattern was not defined. Added the `/* global CanvasGradient */` statement to make linting pass. Updates chartjs#1323
The core.helpers file was failing linting checks as the global CanvasPattern was not defined. Added the `/* global CanvasGradient */` statement to make linting pass. Updates chartjs#1323
How about the below for usage of some form of pattern helper? pattern(shape, backgroundColor, [patternColor, size]); Shape can be either a string matching a set of pre-defined patterns or a custom pattern canvas. datasets: [{
data: [300, 50, 100],
backgroundColor: [pattern('circle', '#f7464a'), '#46bfbd', '#fdb45c']
}] Could alternatively add a pattern option to the config that would auto-generate the patterns using the colors supplied although this is seems less flexible. datasets: [{
data: [300, 50, 100],
backgroundColor: ['#f7464a', '#46bfbd', '#fdb45c'],
pattern: true
}] |
A pattern helper is a good idea. I don't think it should live in the core though otherwise we're just going to increase the size |
True. An external pattern generator makes most sense. I've already started looking at that implementation so will update the issue accordingly. |
There's a problem when drawing the legend squares as well in label mode |
@kenjinp do you have a screen shot and/or some example data to go on? |
I've put together the beginnings of a pattern generator library. Needs more patterns and also some work on scaling. Will get some more patterns in. @etimberg is it worth updating the documentation once there are more patterns? |
@ashiguruma yup, we can update the documentation. If you'd like we could also link to your pattern generator library 😄 |
@etimberg Here's the library for pattern generation. Works quite nicely with large block colors. Happy to update the documentation. |
:D looks great. I'll happily merge a docs update linking to this |
Closing since @ashiguruma has written a great library to make these patterns and I merged the docs update in #3114 |
Is there a way to add background images to chart fills? Patterns can be added to the legend as its template is configurable, however it doesn't currently appear possible to configure the background image of chart fills.
To aid comprehension by color vision deficient viewers it would be useful to add simple patterns. Image files or base64 encoded patterns like those shown below could be specified in the chart config.
Would it be worth creating a pull request for this?
The text was updated successfully, but these errors were encountered: