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

Fix animations when data is replaced #9120

Merged
merged 1 commit into from May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/core/core.datasetController.js
Expand Up @@ -332,16 +332,15 @@ export default class DatasetController {
if (_data) {
// This case happens when the user replaced the data array instance.
unlistenArrayEvents(_data, me);
// Discard old elements, parsed data and stacks
// Discard old parsed data and stacks
const meta = me._cachedMeta;
clearStacks(meta);
meta._parsed = [];
meta.data = [];
}
if (data && Object.isExtensible(data)) {
listenArrayEvents(data, me);
me._syncList = [];
}
me._syncList = [];
me._data = data;
}
}
Expand Down Expand Up @@ -933,7 +932,8 @@ export default class DatasetController {
me._insertElements(numMeta, numData - numMeta, resetNewElements);
} else if (numData < numMeta) {
me._removeElements(numData, numMeta - numData);
} else if (count) {
}
if (count) {
// TODO: It is not optimal to always parse the old data
// This is done because we are not detecting direct assignments:
// chart.data.datasets[0].data[5] = 10;
Expand Down
2 changes: 2 additions & 0 deletions test/specs/core.datasetController.tests.js
Expand Up @@ -392,12 +392,14 @@ describe('Chart.DatasetController', function() {

expect(meta.data.length).toBe(6);
expect(meta._parsed.map(p => p.y)).toEqual(data0);
const point0 = meta.data[0];

chart.data.datasets[0].data = data1;
chart.update();

expect(meta.data.length).toBe(3);
expect(meta._parsed.map(p => p.y)).toEqual(data1);
expect(meta.data[0]).toEqual(point0);

data1.push(9);
chart.update();
Expand Down