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


##########
superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.ts:
##########
@@ -95,11 +97,20 @@ function Calendar(element, props) {
       calContainer.text(`${METRIC_TEXT}: ${verboseMap[metric] || metric}`);
     }
     const timestamps = metricsData[metric];
-    const extents = d3Extent(Object.keys(timestamps), key => timestamps[key]);
-    const step = (extents[1] - extents[0]) / (steps - 1);
-    const colorScale = getSequentialSchemeRegistry()
-      .get(linearColorScheme)
-      .createLinearScale(extents);
+    const rawExtents = d3Extent(
+      Object.keys(timestamps),
+      key => timestamps[key],
+    );
+    // Guard against undefined extents (empty data)
+    const extents: [number, number] =
+      rawExtents[0] != null && rawExtents[1] != null
+        ? [rawExtents[0], rawExtents[1]]
+        : [0, 1];
+    const step = (extents[1] - extents[0]) / (steps - 1) || 0;
+    const colorScheme = getSequentialSchemeRegistry().get(linearColorScheme);
+    const colorScale = colorScheme
+      ? colorScheme.createLinearScale(extents)
+      : (v: number) => '#ccc'; // fallback if scheme not found
 
     const legend = d3Range(steps).map(i => extents[0] + step * i);

Review Comment:
   Fixed in 896b19737d. Added explicit guard: `steps > 1 ? (extents[1] - 
extents[0]) / (steps - 1) : 0` to prevent division by zero when steps is 1 or 
less.



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