From 5054ecfd7eff02a59350c446cda31bf01250373e Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Sat, 11 Jan 2020 01:31:17 +0200 Subject: [PATCH] Re-parse existing elements when data is replaced (#6925) * Re-parse existing elements when data is replaced * Update test --- src/core/core.datasetController.js | 4 ++++ test/specs/core.datasetController.tests.js | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index abe8e461491..c240d784475 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -1051,6 +1051,10 @@ helpers.extend(DatasetController.prototype, { if (numData > numMeta) { me.insertElements(numMeta, numData - numMeta); + if (changed && numMeta) { + // insertElements parses the new elements. The old ones might need parsing too. + me._parse(0, numMeta); + } } else if (numData < numMeta) { meta.data.splice(numData, numMeta - numData); meta._parsed.splice(numData, numMeta - numData); diff --git a/test/specs/core.datasetController.tests.js b/test/specs/core.datasetController.tests.js index 37545d79b2b..8d04dbee330 100644 --- a/test/specs/core.datasetController.tests.js +++ b/test/specs/core.datasetController.tests.js @@ -299,14 +299,22 @@ describe('Chart.DatasetController', function() { var meta = chart.getDatasetMeta(0); expect(meta.data.length).toBe(6); + expect(meta._parsed.map(p => p.y)).toEqual(data0); chart.data.datasets[0].data = data1; chart.update(); expect(meta.data.length).toBe(3); + expect(meta._parsed.map(p => p.y)).toEqual(data1); + + data1.push(9); + expect(meta.data.length).toBe(4); + + chart.data.datasets[0].data = data0; + chart.update(); - data1.push(9, 10, 11); expect(meta.data.length).toBe(6); + expect(meta._parsed.map(p => p.y)).toEqual(data0); }); it('should re-synchronize metadata when data are unusually altered', function() {