bito-code-review[bot] commented on code in PR #36214:
URL: https://github.com/apache/superset/pull/36214#discussion_r3654989208


##########
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:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing tests for natural sort</b></div>
   <div id="fix">
   
   The `naturalCompare` helper (lines 183-202) and its application in series 
sorting (lines 561-590) have no test coverage. Add tests that verify sorting 
behavior with mixed numeric/string x-values and both data array formats.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #d395dd</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to