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

Doughnut mixing hidden states when hidden data items are removed #9807

Closed
juliankigwana opened this issue Oct 29, 2021 · 4 comments · Fixed by #9857
Closed

Doughnut mixing hidden states when hidden data items are removed #9807

juliankigwana opened this issue Oct 29, 2021 · 4 comments · Fixed by #9857

Comments

@juliankigwana
Copy link

juliankigwana commented Oct 29, 2021

When removing data that has been hidden, the chart retains the hidden indexes, and goes out of sync with its legend.

Screen.Recording.Google.Chrome.mp4
Screen.Recording.Google.Chrome.2.mp4

You don't see the problem in the examples only because the deleted data is at the end of the arrays. If you remove any item other than the last one then this happens

Expected Behavior

When the data is deleted, the underlying hiddenIndex to be removed too so that no new items are hidden.

Current Behavior

The chart retains the state of the hiddenIndices and sets the next available item to hidden.

Steps to Reproduce

Create a doughnut, set any item other than the last one to hidden, then delete any data item that has a lower index than the hidden one.

https://codepen.io/juliankigwana/pen/PoKKEvj

Context

I need the ability to add and remove data without the legend going out of sync

Environment

@etimberg etimberg added this to the Version 3.6.1 milestone Oct 29, 2021
@etimberg
Copy link
Member

@kurkle this is related to #9450. When the dataset controller updates, the controller _hiddenIndices object needs to be updated too. It looks like it would need to be rebuilt because all of the indexes will have potentially shifted.

I'm not sure what the best way to achieve this fix would be. In theory the datasets could be different lengths but I think in practice that cannot be the case. Perhaps we need to use listenArrayEvents but specifically listen to the data.labels array as well and use that to update the hidden indices mapping. It might also make sense for _hiddenIndices to be an array rather than a dict because they we can just apply the operations directly without having to recalculate everything. Does that make sense?

@kurkle
Copy link
Member

kurkle commented Oct 30, 2021

Did not look closely, but maybe this could be done at the same time with elements (insertElements etc). Internally we could change to an array, if its easier to handle. Also need to consider the case when data/labels is replaced.

@kurkle
Copy link
Member

kurkle commented Oct 30, 2021

Also it could be much easier to move the hidden attribute back to the elements.

@etimberg
Copy link
Member

That's another option, to move it back to the elements and then resolve the feature another way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants