bito-code-review[bot] commented on code in PR #36214:
URL: https://github.com/apache/superset/pull/36214#discussion_r4078314238
##########
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;
+ }
+
+ // Otherwise fallback to lexicographic
+ return sa.localeCompare(sb);
+}
Review Comment:
<!-- Bito Reply -->
The user's update addresses the reviewer's concern by providing test
coverage for the `naturalCompare` helper. This addition is appropriate as it
ensures the new sorting logic is verified for numeric-like strings,
object-shape cases, and BigInt precision, while confirming that existing
Time/Bar axis behavior remains unaffected.
--
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]