Skip to content

Commit 505afa7

Browse files
authored
Fix element creation for large dataset (#8388)
* Fix element creation for large dataset * Fix syncing * Remove duplication
1 parent 6e56ae6 commit 505afa7

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/core/core.datasetController.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,18 +990,25 @@ export default class DatasetController {
990990
*/
991991
_insertElements(start, count, resetNewElements = true) {
992992
const me = this;
993-
const elements = new Array(count);
994993
const meta = me._cachedMeta;
995994
const data = meta.data;
995+
const end = start + count;
996996
let i;
997997

998-
for (i = 0; i < count; ++i) {
999-
elements[i] = new me.dataElementType();
998+
const move = (arr) => {
999+
arr.length += count;
1000+
for (i = arr.length - 1; i >= end; i--) {
1001+
arr[i] = arr[i - count];
1002+
}
1003+
};
1004+
move(data);
1005+
1006+
for (i = start; i < end; ++i) {
1007+
data[i] = new me.dataElementType();
10001008
}
1001-
data.splice(start, 0, ...elements);
10021009

10031010
if (me._parsing) {
1004-
meta._parsed.splice(start, 0, ...new Array(count));
1011+
move(meta._parsed);
10051012
}
10061013
me.parse(start, count);
10071014

test/specs/controller.line.tests.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,4 +907,30 @@ describe('Chart.controllers.line', function() {
907907
expect(meta.data[2].options.borderWidth).toBe(3);
908908
expect(meta.data[3].options.borderWidth).toBe(4);
909909
});
910+
911+
it('should render a million points', function() {
912+
var data = [];
913+
for (let x = 0; x < 1e6; x++) {
914+
data.push({x, y: Math.sin(x / 10000)});
915+
}
916+
function createChart() {
917+
window.acquireChart({
918+
type: 'line',
919+
data: {
920+
datasets: [{
921+
data,
922+
borderWidth: 1,
923+
radius: 0
924+
}],
925+
},
926+
options: {
927+
scales: {
928+
x: {type: 'linear'},
929+
y: {type: 'linear'}
930+
}
931+
}
932+
});
933+
}
934+
expect(createChart).not.toThrow();
935+
});
910936
});

0 commit comments

Comments
 (0)