Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting correct decimated values when below threshold #8883

Merged
merged 4 commits into from Apr 12, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 17 additions & 12 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 @@ -229,12 +233,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
Expand All @@ -253,6 +251,13 @@ 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) {
Expand Down