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

Handle a frozen dataset.data array. #6060

Merged
merged 6 commits into from Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/developers/updates.md
Expand Up @@ -4,7 +4,7 @@ It's pretty common to want to update charts after they've been created. When the

## Adding or Removing Data

Adding and removing data is supported by changing the data array. To add data, just add data into the data array as seen in this example.
Adding and removing data is supported by changing the data array. To add data, just add data into the data array as seen in this example. However, if `dataset.data` has been frozen using `Object.freeze()`, adding or removing data will not update the chart.
etimberg marked this conversation as resolved.
Show resolved Hide resolved

```javascript
function addData(chart, label, data) {
Expand Down
4 changes: 3 additions & 1 deletion src/core/core.datasetController.js
Expand Up @@ -225,7 +225,9 @@ helpers.extend(DatasetController.prototype, {
unlistenArrayEvents(me._data, me);
}

listenArrayEvents(data, me);
if (data && !Object.isFrozen(data)) {
listenArrayEvents(data, me);
}
me._data = data;
}

Expand Down
16 changes: 16 additions & 0 deletions test/specs/core.datasetController.tests.js
Expand Up @@ -38,6 +38,22 @@ describe('Chart.DatasetController', function() {
});
});

it('should handle a frozen data object', function() {
function createChart() {
var data = Object.freeze([0, 1, 2, 3, 4, 5]);
acquireChart({
type: 'line',
data: {
datasets: [{
data: data
}]
}
});
}

expect(createChart).not.toThrow();
});

etimberg marked this conversation as resolved.
Show resolved Hide resolved
it('should synchronize metadata when data are inserted or removed', function() {
var data = [0, 1, 2, 3, 4, 5];
var chart = acquireChart({
Expand Down