TEMPLATE-564 filterInvalidDataPoints exclude Vensim sentinel values#308
TEMPLATE-564 filterInvalidDataPoints exclude Vensim sentinel values#308
filterInvalidDataPoints exclude Vensim sentinel values#308Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces robust handling for invalid data points such as NaN, Infinity, null, undefined, and Vensim sentinel values. A new isValidDataValue utility function and a filterInvalidDataPoints transformation have been added, and the logic for calculating chart extents has been updated to ignore these invalid values. The changes are well-supported by a comprehensive suite of new tests. The code is well-structured, and I have one suggestion to improve immutability and prevent potential side effects in the new data filtering function.
| return Object.assign(s, { | ||
| data: s.data.reduce(function (acum, datum) { | ||
| if (datum.y != null) { | ||
| acum.push(datum); | ||
| } | ||
|
|
||
| return acum; | ||
| }, []) | ||
| data: s.data.filter(function (datum) { | ||
| return isValidDataValue(datum.y); | ||
| }) | ||
| }); |
There was a problem hiding this comment.
This function mutates the series objects in the series array by using Object.assign(s, ...). While series.map creates a new array, the objects within it are references to the original series objects. Modifying them directly can lead to unexpected side effects in other parts of the application that might be using the original data. To ensure immutability, you should create a shallow copy of the series object before adding the filtered data.
| return Object.assign(s, { | |
| data: s.data.reduce(function (acum, datum) { | |
| if (datum.y != null) { | |
| acum.push(datum); | |
| } | |
| return acum; | |
| }, []) | |
| data: s.data.filter(function (datum) { | |
| return isValidDataValue(datum.y); | |
| }) | |
| }); | |
| return Object.assign({}, s, { | |
| data: s.data.filter(function (datum) { | |
| return isValidDataValue(datum.y); | |
| }) | |
| }); |
|
Hello @mpqmpqm! I'm here to help. It looks like you mentioned me, but didn't specify a command. If you'd like me to perform a code review, summarize the pull request, or need help with available commands, please use one of the following:
If you have a specific question or comment, please feel free to ask! |
Closes TEMPLATE-564.
Improves handling for invalid data values (
NaN,Infinity,null,undefinedand Vensim sentinel values) in line charts.