fix(echarts): allow forcing categorical x-axis for temporal columns#41221
fix(echarts): allow forcing categorical x-axis for temporal columns#41221rusackas wants to merge 3 commits into
Conversation
The "Force categorical" toggle (xAxisForceCategoricalControl) was only visible when the x-axis column was Numeric. Temporal x-axes default to a continuous time scale, where ECharts auto-places ticks at "nice" intervals that don't line up with the actual buckets, so weekly/monthly grain markers appear shifted away from their ticks (issue #28204). The transform layer already supports a categorical axis for temporal data; only the control's visibility gate blocked it. Expose the toggle for temporal columns too so users can opt into a discrete, tick-aligned axis. The numeric-only auto-force-when-sorted behavior in initialValue is left unchanged, so existing temporal charts keep their time scale unless the user opts in. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Code Review Agent Run #b5120dActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
The suggestion to replace Here is the corrected test snippet: const controls: ControlStateMapping = {
x_axis: { value: 'date_column' },
datasource: { datasource: {} },
};
const visible = xAxisForceCategoricalControl.config.visibility!({
controls,
});There are no other review comments on this pull request. Would you like me to perform any other checks? superset-frontend/packages/superset-ui-chart-controls/test/shared-controls/customControls.test.tsx |
…ests Use ControlPanelState / ControlStateMapping types instead of `any` to satisfy the no-any custom rule. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41221 +/- ##
=======================================
Coverage 64.36% 64.36%
=======================================
Files 2651 2651
Lines 144812 144812
Branches 33417 33417
=======================================
Hits 93208 93208
Misses 49935 49935
Partials 1669 1669
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ols test The single `as ControlPanelState` cast failed tsc because the partial state object does not sufficiently overlap with the full type. Mirror the visibility test and cast through `unknown`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Code Review Agent Run #7968a2Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
Fixes #28204
On a temporal x-axis (any chart using a time grain), Superset hands ECharts
xAxis.type: 'time', a continuous linear scale. Bars/points are placed at their exact timestamp, but ECharts auto-computes "nice" tick positions (month boundaries, even N-day divisions) that don't coincide with the actual buckets. With weekly grain this is very visible: a bucket startingNov 30renders right on top of theDectick, and 5 weekly bars can produce 8 misaligned ticks.Superset already has the right tool for this: the Force categorical toggle (
xAxisForceCategoricalControl), which switches the axis totype: 'category'so each bucket becomes a discrete, tick-aligned category. The transform layer already handles temporal data on a categorical axis (the date formatter is selected by column type, not axis type). The only thing blocking these users was the control'svisibilitygate, which only showed the toggle for Numeric x-axis columns.This PR expands that gate to include Temporal columns, so the toggle is exposed for time-grain charts. The numeric-only "auto-force when sorted" logic in
initialValueis untouched, so existing temporal charts keep their continuous time scale unless the user explicitly opts in (default staysfalse).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: on weekly grain, the "Force categorical" toggle is hidden for date x-axes, so ticks land between the weekly markers (see the reporter's screenshots).
After: the toggle appears for temporal x-axes; enabling it renders one category per bucket with aligned, date-formatted ticks.
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION
🤖 Generated with Claude Code