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

fix: dedup data for <VictoryStack/> #2898

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

fix: dedup data for <VictoryStack/> #2898

wants to merge 5 commits into from

Conversation

r281GQ
Copy link

@r281GQ r281GQ commented Sep 12, 2024

Description

That is a tricky issue. The problem is with AreaCharts (or LineCharts) when we use them in stacked mode.

We opt-in for stack mode by wrapping the Chart in the <VictoryStack /> component.

VictoryStack modifies the underlying data which makes AreaChart behave a bit different (draws different area) compared to when it's used on it's own. Only when given invalid data.

What is invalid data? For LineCharts and AreaCharts we can assume data is invalid/bad/corrupt when to elements have identical x values.

Therefore the main responsibility and final call should be of the library user to provide clean data.

However, with a little change we can make the AreaChart provide the same fallback with or without the usage of Stack.

That is to dedup the data. One objection might be, we don't know the identity function for all given data, i.e. how do we know two elements are equal.

In Victory we already assume the identity of the data:

const x1 = isDate ? datum._x.getTime() : datum._x;

We can dedup the elements and removing duplicate instances from the stack.

Fixes #2883 or rather addresses it.

Type of Change

  • 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 not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Manually and adding jest test for testing the dedup logic.

Manually

Before

Screenshot 2024-09-13 at 14 21 57

After

Screenshot 2024-09-13 at 14 22 43

Jest

Created a new suite to mock almost all calls out, expect for the fillData function that has been modified.

Checklist: (Feel free to delete this section upon completion)

  • I have included a changeset if this change will require a version change to one of the packages.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have run all builds, tests, and linting and all checks pass
  • I have added tests that prove my fix is effective or that my feature works
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Copy link

vercel bot commented Sep 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
victory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 13, 2024 1:30pm

Copy link

changeset-bot bot commented Sep 12, 2024

🦋 Changeset detected

Latest commit: 48fd666

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
victory-stack Patch
victory-native Patch
victory Patch
victory-area Patch
victory-axis Patch
victory-bar Patch
victory-box-plot Patch
victory-brush-container Patch
victory-brush-line Patch
victory-candlestick Patch
victory-canvas Patch
victory-chart Patch
victory-core Patch
victory-create-container Patch
victory-cursor-container Patch
victory-errorbar Patch
victory-group Patch
victory-histogram Patch
victory-legend Patch
victory-line Patch
victory-pie Patch
victory-polar-axis Patch
victory-scatter Patch
victory-selection-container Patch
victory-shared-events Patch
victory-tooltip Patch
victory-vendor Patch
victory-voronoi-container Patch
victory-voronoi Patch
victory-zoom-container Patch
victory-docs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@r281GQ r281GQ changed the title fix: dedup elements fix: dedup data for <VictoryStack/> Sep 12, 2024
@r281GQ r281GQ changed the title fix: dedup data for <VictoryStack/> WIP - fix: dedup data for <VictoryStack/> Sep 12, 2024
@r281GQ r281GQ changed the title WIP - fix: dedup data for <VictoryStack/> fix: dedup data for <VictoryStack/> Sep 13, 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.

VictoryStack not displaying area if there is same time point at start.
1 participant