fix: dedup data for <VictoryStack/>
#2898
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
We can dedup the elements and removing duplicate instances from the stack.
Fixes #2883 or rather addresses it.
Type of Change
How Has This Been Tested?
Manually and adding jest test for testing the dedup logic.
Manually
Before
After
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)