rusackas commented on code in PR #42300:
URL: https://github.com/apache/superset/pull/42300#discussion_r3680919964


##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:
##########
@@ -724,6 +724,41 @@ export default function transformProps(
     }
   }
 
+  // Whenever a Y axis bound is defined, whether explicitly configured or
+  // derived above from the data, clamp series values to those bounds
+  // instead of leaving raw out-of-range values in place. ECharts axis
+  // clipping can otherwise drop an out-of-bounds point (and the line
+  // segments around it) entirely rather than truncating it at the
+  // boundary (see https://github.com/apache/superset/issues/27449).
+  if (yAxisMin !== undefined || yAxisMax !== undefined) {
+    const valueIndex = isHorizontal ? 0 : 1;
+    const clampAxisValue = (
+      value: string | number | null | undefined,
+    ): string | number | null | undefined => {
+      if (typeof value !== 'number' || Number.isNaN(value)) return value;
+      let clamped = value;
+      if (yAxisMin !== undefined) clamped = Math.max(clamped, yAxisMin);
+      if (yAxisMax !== undefined) clamped = Math.min(clamped, yAxisMax);
+      return clamped;
+    };
+    series.forEach(s => {
+      if (!Array.isArray(s.data)) return;
+      const clampedData = (
+        s.data as (string | number | null | undefined)[][]
+      ).map(point => {
+        if (Array.isArray(point)) {
+          const newPoint = [...point];
+          newPoint[valueIndex] = clampAxisValue(newPoint[valueIndex]);
+          return newPoint;
+        }
+        return point;
+      });
+      // Matches the existing pattern used elsewhere in this file for
+      // narrowing the broad, union-typed ECharts `SeriesOption.data` field.
+      (s as any).data = clampedData;
+    });

Review Comment:
   Good catch, fixed. colorByPrimaryAxis (and the negative-bar label wrapping) 
puts points in `{ value: [x, y], ... }` objects instead of bare tuples, so 
those were skipping the clamp entirely. Extended it to handle both shapes and 
dropped the `any` cast while I was in there.



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