From 28482d56e6811249ea173e357d6214bdb63c4299 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Thu, 27 May 2021 17:25:02 +0300 Subject: [PATCH] Fix clearStacks with custom scaleId --- src/core/core.datasetController.js | 9 +++- .../controller.bar/stacking/issue-9105.js | 49 ++++++++++++++++++ .../controller.bar/stacking/issue-9105.png | Bin 0 -> 10460 bytes 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/controller.bar/stacking/issue-9105.js create mode 100644 test/fixtures/controller.bar/stacking/issue-9105.png diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index dbf08e77f2b..81d865810e4 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -192,13 +192,18 @@ function createDataContext(parent, index, element) { } function clearStacks(meta, items) { + const axis = meta.vScale && meta.vScale.axis; + if (!axis) { + return; + } + items = items || meta._parsed; for (const parsed of items) { const stacks = parsed._stacks; - if (!stacks || stacks[meta.vScale.id] === undefined || stacks[meta.vScale.id][meta.index] === undefined) { + if (!stacks || stacks[axis] === undefined || stacks[axis][meta.index] === undefined) { return; } - delete stacks[meta.vScale.id][meta.index]; + delete stacks[axis][meta.index]; } } diff --git a/test/fixtures/controller.bar/stacking/issue-9105.js b/test/fixtures/controller.bar/stacking/issue-9105.js new file mode 100644 index 00000000000..200ce4d30a8 --- /dev/null +++ b/test/fixtures/controller.bar/stacking/issue-9105.js @@ -0,0 +1,49 @@ +module.exports = { + description: 'https://github.com/chartjs/Chart.js/issues/9105', + config: { + type: 'bar', + data: { + labels: ['January', 'February', 'March', 'April', 'May', 'June'], + datasets: [ + { + backgroundColor: 'rgba(255,99,132,0.8)', + label: 'Dataset 1', + data: [12, 19, 3, 5, 2, 3], + stack: '0', + yAxisID: 'y-axis-1' + }, + { + backgroundColor: 'rgba(54,162,235,0.8)', + label: 'Dataset 2', + data: [13, 19, 3, 5, 8, 3], + stack: '0', + yAxisID: 'y-axis-1' + }, + { + backgroundColor: 'rgba(75,192,192,0.8)', + label: 'Dataset 3', + data: [13, 19, 3, 5, 8, 3], + stack: '0', + yAxisID: 'y-axis-1' + } + ] + }, + options: { + plugins: false, + scales: { + xaxis: { + display: false, + }, + 'y-axis-1': { + display: false + } + } + } + }, + options: { + run(chart) { + chart.data.datasets[1].stack = '1'; + chart.update(); + } + } +}; diff --git a/test/fixtures/controller.bar/stacking/issue-9105.png b/test/fixtures/controller.bar/stacking/issue-9105.png new file mode 100644 index 0000000000000000000000000000000000000000..14a21682680917e9039119b9822f75789e6f959d GIT binary patch literal 10460 zcmeHN2~bmK9{=7;A_25SK|)mstu1J=V(UQ>F;P*hRf0kU5gW9&uvCc$7&-H>t5mI} zms(noSgXN6053pAl6tJIR-gik1VX?AAwYl-LPC<)??rK@E<1b7&UUvOW-^5LzTUwjUc{4<} zaGE;{0|*a@3RKSO_wsXOS+@!*UlY8)LaOJsm}(lo{Qb%Lxg{ zWNhLSSx6MJOyUDVM|G(cj;3pNtsy1Ro$ z%dUT);51`3Lz4;N#<@!fAx%l99-1n3`h`94ddn%@k?irMYFLIw zm0^JD20yK9S70E$h1dwJ8?DB%BIo}qI%GVPo@;7dr0X_sgDu*D3^()T?QCPCk6LZ+ zl^Qc0vZblIz;XB_Jh8o7YP>IE#(O?#@RmEnoWsUbw1zL`JCf%1Wp0_j&aWxu(SWHb z^U{{K8xP+RwK?LG+PaLp!;Tn~hsRy)dIi>M8)2Jg?5D^|Y#}#AtiWV3#DhT!q@p9a zkf(-QJ;+CCkf?@xJ;-GGHE{LQOb=Bq%nFh(*YA`EEtbsxPn`EF&r2|H4 zOI>b*TYcKB-t+#0J$!TLw`^mNDu0JPK#DsK&C7tZr*-MNbs(klS{So*vs`pRP(542 zOKDxpP8~cqyQ*Oh;tp0febEMIbwV$95U~LjUgNmT=e2p4_tn}+LtSPsBqnh7aDZhW z0?wA%T|tG|#y`VHepD*vECw-K$M2!Ake{fqMB725f!9Nk>ekmr+hgb#W8ti;6AtSl z@+^ls1IjCtVd+-CfC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