codeant-ai-for-open-source[bot] commented on code in PR #26230:
URL: https://github.com/apache/superset/pull/26230#discussion_r3540427311
##########
superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.ts:
##########
@@ -98,10 +104,9 @@ function Calendar(element: HTMLElement, props:
CalendarProps) {
calContainer.text(`${METRIC_TEXT}: ${verboseMap[metric] || metric}`);
}
const timestamps = metricsData[metric];
- const rawExtents = d3Extent(
- Object.keys(timestamps),
- key => timestamps[key],
- );
+ const rawExtents = useCustomColorRange
+ ? ([colorRangeStart, colorRangeEnd] as [number, number])
+ : d3Extent(Object.keys(timestamps), key => timestamps[key]);
Review Comment:
**Suggestion:** The custom range is used directly without validating or
normalizing bound order. If users enter a start greater than end, the generated
legend thresholds become descending, which breaks threshold-based bucket
assignment and produces incorrect cell colors. Normalize bounds (swap when
start > end) or reject invalid ranges before building legend values. [incorrect
condition logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Calendar Heatmap miscolors cells for reversed custom range.
- ⚠️ Legend thresholds appear inverted, confusing chart interpretation.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Create or edit a "Calendar Heatmap" chart in the Superset Explore UI,
which uses
CalendarChartPlugin registered in
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/index.ts:49-56`.
2. In the chart’s "Chart Options" section defined in
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts:81-172`,
set
"Color Range Start" to a value greater than "Color Range End" (for example
start=10,
end=5) using the controls at lines 141-171.
3. When the chart runs, `transformProps()` in
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/transformProps.ts:23-50`
reads
`colorRangeStart` and `colorRangeEnd` from `formData` and computes
`useCustomColorRange`
as true at lines 47-49 because both bounds are finite numbers.
4. The `Calendar` renderer in
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/Calendar.ts:101-124`
constructs `rawExtents` as `[colorRangeStart, colorRangeEnd]` at lines
107-109, yielding
`extents` with start>end, a negative `step` at line 116, and a descending
`legend` array
at line 122; these thresholds are passed into `CalHeatMap.init()` at lines
125-154,
producing a legend and cell coloring that no longer match the intended
numeric range
(colors appear inverted or inconsistent relative to values).
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=91715ae34050419a87f9f442cbd0bbfb&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=91715ae34050419a87f9f442cbd0bbfb&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/legacy-plugin-chart-calendar/src/Calendar.ts
**Line:** 107:109
**Comment:**
*Incorrect Condition Logic: The custom range is used directly without
validating or normalizing bound order. If users enter a start greater than end,
the generated legend thresholds become descending, which breaks threshold-based
bucket assignment and produces incorrect cell colors. Normalize bounds (swap
when start > end) or reject invalid ranges before building legend values.
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%2F26230&comment_hash=663d1612b9cca1b069f927611cff92d0b7565d31c780568da2a17c800a65b474&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F26230&comment_hash=663d1612b9cca1b069f927611cff92d0b7565d31c780568da2a17c800a65b474&reaction=dislike'>👎</a>
##########
superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts:
##########
@@ -136,6 +136,40 @@ const config: ControlPanelConfig = {
},
},
],
+ [
+ {
+ name: 'color_range_start',
+ config: {
+ type: 'TextControl',
+ isInt: true,
+ validators: [legacyValidateInteger],
Review Comment:
**Suggestion:** Both custom color-range controls are restricted to integers,
so users cannot set decimal bounds even though metric values are often
floating-point; this makes fixed ranges inaccurate or unusable for many
datasets. Use numeric/float validation instead of integer-only validation for
these fields. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Calendar Heatmap cannot use decimal color range bounds.
- ⚠️ Fixed color scaling inaccurate for floating-point metric values.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open an existing "Calendar Heatmap" chart in Superset’s Explore view;
this chart uses
CalendarChartPlugin defined in
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/index.ts:49-56`.
2. In the "Chart Options" section configured at
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts:81-172`,
attempt to enter decimal values (for example `0.5` and `1.5`) into the
"Color Range Start"
and "Color Range End" fields whose configs at lines 141-171 use
`TextControl` with `isInt:
true` and `legacyValidateInteger`.
3. Because `isInt: true` and `legacyValidateInteger` enforce integer-only
input,
non-integer bounds are rejected or must be rounded to integers, so the
resulting
`formData.colorRangeStart` and `formData.colorRangeEnd` cannot represent the
desired
decimal range for metrics with fractional values.
4. `transformProps()` in
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/transformProps.ts:23-50`
then
evaluates `useCustomColorRange` via `Number.isFinite(colorRangeStart)` and
`Number.isFinite(colorRangeEnd)` at lines 47-49; with decimal bounds
disallowed or
coerced, the heatmap either falls back to automatic data extents or uses an
imprecise
integer range, preventing accurate fixed color scaling for floating-point
metrics.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=33ce09714bbd410698f723b4d6eb1f3d&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=33ce09714bbd410698f723b4d6eb1f3d&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/legacy-plugin-chart-calendar/src/controlPanel.ts
**Line:** 141:145
**Comment:**
*Type Error: Both custom color-range controls are restricted to
integers, so users cannot set decimal bounds even though metric values are
often floating-point; this makes fixed ranges inaccurate or unusable for many
datasets. Use numeric/float validation instead of integer-only validation for
these fields.
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%2F26230&comment_hash=51f91a65522a5bbd6644108228e8534ce1f03f9a6b9ebf4e484d380c4d0b7a38&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F26230&comment_hash=51f91a65522a5bbd6644108228e8534ce1f03f9a6b9ebf4e484d380c4d0b7a38&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]