Skip to content

Commit 152be46

Browse files
etimbergEvert Timberg
authored andcommitted
Decimation plugin uses the dataKey feature
1 parent e807484 commit 152be46

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/plugins/plugin.decimation.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {isNullOrUndef} from '../helpers';
2+
13
export default {
24
id: 'decimation',
35

@@ -15,8 +17,15 @@ export default {
1517

1618
chart.data.datasets.forEach((dataset, datasetIndex) => {
1719
let i, point, x, y, prevX, minIndex, maxIndex, minY, maxY;
18-
const {data} = dataset;
20+
const {_originalDataKey} = dataset;
1921
const meta = chart.getDatasetMeta(datasetIndex);
22+
const dataKey = !isNullOrUndef(_originalDataKey) ? _originalDataKey : meta.controller.getDataKey();
23+
const data = dataset[dataKey];
24+
25+
if (isNullOrUndef(_originalDataKey)) {
26+
// Store this for the next update
27+
dataset._originalDataKey = dataKey;
28+
}
2029

2130
if (meta.type !== 'line') {
2231
// Only line datasets are supported
@@ -76,8 +85,9 @@ export default {
7685
}
7786
}
7887

79-
dataset._data = dataset.data;
80-
dataset.data = decimated;
88+
// Point the chart to the decimated data
89+
dataset._decimated = decimated;
90+
dataset.dataKey = '_decimated';
8191
});
8292
}
8393
};

0 commit comments

Comments
 (0)