codeant-ai-for-open-source[bot] commented on code in PR #36214:
URL: https://github.com/apache/superset/pull/36214#discussion_r3652261751
##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:
##########
@@ -178,6 +178,29 @@ function getSymbolMarker(symbol: string, color: string) {
}
}
+// ----- natural sort helper -----
+// Try numeric comparison first for numeric-like strings, fallback to
localeCompare.
+function naturalCompare(a: any, b: any): number {
+ const sa = a === undefined || a === null ? '' : String(a);
+ const sb = b === undefined || b === null ? '' : String(b);
+
+ // Handle empty strings explicitly so they are not treated as 0
+ if (sa === '' && sb === '') return 0;
+ if (sa === '') return -1;
+ if (sb === '') return 1;
+
+ const na = Number(sa);
+ const nb = Number(sb);
+
+ // If both parse as finite numbers, do numeric sort
+ if (isFinite(na) && isFinite(nb)) {
+ return na - nb;
+ }
Review Comment:
**Suggestion:** The numeric conversion loses precision for numeric-like
dimension values larger than `Number.MAX_SAFE_INTEGER` (and for sufficiently
precise decimals). Distinct x-values can become equal after conversion, so the
comparator may preserve an incorrect order and render the line incorrectly. Use
a precision-safe comparison for integer-like strings instead of converting them
directly to `number`. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Large numeric-like dimension values can be ordered incorrectly.
- ⚠️ Timeseries lines may connect non-adjacent categories.
- ⚠️ Identifier-based x-axes can display misleading trends.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Render a Timeseries chart through the exported `transformProps()`
function in
`superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:204`,
with a series containing distinct numeric-like dimension values such as
`"9007199254740992"` and `"9007199254740993"`.
2. During the post-processing loop at `transformProps.ts:563-568`, the
series data is
sorted using `naturalCompare()`.
3. `naturalCompare()` converts both strings with `Number()` at
`transformProps.ts:192-193`; both values lose integer precision and become
the same
JavaScript number because they exceed `Number.MAX_SAFE_INTEGER`.
4. The comparator at `transformProps.ts:195-198` returns `0`, so the
distinct x-values are
treated as equal and their original order can be retained even when it is
numerically
incorrect, producing incorrectly connected line segments.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b73bbff0fd5444daa495cf77dfe7733d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b73bbff0fd5444daa495cf77dfe7733d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
**Line:** 195:198
**Comment:**
*Logic Error: The numeric conversion loses precision for numeric-like
dimension values larger than `Number.MAX_SAFE_INTEGER` (and for sufficiently
precise decimals). Distinct x-values can become equal after conversion, so the
comparator may preserve an incorrect order and render the line incorrectly. Use
a precision-safe comparison for integer-like strings instead of converting them
directly to `number`.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36214&comment_hash=723b48dfa930e020dbf29ec7a10e9679ab03ab5753e55abab2c65cb22a51de14&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36214&comment_hash=723b48dfa930e020dbf29ec7a10e9679ab03ab5753e55abab2c65cb22a51de14&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]