]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Setting correct decimated values when below threshold (#8883)
authorNico-DF <difalco.nicola@gmail.com>
Mon, 12 Apr 2021 13:08:39 +0000 (15:08 +0200)
committerGitHub <noreply@github.com>
Mon, 12 Apr 2021 13:08:39 +0000 (09:08 -0400)
* Setting correct decimated values when below threshold
* Using existing function for cleaning decimated data
* Cleaning decimated only on current dataset
* Reordering decimation clean to avoid allocation

src/plugins/plugin.decimation.js

index f9bada37d24d39baf631b7e1a88988efcce5237e..4f1db3661bd7bbca0482a1ab50820a2b923eedab 100644 (file)
@@ -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);
   });
 }
 
@@ -232,6 +236,7 @@ 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;
       }