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


##########
superset-frontend/plugins/preset-chart-deckgl/src/utils/addColor.ts:
##########
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  CategoricalColorNamespace,
+  JsonObject,
+  QueryFormData,
+} from '@superset-ui/core';
+import { hexToRGB } from './colors';
+import { ColorBreakpointType } from '../types';
+import { COLOR_SCHEME_TYPES, ColorSchemeType } from '../utilities/utils';
+import { DEFAULT_DECKGL_COLOR } from '../utilities/Shared_DeckGL';
+
+const { getScale } = CategoricalColorNamespace;
+
+/**
+ * Resolve the per-feature color for a deck.gl layer based on the form data's
+ * color scheme configuration. This mirrors the categorical/fixed/breakpoint
+ * color logic that `CategoricalDeckGLContainer` applies when a layer is
+ * rendered on its own, so that it can be reused when layers are composed
+ * inside the deck.gl Multiple Layers chart.
+ *
+ * Features whose color scheme is not recognized are returned unchanged so the
+ * layer's own fallback color logic can take over.
+ */
+export function addColorToFeatures(
+  data: JsonObject[],
+  fd: QueryFormData,
+  selectedColorScheme: ColorSchemeType = fd.color_scheme_type,
+): JsonObject[] {
+  const appliedScheme = fd.color_scheme;
+  const colorFn = getScale(appliedScheme);
+
+  switch (selectedColorScheme) {
+    case COLOR_SCHEME_TYPES.fixed_color: {
+      const color = fd.color_picker || { r: 0, g: 0, b: 0, a: 1 };
+      const colorArray = [color.r, color.g, color.b, color.a * 255];
+
+      return data.map(d => ({ ...d, color: colorArray }));
+    }
+    case COLOR_SCHEME_TYPES.categorical_palette: {
+      if (!fd.dimension) {
+        const fallbackColor = fd.color_picker || { r: 0, g: 0, b: 0, a: 1 };
+        const colorArray = [
+          fallbackColor.r,
+          fallbackColor.g,
+          fallbackColor.b,
+          fallbackColor.a * 255,
+        ];
+        return data.map(d => ({ ...d, color: colorArray }));
+      }
+
+      return data.map(d => ({
+        ...d,
+        color: hexToRGB(colorFn(d.cat_color, fd.slice_id)),

Review Comment:
   **Suggestion:** The categorical color lookup now uses `fd.slice_id`, but the 
existing legend/category path in `CategoricalDeckGLContainer` still keys color 
resolution with `fd.sliceId`. This mixed key usage can split color resolution 
across different slice namespaces (or pass `undefined` on one side), causing 
legend colors and rendered feature colors to diverge in some contexts. Use a 
single normalized slice id source (e.g., resolve once from `fd.slice_id ?? 
fd.sliceId`) everywhere colors are computed. [inconsistent naming]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Standalone deck.gl scatter legends may use mismatched color scope.
   - ⚠️ Category colors can differ between legend and scatter points.
   - ⚠️ Deck.gl path/arc charts risk similar legend mismatches.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Note that per-feature categorical colors for deck.gl layers are resolved 
in
   `addColorToFeatures` at
   `superset-frontend/plugins/preset-chart-deckgl/src/utils/addColor.ts:56-72`, 
where the
   categorical branch calls `hexToRGB(colorFn(d.cat_color, fd.slice_id))`, 
explicitly keying
   the color scale with `fd.slice_id`.
   
   2. Observe that the legend/category colors for standalone categorical 
deck.gl charts are
   computed in `getCategories` within `CategoricalDeckGLContainer` at
   
`superset-frontend/plugins/preset-chart-deckgl/src/CategoricalDeckGLContainer.tsx:58-80`,
   where the same `colorFn` is called as `hexToRGB(colorFn(d.cat_color, 
fd.sliceId), c.a *
   255)`, using `fd.sliceId` (camelCase) instead of `fd.slice_id`.
   
   3. See how standalone deck.gl scatter/path/arc charts are wired:
   `createCategoricalDeckGLComponent` in
   `superset-frontend/plugins/preset-chart-deckgl/src/factory.tsx:220-257` 
passes the
   `QueryFormData` verbatim as `formData` into `CategoricalDeckGLContainer`, so 
the legend
   path uses `fd.sliceId` while the feature-color path uses `fd.slice_id` on 
the same
   `formData` object.
   
   4. Confirm that deck.gl form data commonly carries `slice_id` and not 
`sliceId` by
   inspecting tests: `addColor.test.ts` at
   
`superset-frontend/plugins/preset-chart-deckgl/src/utils/addColor.test.ts:28-36`
 builds
   `QueryFormData` with `slice_id: 1`, and `Multi.color.test.tsx` at
   
`superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx:71-80`
 sets
   `slice_id: SCATTER_SLICE_ID` in `form_data` but never `sliceId`. In this 
shape,
   `addColorToFeatures` will call `colorFn(cat_color, 1)` while `getCategories` 
calls
   `colorFn(cat_color, undefined)`, splitting the categorical color scale 
across two slice
   namespaces and allowing legend swatch colors to diverge from the per-feature 
colors.
   Normalizing to a single slice identifier (e.g. `const sliceId = fd.slice_id 
??
   fd.sliceId`) in all colorFn calls would remove this inconsistency.
   ```
   </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=f8d4a4aefdfe4c479d2a79599da52c01&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=f8d4a4aefdfe4c479d2a79599da52c01&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/preset-chart-deckgl/src/utils/addColor.ts
   **Line:** 70:70
   **Comment:**
        *Inconsistent Naming: The categorical color lookup now uses 
`fd.slice_id`, but the existing legend/category path in 
`CategoricalDeckGLContainer` still keys color resolution with `fd.sliceId`. 
This mixed key usage can split color resolution across different slice 
namespaces (or pass `undefined` on one side), causing legend colors and 
rendered feature colors to diverge in some contexts. Use a single normalized 
slice id source (e.g., resolve once from `fd.slice_id ?? fd.sliceId`) 
everywhere colors are computed.
   
   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%2F41490&comment_hash=b7d57706a9c359b055cc7e787e0adf591a4efc2fbf407769d344d9e563bed5a8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=b7d57706a9c359b055cc7e787e0adf591a4efc2fbf407769d344d9e563bed5a8&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