bito-code-review[bot] commented on code in PR #35859:
URL: https://github.com/apache/superset/pull/35859#discussion_r2890004152
##########
superset-frontend/plugins/legacy-plugin-chart-country-map/src/CountryMap.ts:
##########
@@ -63,33 +63,46 @@ interface CountryMapProps {
numberFormat: string;
colorScheme: string;
sliceId: number;
+ onContextMenu?: (clientX: number, clientY: number, data: any) => void;
+ emitCrossFilters?: boolean;
+ setDataMask?: (dataMask: any) => void;
+ filterState?: {
+ selectedValues?: string[];
+ extraFormData?: {
+ filters?: any[];
+ };
+ };
+ entity?: string;
}
const maps: Record<string, GeoData> = {};
+// Store zoom state per chart instance using element as key to enable garbage
collection
+const zoomStates = new WeakMap<HTMLElement, { scale: number; translate:
[number, number] }>();
function CountryMap(element: HTMLElement, props: CountryMapProps) {
const {
data,
width,
height,
country,
+ entity,
linearColorScheme,
numberFormat,
colorScheme,
sliceId,
+ filterState,
+ emitCrossFilters,
+ onContextMenu,
+ setDataMask,
} = props;
const container = element;
const format = getNumberFormatter(numberFormat);
- const rawExtents = d3Extent(data, v => v.metric);
- const extents: [number, number] =
- rawExtents[0] != null && rawExtents[1] != null
- ? [rawExtents[0], rawExtents[1]]
- : [0, 1];
- const colorSchemeObj = getSequentialSchemeRegistry().get(linearColorScheme);
- const linearColorScale = colorSchemeObj
- ? colorSchemeObj.createLinearScale(extents)
- : () => '#ccc'; // fallback if scheme not found
+
+ const linearColorScale = getSequentialSchemeRegistry()
+ .get(linearColorScheme)
+ .createLinearScale(d3Extent(data, v => v.metric));
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Fix potential runtime error in linearColorScale</b></div>
<div id="fix">
The linearColorScale creation lacks checks for when the color scheme is not
found or data is empty, potentially causing runtime errors. The previous code
had safeguards; restoring them prevents crashes and maintains fallback behavior.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
const rawExtents = d3Extent(data, v => v.metric);
const extents: [number, number] =
rawExtents[0] != null && rawExtents[1] != null
? [rawExtents[0], rawExtents[1]]
: [0, 1];
const colorSchemeObj =
getSequentialSchemeRegistry().get(linearColorScheme);
const linearColorScale = colorSchemeObj
? colorSchemeObj.createLinearScale(extents)
: () => '#ccc'; // fallback if scheme not found
````
</div>
</details>
</div>
<small><i>Code Review Run #84b1f0</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]