Correct decimation plugin documentation (#8801)

* Correct decimation plugin documentation

* The default for decimation is `false`.
* Added a sample for data decimation
* Corrected an issue in the decimation plugin when switched from enabled to disabled
This commit is contained in:
Evert Timberg
2021-04-03 13:06:31 -04:00
committed by GitHub
parent 238bfa589c
commit bdfaa44ab3
5 changed files with 137 additions and 9 deletions

View File

@@ -141,6 +141,17 @@ function minMaxDecimation(data, availableWidth) {
return decimated;
}
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});
}
});
}
export default {
id: 'decimation',
@@ -151,6 +162,8 @@ export default {
beforeElementsUpdate: (chart, args, options) => {
if (!options.enabled) {
// The decimation plugin may have been previously enabled. Need to remove old `dataset._data` handlers
cleanDecimatedData(chart);
return;
}
@@ -224,13 +237,6 @@ export default {
},
destroy(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});
}
});
cleanDecimatedData(chart);
}
};