Skip to content

Commit

Permalink
Setting correct decimated values when below threshold (#8883)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Nico-DF committed Apr 12, 2021
1 parent ef3a777 commit 5a27de3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/plugins/plugin.decimation.js
Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5a27de3

Please sign in to comment.