From 1efe370101ca1d3e9597ce7a328b08b59fffb29c Mon Sep 17 00:00:00 2001 From: Nico-DF Date: Mon, 12 Apr 2021 08:50:44 +0200 Subject: [PATCH 1/4] Setting correct decimated values when below threshold --- src/plugins/plugin.decimation.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plugins/plugin.decimation.js b/src/plugins/plugin.decimation.js index f9bada37d24..2a31ebd7021 100644 --- a/src/plugins/plugin.decimation.js +++ b/src/plugins/plugin.decimation.js @@ -229,12 +229,6 @@ export default { return; } - let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data); - if (count <= 4 * availableWidth) { - // No decimation is required until we are above this threshold - return; - } - if (isNullOrUndef(_data)) { // First time we are seeing this dataset // We override the 'data' property with a setter that stores the @@ -253,6 +247,13 @@ export default { }); } + let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data); + if (count <= 4 * availableWidth) { + // No decimation is required until we are above this threshold + dataset._decimated = data.slice(start, start + count); + return; + } + // Point the chart to the decimated data let decimated; switch (options.algorithm) { From 0f94e815153334e9e17803b93c64e71516810f1e Mon Sep 17 00:00:00 2001 From: Nico-DF Date: Mon, 12 Apr 2021 09:52:52 +0200 Subject: [PATCH 2/4] Using existing function for cleaning decimated data --- src/plugins/plugin.decimation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/plugin.decimation.js b/src/plugins/plugin.decimation.js index 2a31ebd7021..c359b2aac79 100644 --- a/src/plugins/plugin.decimation.js +++ b/src/plugins/plugin.decimation.js @@ -250,7 +250,7 @@ export default { let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data); if (count <= 4 * availableWidth) { // No decimation is required until we are above this threshold - dataset._decimated = data.slice(start, start + count); + cleanDecimatedData(chart); return; } From 5b3f260d02b01ff4fc103809006cb33568989472 Mon Sep 17 00:00:00 2001 From: Nico-DF Date: Mon, 12 Apr 2021 10:15:15 +0200 Subject: [PATCH 3/4] Cleaning decimated only on current dataset --- src/plugins/plugin.decimation.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/plugin.decimation.js b/src/plugins/plugin.decimation.js index c359b2aac79..d5dce1a739d 100644 --- a/src/plugins/plugin.decimation.js +++ b/src/plugins/plugin.decimation.js @@ -153,14 +153,18 @@ function minMaxDecimation(data, start, count, availableWidth) { return decimated; } +function cleanDecimatedDataset(dataset) { + if (dataset._decimated) { + const data = dataset._data; + delete dataset._decimated; + delete dataset._data; + Object.defineProperty(dataset, 'data', {value: data}); + } +} + function cleanDecimatedData(chart) { chart.data.datasets.forEach((dataset) => { - if (dataset._decimated) { - const data = dataset._data; - delete dataset._decimated; - delete dataset._data; - Object.defineProperty(dataset, 'data', {value: data}); - } + cleanDecimatedDataset(dataset); }); } @@ -250,7 +254,7 @@ export default { let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data); if (count <= 4 * availableWidth) { // No decimation is required until we are above this threshold - cleanDecimatedData(chart); + cleanDecimatedDataset(dataset); return; } From 4bd7e8776c5cfe31540678337637e3f8472cd8ce Mon Sep 17 00:00:00 2001 From: Nico-DF Date: Mon, 12 Apr 2021 10:44:18 +0200 Subject: [PATCH 4/4] Reordering decimation clean to avoid allocation --- src/plugins/plugin.decimation.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/plugin.decimation.js b/src/plugins/plugin.decimation.js index d5dce1a739d..4f1db3661bd 100644 --- a/src/plugins/plugin.decimation.js +++ b/src/plugins/plugin.decimation.js @@ -233,6 +233,13 @@ export default { return; } + let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data); + if (count <= 4 * availableWidth) { + // No decimation is required until we are above this threshold + cleanDecimatedDataset(dataset); + return; + } + if (isNullOrUndef(_data)) { // First time we are seeing this dataset // We override the 'data' property with a setter that stores the @@ -251,13 +258,6 @@ export default { }); } - let {start, count} = getStartAndCountOfVisiblePointsSimplified(meta, data); - if (count <= 4 * availableWidth) { - // No decimation is required until we are above this threshold - cleanDecimatedDataset(dataset); - return; - } - // Point the chart to the decimated data let decimated; switch (options.algorithm) {