{"action":"created","issue":{"url":"https://api.github.com/repos/highcharts/highcharts/issues/4259","repository_url":"https://api.github.com/repos/highcharts/highcharts","labels_url":"https://api.github.com/repos/highcharts/highcharts/issues/4259/labels{/name}","comments_url":"https://api.github.com/repos/highcharts/highcharts/issues/4259/comments","events_url":"https://api.github.com/repos/highcharts/highcharts/issues/4259/events","html_url":"https://github.com/highcharts/highcharts/issues/4259","id":84741556,"number":4259,"title":"setData mutating source array","user":{"login":"mjyeaney","id":1410150,"avatar_url":"https://avatars.githubusercontent.com/u/1410150?v=3","gravatar_id":"","url":"https://api.github.com/users/mjyeaney","html_url":"https://github.com/mjyeaney","followers_url":"https://api.github.com/users/mjyeaney/followers","following_url":"https://api.github.com/users/mjyeaney/following{/other_user}","gists_url":"https://api.github.com/users/mjyeaney/gists{/gist_id}","starred_url":"https://api.github.com/users/mjyeaney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjyeaney/subscriptions","organizations_url":"https://api.github.com/users/mjyeaney/orgs","repos_url":"https://api.github.com/users/mjyeaney/repos","events_url":"https://api.github.com/users/mjyeaney/events{/privacy}","received_events_url":"https://api.github.com/users/mjyeaney/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/highcharts/highcharts/labels/Undecided","name":"Undecided","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-06-03T19:46:21Z","updated_at":"2016-02-26T14:44:32Z","closed_at":null,"body":"Seeing a strange behavior against Highcharts 4.1.5. When providing an Array of numbers (i.e, [1,2,3,4]), after some threshold the source array seems to be mutated into the following form:\r\n\r\n[{y = 1}, {y=2}, {y=3}, {y=4}]\r\n\r\nThis seems to happen on larger sets of data (1300 - 1400 points + ), but we can't seem to get turboThreshold or cropThreshold to make a difference. Is there a setting we're missing, or is this a known bug?\r\n\r\nNormally not an issue, but we're visualizing running time-series data windows and as a result are hanging on to the arrays we're calling setData() with. Once they are mutated, they are effectively \"broke\"...upstream sorting/binning code doesn't expect the inner objects, and stops working.\r\n\r\nThanks for your help!"},"comment":{"url":"https://api.github.com/repos/highcharts/highcharts/issues/comments/189309119","html_url":"https://github.com/highcharts/highcharts/issues/4259#issuecomment-189309119","issue_url":"https://api.github.com/repos/highcharts/highcharts/issues/4259","id":189309119,"user":{"login":"TorsteinHonsi","id":227836,"avatar_url":"https://avatars.githubusercontent.com/u/227836?v=3","gravatar_id":"","url":"https://api.github.com/users/TorsteinHonsi","html_url":"https://github.com/TorsteinHonsi","followers_url":"https://api.github.com/users/TorsteinHonsi/followers","following_url":"https://api.github.com/users/TorsteinHonsi/following{/other_user}","gists_url":"https://api.github.com/users/TorsteinHonsi/gists{/gist_id}","starred_url":"https://api.github.com/users/TorsteinHonsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TorsteinHonsi/subscriptions","organizations_url":"https://api.github.com/users/TorsteinHonsi/orgs","repos_url":"https://api.github.com/users/TorsteinHonsi/repos","events_url":"https://api.github.com/users/TorsteinHonsi/events{/privacy}","received_events_url":"https://api.github.com/users/TorsteinHonsi/received_events","type":"User","site_admin":false},"created_at":"2016-02-26T14:44:32Z","updated_at":"2016-02-26T14:44:32Z","body":"@pawel: Consider the fiddle above.\r\n\r\nLike we talked about earlier, creating a copy of of the source data is expensive, especially when dealing with a large amount of data. A leaner solution would be to identify the places where the source data is mutated, and do the copy there. Like in the case above, it is fixed by creating a copy in `point.update`:\r\n\r\n_Find this code:_\r\n```js\r\n\t\t\t// Record the options to options.data. If there is an object from before,\r\n\t\t\t// use point options, otherwise use raw options. (#4701)\r\n\t\t\tseriesOptions.data[i] =  (isObject(seriesOptions.data[i]) && !isArray(seriesOptions.data[i])) ? point.options : options;\r\n```\r\n\r\n_Before it, add this code:_\r\n```js\r\n\t\t\t// If this is the first time we're writing back to options.data, create\r\n\t\t\t// a copy so that we don't mutate the source array. (#4259)\r\n\t\t\tif (!seriesOptions.data.isCopy) {\r\n\t\t\t\tseriesOptions.data = seriesOptions.data.slice();\r\n\t\t\t\tseriesOptions.data.isCopy = true;\r\n\t\t\t}\r\n```\r\n\r\nWhat do you think? And do you have other cases of data source mutation where this fix doesn't work?\r\n"}}