Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Uncaught RangeError: Maximum call stack size exceeded

Open misraelsen opened this issue 6 years ago • 3 comments

This request is related to:

Chart.Js - Maximum Call Stack Size Exceeded (Chrome), too much recursion (Firefox) com.google.gwt.core.client.JavaScriptException #6062

Description

So I am piggy backing an array of objects I called "meta1" in the datasets object which has a bunch of data/info for drilldown purposes. I then listen for when the user clicks on a point on the graph. When they do click on the graph I am able to easily get to my "meta1" object which allows me to create the new graph that represents the drilldown for that point. This can be done for as many drilldowns the user has defined for this data.

Here is pseudo code that accomplished this:

chartListener(evt) { var activePoints = this.chart.getElementsAtEvent(evt); if (activePoints[0]) { var chartData = activePoints[0]['_chart'].config.data; var idx = activePoints[0]['_index']; var meta1 = chartData.datasets[0].meta1[idx]; this.createDrillDownGraph(meta1); } };

In chart.js 2.8.0 this method of doing drilldown works fine.

However, in chart.js 2.9.3 I get the "max stack size exceeded" error. I am guessing that chart.js (starting in chart.js 2.9 ) must be cloning or following this large "meta1" object I am passing along with the dataset and it is causing this error. I know it is my meta1 object that is causing the problem because when I remove it then I do not get the error.

Is there any way to just have chart.js clone only the things it needs in the chartConfig/datasets object rather than cloning/following any and all items in the dataset object?

Another option could be to copy everything but the meta1 array/object.

Any suggestions you have would be greatly appreciated.

The code that appears to be doing the cloning is the following: /** * Returns a deep copy of source without keeping references on objects and arrays. * @param {} source - The value to clone. * @returns {} */ clone: function(source) { if (helpers.isArray(source)) { return source.map(helpers.clone); } if (helpers.isObject(source)) { var target = {}; var keys = Object.keys(source); var klen = keys.length; var k = 0; for (; k < klen; ++k) { target[keys[k]] = helpers.clone(source[keys[k]]); } return target; } return source; },

Thanks for you consideration. -Marty

misraelsen avatar Feb 01 '20 20:02 misraelsen

@misraelsen I tested this in v2.9.3 and the latest v3 dev code. In both cases, objects attached to the data object are not cloned.

2.9.3: https://jsfiddle.net/jLt9gnyd/ v3: https://jsfiddle.net/0cfmxs65/1/

Am I trying to reproduce this correctly?

etimberg avatar Jun 01 '20 00:06 etimberg

Closing as stale per my comment above

etimberg avatar Jun 07 '20 18:06 etimberg

Just an FYI. was able to work around the Issue by storing the object in a global variable. I believe the object had a circular reference which may have caused the issue somehow. In any case I have worked around it do closing this is fine.

Marty

On Sun, Jun 7, 2020 at 12:40 PM Evert Timberg [email protected] wrote:

Closed #7051 https://github.com/chartjs/Chart.js/issues/7051.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chartjs/Chart.js/issues/7051#event-3416980908, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHPIUBE47W42CQIWE7TXYSTRVPNLFANCNFSM4KOVJMWA .

misraelsen avatar Jun 09 '20 04:06 misraelsen