codeant-ai-for-open-source[bot] commented on code in PR #36214:
URL: https://github.com/apache/superset/pull/36214#discussion_r3651879510


##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:
##########
@@ -535,6 +558,37 @@ export default function transformProps(
     }
   });
 
+  // ----- ensure series data are sorted naturally on the x-value -----
+  // Run after all series have been created so each series.data is complete.
+  series.forEach((s: SeriesOption) => {
+    const dataArr = (s as any).data;
+    if (!Array.isArray(dataArr) || dataArr.length <= 1) return;
+
+    (s as any).data = dataArr.sort((row1: any, row2: any) => {
+      // extract the raw x values (support both [x,y] and { x, y } shapes)
+      const rawX1 = Array.isArray(row1) ? row1[0] : row1?.x;
+      const rawX2 = Array.isArray(row2) ? row2[0] : row2?.x;

Review Comment:
   **Suggestion:** The sort key extraction does not handle standard ECharts 
object data items whose coordinates are stored under `value`, such as `{ value: 
[x, y] }`. For those points both `rawX1` and `rawX2` become `undefined`, so 
every comparison returns equality and the data remains unordered, leaving the 
reported x-axis ordering bug unfixed for object-shaped series data. [logic 
error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Object-shaped ECharts series remain unsorted.
   - ❌ Numeric-like x-axis charts can draw non-adjacent connections.
   - ⚠️ Affected output is limited to series using `value` objects.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Render a timeseries through `transformProps()` in
   
`superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts`;
 the
   function builds each ECharts series before the sorting pass at lines 561-563.
   
   2. Provide a series whose ECharts data items use the standard object form `{ 
value: [x, y]
   }`, rather than tuple data or `{ x, y }` objects. The sorting pass at lines 
563-567 still
   processes this data because it sorts every array-valued `series.data`.
   
   3. For each item, lines 568-570 evaluate `Array.isArray(row)` as false and 
read `row.x`.
   Since the x-coordinate is actually under `row.value[0]`, both `rawX1` and 
`rawX2` are
   `undefined`.
   
   4. The comparator at lines 584-588 therefore calls 
`naturalCompare(undefined, undefined)`,
   which returns `0` at line 188. The original order is preserved, so 
numeric-like or string
   x-values remain incorrectly ordered for these object-shaped series.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=53a0a1a4296749acbaf34618ac402a94&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=53a0a1a4296749acbaf34618ac402a94&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:** 567:570
   **Comment:**
        *Logic Error: The sort key extraction does not handle standard ECharts 
object data items whose coordinates are stored under `value`, such as `{ value: 
[x, y] }`. For those points both `rawX1` and `rawX2` become `undefined`, so 
every comparison returns equality and the data remains unordered, leaving the 
reported x-axis ordering bug unfixed for object-shaped series data.
   
   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=b1ed926d434bf43c1ee5afa501d52b109df63a8165250d7fc04acf7bff762ae8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F36214&comment_hash=b1ed926d434bf43c1ee5afa501d52b109df63a8165250d7fc04acf7bff762ae8&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]

Reply via email to