From 5eb81a086ab6c0c04ad8afd0c5fe7bbf4840647c Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 19 Dec 2022 17:39:32 +0100 Subject: [PATCH 1/5] Check colors definition in the chart options --- src/plugins/plugin.colors.ts | 12 +++++- .../plugin.colors/chart-options-colors.js | 37 ++++++++++++++++++ .../plugin.colors/chart-options-colors.png | Bin 0 -> 15500 bytes 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/plugin.colors/chart-options-colors.js create mode 100644 test/fixtures/plugin.colors/chart-options-colors.png diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index b2817c85a12..aba0fec7542 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -81,6 +81,16 @@ function containsColorsDefinitions( return false; } +function containsColorsDefinition( + descriptor: ColorsDescriptor +) { + if (descriptor && descriptor.borderColor || descriptor.backgroundColor) { + return true; + } + + return false; +} + export default { id: 'colors', @@ -99,7 +109,7 @@ export default { data: {datasets} } = chart.config; - if (!options.forceOverride && (containsColorsDefinitions(datasets) || elements && containsColorsDefinitions(elements))) { + if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(chart.config.options) || (elements && containsColorsDefinitions(elements)))) { return; } diff --git a/test/fixtures/plugin.colors/chart-options-colors.js b/test/fixtures/plugin.colors/chart-options-colors.js new file mode 100644 index 00000000000..5add0c25883 --- /dev/null +++ b/test/fixtures/plugin.colors/chart-options-colors.js @@ -0,0 +1,37 @@ +module.exports = { + config: { + type: 'bar', + data: { + labels: [0, 1, 2, 3, 4, 5], + datasets: [ + { + data: [0, 5, 10, null, -10, -5], + }, + { + data: [10, 2, 3, null, 10, 5] + } + ] + }, + options: { + backgroundColor: ['red', 'green'], + scales: { + x: { + ticks: { + display: false, + } + }, + y: { + ticks: { + display: false, + } + } + }, + plugins: { + legend: false, + colors: { + enabled: true + } + } + } + } +}; diff --git a/test/fixtures/plugin.colors/chart-options-colors.png b/test/fixtures/plugin.colors/chart-options-colors.png new file mode 100644 index 0000000000000000000000000000000000000000..5b24310ed0bbd21ba043b17497004ef58c5d30b0 GIT binary patch literal 15500 zcmeHOX;hQfy53(%fPfY>Dj*6tK^+4{0W~H;oN$U4TgS>^P^f}nr5Xv452WG{fgY@= zKoV*-S~-Y{69S1-QmPWH1E@eEv4Tt?21p>&*&j~#-1gpe&bjxlb?-U(Ls%=xxA%Vc z`#kUSynAQ=iscIj+l{mX01OUZG%o}I9Q+ptY^~u-H|tS9d_i`EESw99t4F;Czyk!& z3;diF+L7<0ijqcbh&nTAB5@D?*B=*0(1!`KZg>(>#q$^MoV4=lNyXs>i^m+I(nl_g zmre=`ymMjEkRR=Ej`$_QaV|yqbL|Al&Dw-U_H5s%_3{dpD5`it#>LV`u8-+4%Y2R@ zb(XtDQumoP&wZ%oK4(#dKBI3tSHc?- zPlMcOUzx!&5scT3PrhR9x~@uZ zgBY_O%u@MP3Jc0Anrv1f(xs=#E!J z^p<+5eOWjOa7UEsK|mA_ z1dNiE3hez5ar6*I{i^tpJfb*-xeVm{GQgn%d#xHWl2H{w*Cvss3f7gtdiveWL=HE>Tu?pleqFm<3&?|L`!p3I(1!t z*p<%V37Pwv9hl|DXl|Cu6d`g^-jzvo{hcZkK^{agr?r`{t}XhMw83oH zotchrZPStlzWdG2p(vXXaR%`M2^7p8eOiqNIU55@8LPgD-Eu~+S@(I-93(uy=uwE( za?mmbGgm9}iNNztS~S0?_1U8kZS$qmYuGq(z}hn>t@A<6TFjaW0!U!#0m1|7+Q*m9 zoa~fs{kQYIcy#-PkR^iy5Wz({6rc3%p5W*(`yY}o{Iqo?oJ#Ev8#{G?Cnqwe5WXitYs-KFNP5p)w zdhoy{FTlpaXUqI9Ju>c|I_U`ycrRbIWgsvkEP?sw4h&-~P+9j^hVe6fDmQVOqE>z^ zJ53+T&L)azWSlfl?bF`9QGSRljg!=dzW8m~I|EQJ)8zS78e)p1nl~#qG+RYOY`O1( z015*AXVrbWmnJiHBrQ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!pA&QMwa1f1Ukbkjosql)?HCkhT0$1JfD*qlWg|h58^R_Q<8ggZD z$9wke6lOiIe0NDUpzp?bN14Mbp;64q4h5Yw!JsFb++?gWe7#>ORLb57@Sc9G+fvZ! zPPf{5O#1FoSPKDO`@g)~8@b8>gX=zi1@EXG%DazMFwDi_UzJulc&4&aylEXaraka@#*Az#`B+Oa5o#&F7PVs0T^5=8 zPbj!QD99ZPjOuZYskZYxaCe7zkbz4syZxGMAVkFYDT!Nour8vcw-G^%%{!= xz3>F4I$f}63gU6NeyLR^b}IMZ8pP~0Z%f^4ZQRQs`14{AJb(GT;<@2ze*wK%$}j)` literal 0 HcmV?d00001 From 2957cc69a31f79712e6987d162dc9427550b2bca Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 19 Dec 2022 17:48:58 +0100 Subject: [PATCH 2/5] Update src/plugins/plugin.colors.ts Co-authored-by: Dan Onoshko --- src/plugins/plugin.colors.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index aba0fec7542..7e58daf0bb9 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -84,11 +84,7 @@ function containsColorsDefinitions( function containsColorsDefinition( descriptor: ColorsDescriptor ) { - if (descriptor && descriptor.borderColor || descriptor.backgroundColor) { - return true; - } - - return false; + return descriptor && (descriptor.borderColor || descriptor.backgroundColor) } export default { From e47609695e6755c135d4fa401a7d3a422c11db8c Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 19 Dec 2022 17:49:24 +0100 Subject: [PATCH 3/5] Update src/plugins/plugin.colors.ts Co-authored-by: Dan Onoshko --- src/plugins/plugin.colors.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index 7e58daf0bb9..5785b332411 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -102,8 +102,10 @@ export default { const { options: {elements}, - data: {datasets} + data: {datasets}, + options } = chart.config; + const {elements} = options if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(chart.config.options) || (elements && containsColorsDefinitions(elements)))) { return; From d52b6ad5ed638b6762d5ae8f3488e5ebe641dea4 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 19 Dec 2022 17:49:33 +0100 Subject: [PATCH 4/5] Update src/plugins/plugin.colors.ts Co-authored-by: Dan Onoshko --- src/plugins/plugin.colors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index 5785b332411..672efb40e96 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -107,7 +107,7 @@ export default { } = chart.config; const {elements} = options - if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(chart.config.options) || (elements && containsColorsDefinitions(elements)))) { + if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(options) || (elements && containsColorsDefinitions(elements)))) { return; } From 0ee9259841991e5dc5b553ecf1df786538a6d9a7 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 19 Dec 2022 17:56:21 +0100 Subject: [PATCH 5/5] apply review --- src/plugins/plugin.colors.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plugins/plugin.colors.ts b/src/plugins/plugin.colors.ts index 672efb40e96..03af80eeabd 100644 --- a/src/plugins/plugin.colors.ts +++ b/src/plugins/plugin.colors.ts @@ -84,7 +84,7 @@ function containsColorsDefinitions( function containsColorsDefinition( descriptor: ColorsDescriptor ) { - return descriptor && (descriptor.borderColor || descriptor.backgroundColor) + return descriptor && (descriptor.borderColor || descriptor.backgroundColor); } export default { @@ -101,13 +101,12 @@ export default { } const { - options: {elements}, data: {datasets}, - options + options: chartOptions } = chart.config; - const {elements} = options + const {elements} = chartOptions; - if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(options) || (elements && containsColorsDefinitions(elements)))) { + if (!options.forceOverride && (containsColorsDefinitions(datasets) || containsColorsDefinition(chartOptions) || (elements && containsColorsDefinitions(elements)))) { return; }