-
Notifications
You must be signed in to change notification settings - Fork 16.3k
fix(Gauge): clearing previously set min and max values in a gauge chart sets the data labels to 0 #36425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… the data labels to 0
|
@geido This workflow is deprecated! Please use the new Superset Showtime system instead:
Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
|
@geido Ephemeral environment spinning up at http://54.201.32.96:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
|
🎪 Showtime deployed environment on GHA for b98359d • Environment: http://54.188.234.208:8080 (admin/admin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where clearing previously set min and max values in a gauge chart incorrectly sets the data labels to 0 instead of falling back to calculated default values.
Key Changes:
- Introduced a validation function
isValidNumberto properly validate min/max values before using them - Modified min/max calculation logic to fall back to calculated defaults when values are invalid (null, undefined, empty strings, NaN, or Infinity)
- Added comprehensive test coverage for various min/max validation scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| superset-frontend/plugins/plugin-chart-echarts/src/Gauge/transformProps.ts | Added isValidNumber helper function to validate min/max values and updated min/max calculation logic to use validation before applying user-provided values |
| superset-frontend/plugins/plugin-chart-echarts/test/Gauge/transformProps.test.ts | Added 15 new test cases covering various scenarios: null values, empty strings, invalid strings, numeric strings, negative values, zero values, and different splitNumber configurations |
| const max = maxVal ?? calculateMax(transformedData); | ||
| const isValidNumber = ( | ||
| val: number | null | undefined | string, | ||
| ): val is number => { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type predicate val is number is inaccurate since the function returns true when val is a valid numeric string (e.g., '10'). While lines 234 and 237 handle this correctly with Number(minVal) and Number(maxVal), the type guard is misleading.
Consider changing the return type to accurately reflect what the function validates:
const isValidNumber = (
val: number | null | undefined | string,
): val is number | string => {Or, alternatively, be more precise and only accept actual numbers in the type guard:
const isValidNumber = (
val: number | null | undefined | string,
): boolean => {| ): val is number => { | |
| ): boolean => { |
| }); | ||
| }); | ||
|
|
||
| describe('Min/Max calculation and axis labels', () => { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite is missing coverage for important edge cases that the implementation handles:
minValormaxValset toNaNminValormaxValset toInfinityor-InfinityminValormaxValexplicitly set toundefined
These cases are validated in the implementation (lines 228-230 of transformProps.ts), but should have corresponding test cases to ensure they fall back to calculated defaults correctly.
Consider adding tests like:
it('should calculate min/max from data when minVal is NaN', () => {
const formData: SqlaFormData = {
...baseFormData,
minVal: NaN as any,
maxVal: 100,
};
// ... test that min is calculated from data
});
it('should calculate min/max from data when maxVal is Infinity', () => {
const formData: SqlaFormData = {
...baseFormData,
minVal: 0,
maxVal: Infinity as any,
};
// ... test that max is calculated from data
});|
@dpgaspar This workflow is deprecated! Please use the new Superset Showtime system instead:
Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments |
|
@dpgaspar Ephemeral environment spinning up at http://34.219.240.245:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup. |
SUMMARY
Clearing previously set min and max values in a gauge chart sets the data labels to 0 instead of getting default values.
Now we:
Validate that
minValandmaxValare valid numbersTreat
null,undefined, empty strings,NaN, andInfinityas invalidFall back to calculated defaults when values are invalid
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE:
519715981-cf840003-21fa-46cd-a246-7c8076594574.mp4
AFTER:
519716143-5b7e2b23-5e2c-4709-9be4-fd71d8ffeda8.mp4
TESTING INSTRUCTIONS
Expected results
You should now get the default values of the chart
ADDITIONAL INFORMATION