From 22e367c44537d9f23c214809d3c993209992592b 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 zc-rljdr(t%7RS%MCMA#ZP!ef@n(QEy!cuT5hPG;MTMePMRH}W zZ0WMm(W=F^M5=%w!4-KFgxt|8+jZ)rsJ9p(SSkpSM}ZW~1Nu|9GeZCD?sRrG`6u_D zdw$>F`J9vd?)RhUs4z#4I|l$9*RNX>1AwDT3|Nn#uXDREW&k{1wSLVDaa*Osoy#uD z29kE&RDLIXrl6_f@R4>e)=NYIn|Qp_ky)&c@o^Q#>~dM_k{j-xyAt;*x-BGFnRf=9 zjC%i`<}UMHoz0j#{H0zm&(E1Dqlj2oVPcqy$KR_jPj-@`;5&qxBhe_ zRZ17?@^06uD%7^I=WSQ(#7p4|)6^h?MI0J1NbK6 znm3bNg+%XB9M>qgWSKXV?7yGjhY}j?3HF5ldV;AO8>=g|-D%g^hUL0UUSrMdPt~<; z<^jEQ!exh`h^jEEwMO&a!u)PSia;x0V!rbifj@AxNK5Vx0&%|e8>K{-eQ%-pLZHri zPFB0^uat9WZ-;3Ut+ZJWr%qkcI@1R6WT%5T0eC4`^eG0>apO9k_U_4C5r!#x%W#c` zbHCQ>4U6H>-fJyv7P-KU56pPr1z?v?HPplRpB?XsB*3$&5_~Jszllwj*Vizq{?|;| zINn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