You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "antbertrand (via GitHub)" <gi...@apache.org> on 2025/12/17 09:29:01 UTC
[PR] Add relative day formatters for time-series X-axis [superset]
antbertrand opened a new pull request, #36702:
URL: https://github.com/apache/superset/pull/36702
SUMMARY
This PR adds two new time formatters for time-series charts that display dates as relative days from a reference point (Day 1 = 01/01/2000), enabling use cases where data is normalized to a common timeline but needs to display relative day labels instead of actual timestamps. Problem: Users working with normalized time-series data (e.g., clinical trials, A/B tests, cohort studies) often need to:
- Keep datetime columns for proper time-based chart features (zooming, panning, time-grain aggregation)
- Display X-axis labels as relative days ("Day 1", "Day -1", "Day 14") instead of raw timestamps
- This was not possible with existing formatters, requiring users to choose between proper datetime functionality OR readable relative labels
Solution: Added two new time formatters:
1. Relative Day (Day 1: 12:00am) - Shows both day and time (e.g., "Day 4: 6:30pm")
2. Relative Day (Day 1) - Shows only the day (e.g., "Day 4")
Both formatters:
- Use 01/01/2000 00:00 UTC as the reference date (Day 1)
- Skip Day 0 (go from Day -1 to Day 1)
- Support negative days for dates before the reference
- Work with any datetime/timestamp column that has been normalized to this reference
Implementation:
- Created new TimeFormatter implementations in @superset-ui/core/time-format
- Registered formatters in the global formatter registry
- Added to time format dropdown in chart controls
- Wired into ECharts X-axis rendering logic
BEFORE:
- X-axis shows raw timestamps: "2000-01-01", "2000-01-04", "1999-12-31"
- Users must choose between datetime features OR readable labels
AFTER:
- X-axis shows relative days: "Day 1", "Day 4", "Day -1"
- Users get both datetime functionality AND readable relative labels
- Available in the "Time format" dropdown under chart customization
Run tests:
```
cd superset-frontend
npm run test -- relativeDayFormatter
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add relative day formatters for time-series X-axis [superset]
Posted by "antbertrand (via GitHub)" <gi...@apache.org>.
antbertrand closed pull request #36702: Add relative day formatters for time-series X-axis
URL: https://github.com/apache/superset/pull/36702
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add relative day formatters for time-series X-axis [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #36702:
URL: https://github.com/apache/superset/pull/36702#issuecomment-3664473207
CodeAnt AI is reviewing your PR.
---
### Thanks for using CodeAnt! ๐
We're free for open-source projects. if you're enjoying it, help us grow by sharing.
[Share on X](https://twitter.com/intent/tweet?text=Just%20tried%20%40CodeAntAI%20for%20automated%20code%20review%20and%20I%27m%20impressed%21%20Free%20for%20open%20source%20with%20a%20free%20trial%20for%20private%20repos.%20Worth%20checking%20out%3A&url=https%3A//codeant.ai) ยท
[Reddit](https://www.reddit.com/submit?title=Check%20out%20CodeAnt%20for%20automated%20code%20review&text=Just%20tried%20CodeAnt%20for%20automated%20code%20review%20and%20I%27m%20impressed%21%20Free%20for%20open%20source%20with%20a%20free%20trial%20for%20private%20repos.%20Worth%20checking%20out%3A%20https%3A//codeant.ai) ยท
[LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcodeant.ai&mini=true&title=Check%20out%20CodeAnt%20for%20automated%20code%20review&summary=Just%20tried%20CodeAnt%20for%20automated%20code%20review%20and%20I%27m%20impressed%21%20Free%20for%20open%20source%20with%20a%20free%20trial%20for%20private%20repos)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add relative day formatters for time-series X-axis [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #36702:
URL: https://github.com/apache/superset/pull/36702#issuecomment-3664491098
## Nitpicks ๐
<table>
<tr><td>๐ <strong>No security issues identified</strong></td></tr>
<tr><td>โก <strong>Recommended areas for review</strong><br><br>
- [ ] <a href='https://github.com/apache/superset/pull/36702/files#diff-f066be5f3a8b8b807b00714836b4d6f868233ed60bb2423e7bf9ed489bcfde24R48-R51'><strong>Possible Missing Named Exports</strong></a><br>The file re-exports `RELATIVE_DAY_ID`, `createRelativeDayFormatter` and their "no time" counterparts from two modules. If those modules do not export these identifiers as named exports (for example they export a default or different names), this re-export will cause build-time errors. Validate that the formatter modules actually export those names and that their TypeScript declarations are present.<br>
- [ ] <a href='https://github.com/apache/superset/pull/36702/files#diff-91f9fc1f75fd47cde0bc108906162087ab1d789eef99d6e02c6b329667d10d8eR19-R26'><strong>Possible missing export</strong></a><br>This change imports `RELATIVE_DAY_ID` and `RELATIVE_DAY_NO_TIME_ID` from `@superset-ui/core`. If those constants are not exported from that package (or have different names), the build will fail with a TypeScript/ES module error. Verify the constants are exported and stable across package versions, and update the import source or add a fallback if necessary.<br>
- [ ] <a href='https://github.com/apache/superset/pull/36702/files#diff-131da5e05f5855060a3cf29eec69773ce4203953f5e4d2976b8ccbf523b26decR39-R42'><strong>Day boundary logic</strong></a><br>The day calculation uses `Math.floor(msDiff / MS_PER_DAY)` and then maps non-negative values to `daysDiff + 1`. This works for many cases but is subtle around negative fractions (times before Day 1 but within the same UTC day) and might be easier to reason about if extracted to a small helper with tests. Ensure this behavior (no Day 0, Day 1 = 2000-01-01T00:00Z) is deliberate and covered by unit tests.<br>
- [ ] <a href='https://github.com/apache/superset/pull/36702/files#diff-f066be5f3a8b8b807b00714836b4d6f868233ed60bb2423e7bf9ed489bcfde24R52-R55'><strong>Registry / UI integration</strong></a><br>Adding the exports is only part of the change โ confirm the new formatter IDs are registered with the formatter registry and included in the chart time-format dropdown (with proper labels and i18n). Also check that switching to these formatters preserves datetime chart behaviors (zoom/aggregation).<br>
- [ ] <a href='https://github.com/apache/superset/pull/36702/files#diff-8fa09dddb58067c61e8a8ca18ad456fb0979f40204cc86f4c4b7d669b0b590e0R22-R26'><strong>API inconsistency</strong></a><br>The first test asserts that the returned formatter has a `format` method (object API) but all other tests call the formatter as a function (callable API). This mismatch can cause fragile tests or false failures depending on whether the implementation returns a function, an object with `format()`, or a callable function-object hybrid. The test should assert the concrete API the implementation provides.<br>
</td></tr>
</table>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add relative day formatters for time-series X-axis [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #36702:
URL: https://github.com/apache/superset/pull/36702#discussion_r2626294979
##########
superset-frontend/packages/superset-ui-core/test/time-format/formatters/relativeDayFormatter.test.ts:
##########
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { createRelativeDayFormatter } from '@superset-ui/core';
+
+test('createRelativeDayFormatter returns a formatter', () => {
+ const formatter = createRelativeDayFormatter();
+ expect(formatter).toBeDefined();
+ expect(typeof formatter.format).toBe('function');
Review Comment:
**Suggestion:** Incorrect type assertion: the test checks `typeof formatter.format` but `createRelativeDayFormatter()` returns a callable formatter (a function) rather than an object with a `.format` method; this causes the test to fail because `formatter.format` is undefined. Change the assertion to verify that `formatter` itself is a function. [type error]
**Severity Level:** Minor โ ๏ธ
```suggestion
expect(typeof formatter).toBe('function');
```
<details>
<summary><b>Why it matters? โญ </b></summary>
The tests call formatter(date) elsewhere in the file, so createRelativeDayFormatter returns a callable. Checking typeof formatter.format is incorrect (formatter.format will be undefined) and will make the test fail. Replacing the assertion with typeof formatter === 'function' directly fixes a real test bug.
</details>
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/packages/superset-ui-core/test/time-format/formatters/relativeDayFormatter.test.ts
**Line:** 25:25
**Comment:**
*Type Error: Incorrect type assertion: the test checks `typeof formatter.format` but `createRelativeDayFormatter()` returns a callable formatter (a function) rather than an object with a `.format` method; this causes the test to fail because `formatter.format` is undefined. Change the assertion to verify that `formatter` itself is a function.
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.
```
</details>
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/formatters.ts:
##########
@@ -92,6 +94,12 @@ export function getXAxisFormatter(
if (format === SMART_DATE_ID || !format) {
return undefined;
}
+ if (format === RELATIVE_DAY_ID) {
+ return getTimeFormatter(RELATIVE_DAY_ID);
+ }
+ if (format === RELATIVE_DAY_NO_TIME_ID) {
+ return getTimeFormatter(RELATIVE_DAY_NO_TIME_ID);
Review Comment:
**Suggestion:** Duplicate conditional branches for the two relative-day formats increase maintenance burden and risk of inconsistent behaviour; combine them into a single conditional and call `getTimeFormatter` with the actual `format` value (with a string type guard) to avoid repeating nearly identical code and accidental drift between branches. [logic error]
**Severity Level:** Minor โ ๏ธ
```suggestion
if (typeof format === 'string' && (format === RELATIVE_DAY_ID || format === RELATIVE_DAY_NO_TIME_ID)) {
return getTimeFormatter(format);
```
<details>
<summary><b>Why it matters? โญ </b></summary>
The proposed consolidation removes duplicated branches without changing runtime behavior โ when format equals one of those constants, calling getTimeFormatter(format) is equivalent to passing the constant. It's a small, safe maintenance improvement (the typeof guard is redundant given the signature but harmless).
</details>
<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/utils/formatters.ts
**Line:** 97:101
**Comment:**
*Logic Error: Duplicate conditional branches for the two relative-day formats increase maintenance burden and risk of inconsistent behaviour; combine them into a single conditional and call `getTimeFormatter` with the actual `format` value (with a string type guard) to avoid repeating nearly identical code and accidental drift between branches.
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.
```
</details>
##########
superset-frontend/packages/superset-ui-core/src/time-format/formatters/relativeDayFormatterNoTime.ts:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import TimeFormatter from '../TimeFormatter';
+
+export const RELATIVE_DAY_NO_TIME_ID = 'relative_day_no_time';
+
+// Reference date: January 1, 2000 00:00:00 UTC = Day 1
+const DAY_ONE_DATE = Date.UTC(2000, 0, 1, 0, 0, 0, 0);
+const MS_PER_DAY = 86400000;
+
+export function createRelativeDayFormatterNoTime() {
+ return new TimeFormatter({
+ id: RELATIVE_DAY_NO_TIME_ID,
+ label: 'Relative Day (No Time)',
+ description: 'Formats dates as relative days from Day 1 (01/01/2000) without time',
+ formatFunc: (date: Date) => {
+ const ms = date.getTime();
+
Review Comment:
**Suggestion:** Runtime failure for invalid dates: calling `getTime()` on an invalid `Date` returns NaN which will propagate and produce `Day NaN`; detect invalid dates (Number.isNaN on milliseconds) and return a sensible string (e.g., 'Invalid Date') to avoid confusing output or downstream errors. [possible bug]
**Severity Level:** Critical ๐จ
```suggestion
if (Number.isNaN(ms)) {
return 'Invalid Date';
}
```
<details>
<summary><b>Why it matters? โญ </b></summary>
Valid point โ an invalid Date yields NaN and the formatter would return "Day NaN", which is confusing. Guarding against Number.isNaN(ms) and returning a sensible fallback (or empty string) prevents misleading output.
</details>
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/packages/superset-ui-core/src/time-format/formatters/relativeDayFormatterNoTime.ts
**Line:** 35:35
**Comment:**
*Possible Bug: Runtime failure for invalid dates: calling `getTime()` on an invalid `Date` returns NaN which will propagate and produce `Day NaN`; detect invalid dates (Number.isNaN on milliseconds) and return a sensible string (e.g., 'Invalid Date') to avoid confusing output or downstream errors.
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.
```
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add relative day formatters for time-series X-axis [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #36702:
URL: https://github.com/apache/superset/pull/36702#issuecomment-3664501532
CodeAnt AI finished reviewing your PR.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add relative day formatters for time-series X-axis [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #36702:
URL: https://github.com/apache/superset/pull/36702#issuecomment-3664473513
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org