Closed JohnArcher closed 5 years ago
I think this is a great idea. To make it more generalized, how about naming it custom
and allowing it to receive the array of color strings and to return the customized color strings?
var myCustomFunction = function(colors) {
var myColors = ['#ff00000', '#00ff00'];
Array.prototype.push.apply(colors, myColors);
// ... or calculate your colors with some fancy algorithm
return colors;
}
// ...
plugins: {
colorschemes: {
scheme: 'brewer.Paired12',
custom: myCustomFunction
}
}
In order to keep the original color string array untouched, the array should be cloned before it is passed to the custom
function.
If this is ok, feel free to create a pull request 🙂
Sorry for my late reply. I had some days off due to Easter holidays.
I am glad you like the idea; thank you! I will incorporate your changes and create the pull request.
Ok, I reworked the code. Have a look: https://github.com/JohnArcher/chartjs-plugin-colorschemes/commit/ee2d23fbb89b50eb77a7a24e797bbfdc7d9bca1f
It is no problem for me to change it further if you don't like pieces of this.
Thank you @JohnArcher. Other than this comment, the code looks good. Can you create a PR for this? It would be great if you also add a description about the custom
option in README.
You're welcome, @nagix. Here is the latest commit: https://github.com/JohnArcher/chartjs-plugin-colorschemes/commit/aaf6ac90e3435cf05d017457ae10f0cec18842eb Not sure whether the documentation is ok (language, overall style), that's why I didn't create the PR right away.
Please see my comments in https://github.com/JohnArcher/chartjs-plugin-colorschemes/commit/aaf6ac90e3435cf05d017457ae10f0cec18842eb and go ahead with PR. Thanks!
Thanks for your good comments! PR is there.
Closing as v0.4.0 was released.
Hey @nagix , would you accept this commit as a pull request? -> https://github.com/JohnArcher/chartjs-plugin-colorschemes/commit/707ce90516af10e23e7ded3055f75d9c4a4e9f63
The aim is to (dynamically) add additional colors to a scheme in order to e.g. prevent that the same colors are used again when you have more datasets then colors.
An example using my code would be:
I really need this behaviour. :-) What do you think?