codeant-ai-for-open-source[bot] commented on code in PR #41490: URL: https://github.com/apache/superset/pull/41490#discussion_r3485865590
########## 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:** In the categorical-palette branch, the resolved color is generated without applying the configured `color_picker` alpha, so points become fully opaque (`255`) even when the chart opacity is set lower. This regresses behavior compared to the existing legend/category logic and causes visual mismatch; pass the configured alpha (scaled to 0-255) into the hex-to-RGBA conversion when resolving categorical colors. [logic error] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx ❌ Multiple Layers scatter points ignore configured opacity alpha. ⚠️ Legend uses opacity; map points always fully opaque. ⚠️ Users experience misleading opacity in deck.gl charts. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Configure a deck.gl Scatterplot slice with a categorical palette and a non-opaque point color: in the UI set `Point Color` to a categorical palette over some dimension and choose a color with alpha < 1 (this becomes `formData.color_scheme_type = COLOR_SCHEME_TYPES.categorical_palette`, `formData.dimension` truthy, and `formData.color_picker.a < 1` in the `QueryFormData` passed to the plugin). 2. Render that slice either standalone or inside a Multiple Layers chart: for standalone scatter, `createCategoricalDeckGLComponent` in `superset-frontend/plugins/preset-chart-deckgl/src/factory.tsx:21-59` wraps it in `CategoricalDeckGLContainer`; for Multiple Layers, `DeckMulti` in `superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx:119-119` is used. 3. During rendering of the Multiple Layers chart, `DeckMulti.createLayerFromData` at `superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx:240-258` detects a color-aware layer (`subsliceFormData.viz_type === 'deck_scatter'` and `subsliceFormData.color_scheme_type` set) and rewrites the payload with per-feature colors via `features: addColorToFeatures(json.data.features, subsliceFormData)`. 4. Inside `addColorToFeatures` in `superset-frontend/plugins/preset-chart-deckgl/src/utils/addColor.ts:41-72`, the `COLOR_SCHEME_TYPES.categorical_palette` branch with a dimension set falls through to `return data.map(d => ({ ...d, color: hexToRGB(colorFn(d.cat_color, fd.slice_id)), }))` (lines 68-71). `hexToRGB` in `superset-frontend/plugins/preset-chart-deckgl/src/utils/colors.ts:22-31` defaults its `alpha` parameter to `255` when no value is passed, so each feature’s RGBA color ends with `255` regardless of `fd.color_picker.a`. Meanwhile the legend categories are built in `getCategories` at `superset-frontend/plugins/preset-chart-deckgl/src/CategoricalDeckGLContainer.tsx:58-75`, which calls `hexToRGB(colorFn(d.cat_color, fd.slice_id), c.a * 255)` and therefore respects the configured alpha. When you view the chart, legend swatches appear semi-transparent (using `color_picker.a`) but points on the map are fully opaque (`alpha = 255`), demonstrating the visual mismatch caused by dropping the configured opacity in the categorical feature colors. ``` </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0184f09e42a147bf86a4b285563add28&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0184f09e42a147bf86a4b285563add28&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:** 68:71 **Comment:** *Logic Error: In the categorical-palette branch, the resolved color is generated without applying the configured `color_picker` alpha, so points become fully opaque (`255`) even when the chart opacity is set lower. This regresses behavior compared to the existing legend/category logic and causes visual mismatch; pass the configured alpha (scaled to 0-255) into the hex-to-RGBA conversion when resolving categorical colors. 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=ecc9fe01a2f3c9062f20d6d0ba0cc9ac10e30be98320a24219fe6dad5fb1c595&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=ecc9fe01a2f3c9062f20d6d0ba0cc9ac10e30be98320a24219fe6dad5fb1c595&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]
