-
Notifications
You must be signed in to change notification settings - Fork 28
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
Match structure of all data points so each DataSeries contain the same keys #1600
Conversation
size-limit report 📦
|
67d0342
to
8ecfc59
Compare
]); | ||
}); | ||
|
||
it('loops through a large data set in less than 10ms', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is even worth testing, but the original implementation below would get between 80
and 100ms
. The new implementation gets around 4ms
.
for (const {data} of dataSeries) {
for (const {key} of data) {
allKeys.add(`${key}`);
}
}
return dataSeries.map(({name, data}) => ({
name,
data: [...allKeys].map((key) => {
const matchedValue = data.find((item) => item.key === key);
return matchedValue ? matchedValue : {key, value: null};
}),
}));
const areAnyDataLengthsDifferent = dataSeries.some( | ||
({data}) => data.length !== dataSeries[0].data.length, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on this check to see if we need to fill in missing points is going to miss cases where the dataSeries
is the same length but the keys
are different. I think we'll want to check that the key
s are the same across each series instead
e.g. This is a valid case where we'd want to continue but would early return
{
name: 'Canada',
data: [
{key: 'Cats', value: 6.64},
{key: 'Birds', value: 54.47},
],
},
{
name: 'United States',
data: [
{key: 'Lizards', value: 350.13},
{key: 'Turtles', value: 223.43},
],
},
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I thought about that but I'm not sure how often we'd hit this case.
I was originally doing an equality check on the next array in this .some()
but it adds about 10ms onto the time.
I wonder if we should just always run the code and not try and bail early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just always run the code and not try and bail early.
Agreed, probably worth just running it every time. Looking for extraneous keys would be a hard one to check too
{
name: 'Canada',
data: [
{key: 'Cats', value: 6.64},
{key: 'Birds', value: 54.47},
],
},
{
name: 'United States',
data: [
{key: 'Cats', value: 350.13},
{key: 'Birds', value: 223.43},
{key: 'Snakes', value: 100.00},
],
},
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm ... I always just assume if there is a data edge case there are going to be merchant out there that are going to see it 🤷♀️
I'm team lets not bail early and we can always come back and optimize it later. Curious what others think tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I removed the early bailout
…hing data structures
160a053
to
0e54a1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 🚀
What does this implement/fix?
https://6062ad4a2d14cd0021539c1b-jcjslbrrgq.chromatic.com/?path=/story/polaris-viz-charts-barchart-playground--mis-matched-data
Now that we're allowing consumers to create any type of report we were running into an issue where data being fed into
BarChart
didn't have the same data between each DataSeries, which would cause the chart to crash.For example, data would come in like:
Now we're going to fill all the data so each
DataSeries
has key/values that match the entire data set, not just the singleDataSeries
itself.