From 2b57660abaed8b98c8ed8d472c717aad805a81c2 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Fri, 29 May 2020 23:27:10 +0300 Subject: [PATCH] Make indexable options looping (#7442) * Make indexable options looping * Migration note --- docs/docs/getting-started/v3-migration.md | 6 +++ src/helpers/helpers.options.js | 2 +- .../backgroundColor/loopable.js | 45 ++++++++++++++++++ .../backgroundColor/loopable.png | Bin 0 -> 6627 bytes test/specs/helpers.options.tests.js | 11 +++-- 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/controller.bar/backgroundColor/loopable.js create mode 100644 test/fixtures/controller.bar/backgroundColor/loopable.png diff --git a/docs/docs/getting-started/v3-migration.md b/docs/docs/getting-started/v3-migration.md index 1d3406a57..00c222c6a 100644 --- a/docs/docs/getting-started/v3-migration.md +++ b/docs/docs/getting-started/v3-migration.md @@ -25,6 +25,12 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released A number of changes were made to the configuration options passed to the `Chart` constructor. Those changes are documented below. +#### Generic changes + +* Indexable options are now looping. `backgroundColor: ['red', 'green']` will result in alternating `'red'` / `'green'` if there are more than 2 data points. + +#### Specific changes + * `hover.animationDuration` is now configured in `animation.active.duration` * `responsiveAnimationDuration` is now configured in `animation.resize.duration` * Polar area `startAngle` option is now consistent with `Radar`, 0 is at top and value is in degrees. Default is changed from `-½π` to `0`. diff --git a/src/helpers/helpers.options.js b/src/helpers/helpers.options.js index 1335d0ae2..c6dd6ef14 100644 --- a/src/helpers/helpers.options.js +++ b/src/helpers/helpers.options.js @@ -120,7 +120,7 @@ export function resolve(inputs, context, index, info) { cacheable = false; } if (index !== undefined && isArray(value)) { - value = value[index]; + value = value[index % value.length]; cacheable = false; } if (value !== undefined) { diff --git a/test/fixtures/controller.bar/backgroundColor/loopable.js b/test/fixtures/controller.bar/backgroundColor/loopable.js new file mode 100644 index 000000000..1e6ff1ee8 --- /dev/null +++ b/test/fixtures/controller.bar/backgroundColor/loopable.js @@ -0,0 +1,45 @@ +module.exports = { + config: { + type: 'bar', + data: { + labels: [0, 1, 2, 3, 4, 5], + datasets: [ + { + // option in dataset + data: [0, 2, 3, 4, 5, 6], + backgroundColor: [ + '#ff0000', + '#00ff00', + '#0000ff' + ] + }, + { + // option in element (fallback) + data: [6, 5, 4, 3, 2, 1], + } + ] + }, + options: { + legend: false, + title: false, + elements: { + rectangle: { + backgroundColor: [ + '#000000', + '#888888' + ] + } + }, + scales: { + x: {display: false}, + y: {display: false} + } + } + }, + options: { + canvas: { + height: 256, + width: 512 + } + } +}; diff --git a/test/fixtures/controller.bar/backgroundColor/loopable.png b/test/fixtures/controller.bar/backgroundColor/loopable.png new file mode 100644 index 0000000000000000000000000000000000000000..ea13b696d532fe1489cdf356feefdaf372f2ebd5 GIT binary patch literal 6627 zcmeHMYgAKL7T))olq3ufC6OsmlUWF*FbudVhPG;MTM8j?;YMJbXi zwKAo{#4cO4XiKCD2ofBTM?uJ4I!aqteGKXq0|ZM2A@V4Yf_cCkqg}%MopyE2n*6$V z?X%B5ul;@Z+vk1|6CLiv@!$Y})5Zb*C#die+E9>5% zvq2Zo+tO{iueBQTM!wML_!@q1nle{Rr>&mKRu+h9q07!jl@CF}t}*V+RKKBR_RjB) zrb*}`ZT{VQWu?kG{(|*dy=XanZk!%suv}->@Lb_eFs{xLACN)mfe;L5Nc;rAX#~F% zT>VC}n}Fy$hU03vBU$bPrTc9T{>Y)p?jW)6!!Ml=#tLk_zRY^BLu(z8X|uRZwR1nz z)U}%ib&^TfUHoFI(xB29O#6xodi1G$jcl3e-h2E2;Al{G$~=HCDzJR55NmTDbTnNI z(pt_->vsH=atZ6}G;X04R?CsJ>B|}yS}&UFau6i~Hx-LH%^*5&-N4h|K9wiLFnM1& zu2yqw*?*&PDID5&y_L-(7rFC*nE>2C?8@oJ2Do|nL~j%UUd>hDSB22TCMz0hnbg1^ zjX5~pM};wo7kLo230Brh17X$EHMwrC;P3~3;8Z_^ku)1S`CM|_AreC6o3WS}CUJ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