vasturiano / sunburst-chart

A sunburst interactive chart web component for visualizing hierarchical data
https://vasturiano.github.io/sunburst-chart/example/flare/
MIT License
292 stars 89 forks source link

Sunburst folded until page refresh ( ERROR TypeError b.focusOnNode.__dataNode is undefined ) #121

Closed relouman closed 2 months ago

relouman commented 2 months ago

Describe the bug Once in a while, when going to the sunburst page, we have our sunburst completely folded (we only see the center part of the sunburst without all the other layers/rings). When opening the console debugger in the browser we get the following error; ERROR TypeError b.focusOnNode.__dataNode is undefined.

To Reproduce It is hard to reproduce the problem, it happens once and a while.

Expected behavior The sunburst is unfolded

Screenshots N/A

Desktop (please complete the following information): firefox 116 OS ubuntu

Additional context We read your code and found out only one place with the code focusOnNode.__dataNode on it. It is the file sunburst.js and the line is:

state.focusOnNode && state.focusOnNode.__dataNode.y0 >= 0 && state.focusOnNode.__dataNode

is it correct, i am not a js expert but I would have found it safer to write the condition state.focusOnNode.dataNode before the evaluation state.focusOnNode.dataNode.y0 like this :

state.focusOnNode &&  state.focusOnNode.__dataNode && state.focusOnNode.__dataNode.y0 >= 0 

Do you think it might be an error on your code, or is there a initialization problem on our side (while retrieving data)?

vasturiano commented 2 months ago

@relouman thanks for reaching out. The code should be correct as it is. It makes sense when you see the context around it: https://github.com/vasturiano/sunburst-chart/blob/c72cf0c527974ef67abf426cfb765d79af8a6a66/src/sunburst.js#L147-L149

In your app code are you programmatically invoking focusOnNode(...)? And if so, are you certain that you are always passing an existing node object, that has a __dataNode attribute?

relouman commented 2 months ago

@vasturiano : Thank you very much for your fast answer. I understand the problem lies on our side, especially on the completion of the node object. The issue can be closed. Thank you for the great work.