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


##########
superset-frontend/plugins/legacy-plugin-chart-map-box/src/ScatterPlotGlowOverlay.tsx:
##########
@@ -181,13 +185,13 @@ class ScatterPlotGlowOverlay extends 
PureComponent<ScatterPlotGlowOverlayProps>
       }
     });
 
-    const filteredLabels = clusterLabelMap.filter(
-      v => !Number.isNaN(v),
-    ) as number[];
-    // Guard against empty array or zero max to prevent NaN from division
-    const maxLabel =
-      filteredLabels.length > 0 ? Math.max(...filteredLabels) : 1;
-    const safeMaxLabel = maxLabel > 0 ? maxLabel : 1;
+    const finiteClusterLabels = clusterLabelMap
+      .map(value => Number(value))
+      .filter(value => Number.isFinite(value));
+    const safeMaxAbsLabel =
+      finiteClusterLabels.length > 0
+        ? Math.max(...finiteClusterLabels.map(value => Math.abs(value)))
+        : 1;

Review Comment:
   **Suggestion:** `safeMaxAbsLabel` can still become `0` when all finite 
cluster labels are zero, so `Math.abs(safeNumericLabel) / safeMaxAbsLabel` 
evaluates to `0/0` and produces `NaN`, which then propagates into 
`scaledRadius` and breaks cluster rendering. Ensure the computed max magnitude 
is clamped to at least `1` before using it as a divisor. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ MapBox zero-valued clusters render with NaN radius, disappear.
   - ⚠️ Cluster density perception breaks for custom-metric dashboards.
   ```
   </details>
   
   ```suggestion
       const finiteClusterLabels = clusterLabelMap
             .map(value => Number(value))
             .filter(value => Number.isFinite(value));
           const maxAbsLabel =
             finiteClusterLabels.length > 0
               ? Math.max(...finiteClusterLabels.map(value => Math.abs(value)))
               : 0;
           const safeMaxAbsLabel = maxAbsLabel > 0 ? maxAbsLabel : 1;
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open a MapBox visualization in Superset UI (plugin is registered in
   `superset-frontend/src/visualizations/presets/MainPreset.ts:134` via `new
   MapBoxChartPlugin().configure({ key: VizType.MapBox })`).
   
   2. In MapBox control panel, enable custom metric labeling with aggregator 
`sum`
   (configured at
   
`superset-frontend/plugins/legacy-plugin-chart-map-box/src/controlPanel.ts:168-173`)
 and
   use data where clustered metric values evaluate to `0` for all visible 
clusters.
   
   3. Render path executes `transformProps()` 
(`.../transformProps.ts:59-75,120`) -> `MapBox`
   passes `aggregation` to overlay (`.../MapBox.tsx:221-232`) -> 
`computeClusterLabel()`
   returns zero cluster labels for `sum` 
(`.../ScatterPlotGlowOverlay.tsx:87-89`).
   
   4. In `redraw()`, `safeMaxAbsLabel` becomes `0` when all finite labels are 
zero
   (`.../ScatterPlotGlowOverlay.tsx:188-194`), then `ratio = 
Math.abs(safeNumericLabel) /
   safeMaxAbsLabel` (`:253`) evaluates `0/0`, producing `NaN`, which propagates 
to
   `scaledRadius` (`:254-256`) and then into `ctx.arc(... scaledRadius ...)` 
(`:277-283`),
   causing invalid/invisible cluster bubbles.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/legacy-plugin-chart-map-box/src/ScatterPlotGlowOverlay.tsx
   **Line:** 188:194
   **Comment:**
        *Logic Error: `safeMaxAbsLabel` can still become `0` when all finite 
cluster labels are zero, so `Math.abs(safeNumericLabel) / safeMaxAbsLabel` 
evaluates to `0/0` and produces `NaN`, which then propagates into 
`scaledRadius` and breaks cluster rendering. Ensure the computed max magnitude 
is clamped to at least `1` before using it as a divisor.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38458&comment_hash=65b8de1e87c048869905ffbad989f85d057af89eafeda10a9e9f9200ce4c400d&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38458&comment_hash=65b8de1e87c048869905ffbad989f85d057af89eafeda10a9e9f9200ce4c400d&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