feat(Timeseries): Respect time grain
User description
SUMMARY
Respect time grain in timeseries and mixed timeseries chart.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
BEFORE
AFTER
TESTING INSTRUCTIONS
Create a Timeseries or MixedTimeseries chart and use the time grain Quarter.
ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [x] Changes UI
- [ ] Includes DB Migration (follow approval process in SIP-59)
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
CodeAnt-AI Description
Respect time grain for x-axis and tooltip date formatting in Timeseries and MixedTimeseries charts
What Changed
- X-axis labels and tooltip date strings now honor the chart's selected time grain (day, week, month, quarter, year), showing appropriate ranges and concise labels (for example: weekly ranges, "Jan 2021" for months, "Q1 2021" for quarters, "2021" for years).
- Time grain overrides supplied to the chart (for example, via dashboard/extra form overrides) are applied to both x-axis and tooltip formatting.
- The SMART_DATE verbose formatter now produces verbose date strings that match the selected time grain.
- Unit tests added for Timeseries and MixedTimeseries to validate formatting across days, weeks, months, quarters, and years.
Impact
✅ Clearer time labels for weekly/monthly/quarterly/yearly charts
✅ Consistent tooltip dates with configured time grain
✅ Fewer incorrect date displays when dashboards override time grain
💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
@codeant-ai ask: Your question here
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
@codeant-ai ask: Can you suggest a safer alternative to storing this secret?
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
@codeant-ai: Your feedback here
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
@codeant-ai: Do not flag unused imports.
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
@codeant-ai: review
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
You need to run the pre-commit hook to pass CI.
Superset uses Git pre-commit hooks courtesy of pre-commit. To install run the following:
pip3 install -r requirements/development.txt
pre-commit install
A series of checks will now run when you make a git commit.
Alternatively it is possible to run pre-commit by running pre-commit manually:
pre-commit run --all-files
@gerbermichi thanks for this PR! A few questions/requests:
- The PR description is very light on details for all the changes in the PR. Would it be possible to cover all changes in the description to provide more context to reviewers?
- I see there's a change for both i18n and time grain formatting in this PR - would it be possible to split the PR into two different PRs?
- I know testing i18n related features can be challenging, but would it be possible to add unit tests for the time grain formatting? Adding a test that failed before but passes after the changes tends to be a great way of showing what the current issue is, how the added/changed logic addresses that, and finally protect against future regressions.
@villebro thank you for your feedback. I removed the i18n part and will add it in a new PR.
I also added tests for the time grain part to ensure that it works as expected.
@villebro can you have a look at this PR?
@rusackas Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments
@rusackas Ephemeral environment spinning up at http://35.92.241.166:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup.
Some feedback from Claude:
Breaking Change Risk: The convertKeysToCamelCase(formData.extraFormData) could be a breaking change if:
Other components expect snake_case keys from extraFormData There are existing visualizations that rely on the current key format The conversion could cause naming conflicts
Format Override Behavior: When timeGrain is QUARTER, MONTH, or YEAR, the code completely ignores the user-specified format and uses a default formatter. This might surprise users who expect their custom format to be applied.
Undefined Format Handling: The code passes undefined as the format to getTimeFormatter for certain time grains, which needs verification that this is handled properly.
Some feedback from Claude:
Breaking Change Risk: The convertKeysToCamelCase(formData.extraFormData) could be a breaking change if:
Other components expect snake_case keys from extraFormData There are existing visualizations that rely on the current key format The conversion could cause naming conflicts
Format Override Behavior: When timeGrain is QUARTER, MONTH, or YEAR, the code completely ignores the user-specified format and uses a default formatter. This might surprise users who expect their custom format to be applied.
Undefined Format Handling: The code passes undefined as the format to getTimeFormatter for certain time grains, which needs verification that this is handled properly.
I changed the code so that it does not need to convert the keys. Now I use formData.extraFormData.time_grain_sqla directly.
Could you have another look?
CodeAnt AI is reviewing your PR.
Nitpicks 🔍
| 🔒 No security issues identified |
⚡ Recommended areas for review
|
CodeAnt AI finished reviewing your PR.