codeant-ai-for-open-source[bot] commented on code in PR #41859:
URL: https://github.com/apache/superset/pull/41859#discussion_r3544437705
##########
superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx:
##########
@@ -63,6 +70,60 @@ const {
yAxisIndex,
} = DEFAULT_FORM_DATA;
+function hasBarSeriesInState(state: ControlPanelState | null): boolean {
+ const formData = state?.form_data;
+ const seriesA =
+ state?.controls?.seriesType?.value ?? formData?.seriesType ?? seriesType;
+ const seriesB =
+ state?.controls?.seriesTypeB?.value ?? formData?.seriesTypeB ?? seriesType;
+ return (
+ seriesA === EchartsTimeseriesSeriesType.Bar ||
+ seriesB === EchartsTimeseriesSeriesType.Bar
+ );
+}
+
+function isNumericXAxisState(state: ControlPanelState | null): boolean {
+ return checkColumnType(
+ getColumnLabel(state?.controls?.x_axis?.value as QueryFormColumn),
+ state?.controls?.datasource?.datasource,
+ [GenericDataType.Numeric],
+ );
+}
+
+const mixedXAxisForceCategoricalControl = {
+ ...xAxisForceCategoricalControl,
+ config: {
+ ...xAxisForceCategoricalControl.config,
+ description: t(
+ 'Treat values as categorical. Enabled by default when any query uses bar
series to prevent bar overflow and intermediate tick labels. Disable to use a
continuous numeric x-axis that preserves spacing for missing values.',
+ ),
+ initialValue: (control: ControlState, state: ControlPanelState | null) => {
+ if (!isNumericXAxisState(state)) {
+ return control.value;
+ }
+ if (state?.form_data?.x_axis_sort !== undefined) {
+ return true;
+ }
+ if (control?.value !== undefined) {
+ return control.value;
+ }
+ return hasBarSeriesInState(state);
Review Comment:
**Suggestion:** The defaulting logic is gated to numeric x-axes, so mixed
charts with bar series on temporal x-axes fall back to the base default instead
of auto-enabling categorical mode. This breaks the intended “bar series
defaults to categorical” behavior for mixed charts; the bar-series default
decision should not be skipped for non-numeric x-axes. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ MixedTimeseries bar charts on time axis stay continuous.
- ⚠️ Intended bar default-to-categorical behavior not applied.
- ⚠️ Users must manually toggle categorical for temporal x-axis.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. In
`plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx:93-113`, note
`mixedXAxisForceCategoricalControl.config.initialValue`:
- It calls `isNumericXAxisState(state)` (lines 85-90), which uses
`checkColumnType`
with `[GenericDataType.Numeric]`.
- If the x-axis column is not numeric, it returns `control.value`
immediately (line
102), bypassing both the `x_axis_sort` check and
`hasBarSeriesInState(state)` (line
110).
2. For a MixedTimeseries chart with a temporal x-axis, `checkColumnType`
returns false for
the time column, so `isNumericXAxisState(state)` is false and `initialValue`
returns
`control.value` (line 102). On a new chart, `control.value` comes from the
base control
definition at
`packages/superset-ui-chart-controls/src/shared-controls/customControls.tsx:15-21`,
where
`xAxisForceCategoricalControl.config.default` is `false`.
3. Create a MixedTimeseries chart using this control panel (registered in
`plugins/plugin-chart-echarts/src/MixedTimeseries/index.ts:34-52` as
`controlPanel`). Set
Query A`s series type to `Bar` via `seriesType` in `createCustomizeSection`
at
`MixedTimeseries/controlPanel.tsx:203-223`. Despite having a bar series, the
early
non-numeric return means `xAxisForceCategorical` stays at its default
`false` for temporal
x-axes.
4. In
`plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts:120-153`,
form
data (including `xAxisForceCategorical`) and column types are read:
- `xAxisDataType` is computed from `getColtypesMapping` (lines 150-152)
and is
`GenericDataType.Temporal` for a time column.
- `xAxisType` is computed by `getAxisType(stack, xAxisForceCategorical,
xAxisDataType)`
(line 152), implemented in
`plugins/plugin-chart-echarts/src/utils/series.ts:14-28`.
With `forceCategorical=false` and `dataType=Temporal`, `getAxisType`
returns
`AxisType.Time`, not `AxisType.Category`.
As a result, MixedTimeseries bar charts on temporal x-axes default to a
time axis
instead of categorical, contradicting the PR’s stated intent that “bar
charts default
to categorical via chart control panels” and “Mixed Time-Series chart:
default Force
categorical to true when Query A or Query B uses a bar series.”
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e54e721955384126be8616149503d30a&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=e54e721955384126be8616149503d30a&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/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
**Line:** 101:110
**Comment:**
*Logic Error: The defaulting logic is gated to numeric x-axes, so mixed
charts with bar series on temporal x-axes fall back to the base default instead
of auto-enabling categorical mode. This breaks the intended “bar series
defaults to categorical” behavior for mixed charts; the bar-series default
decision should not be skipped for non-numeric x-axes.
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%2F41859&comment_hash=9f23f546a664eacc319d0b21fba5931e7f60c51f11d8606b67d5265fcbde3a5b&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41859&comment_hash=9f23f546a664eacc319d0b21fba5931e7f60c51f11d8606b67d5265fcbde3a5b&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]