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

Draft: New: ignoreZeroSegments prop on pie #4107

Closed
wants to merge 2 commits into from

Conversation

imagineLife
Copy link
Contributor

Description

A Problem: When rendering segments of a pie that contain a "0" value, the lint error react/no-array-index-key appears.
This solution: provide recharts consumers the ability to "tell" recharts to "skip" rendering segments of a pie where the value(s) are zero:

  • new prop
  • check for prop presence and element value during segment mapping, and "skip" when appropriate

Also, this address some unforeseen lint issues in the pie "demo" file.

Related Issue

4004

Motivation and Context

One way forward out of the index-based keys currently in use in recharts.
If this seems like a plausible addition, this same prop could be added to many (all?) other chart types where "0" values may cause index-based-key errors.

How Has This Been Tested?

...tbd...

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or extended an existing story to show my changes
    • I added a comment above the prop to show a one-liner in the storybook prop definition
  • All new and existing tests passed.

@imagineLife imagineLife marked this pull request as draft February 1, 2024 15:57
@ckifer
Copy link
Member

ckifer commented Feb 1, 2024

The solution can't be something that breaks people, even if there is a way out of it. At least not in this major version.

If we create this prop and then change the keys back to how they were people will get the key error until they take action which isn't ideal.

This prop also complicates the API for something that should be an internal detail imo.

@ckifer
Copy link
Member

ckifer commented Feb 1, 2024

One idea for solving the key issue would be to create a key map at render time. Both the key and value would be the react key we're creating. If it doesn't exist, add it to the map. If it does exist, increment a counter by 1 for that particular key and append the count.

This is deterministic (will happen the same every render/every time unless data order changes). Who knows, maybe that's as bad as indices but just a thought

@ckifer ckifer closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants