bito-code-review[bot] commented on code in PR #44701:
URL: https://github.com/apache/superset/pull/44701#discussion_r4185577930
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/formatters.ts:
##########
@@ -406,3 +406,34 @@ export function getXAxisDomain(
});
return [domainMin, domainMax];
}
+
+/**
+ * Wraps a temporal x-axis formatter so ticks that fall outside the data
+ * domain — the sub-second noise ECharts adds when it pads a time axis
+ * beyond the data extent — are floored to the second before formatting,
+ * instead of triggering smart_date's millisecond tier ('.943ms', #44698).
+ * Ticks inside the data domain are passed through untouched: a genuine
+ * sub-second timestamp is real data and keeps its precision.
+ */
+export function createPaddedExtentFloorFormatter(
+ formatter: XAxisFormatterFn | undefined,
+ domainMin: number | undefined,
+ domainMax: number | undefined,
+): (value: number | string) => string {
+ const wrapper = (value: number | string) => {
+ if (
+ typeof value === 'number' &&
+ formatter &&
+ (value < (domainMin ?? -Infinity) || value > (domainMax ?? Infinity))
+ ) {
+ return formatter(Math.floor(value / 1000) * 1000);
+ }
+ return typeof formatter === 'function'
+ ? (formatter as Function)(value)
+ : String(value);
+ };
+ if (typeof formatter === 'function' && 'id' in formatter) {
+ (wrapper as { id?: unknown }).id = (formatter as { id?: unknown }).id;
+ }
Review Comment:
<!-- Bito Reply -->
The implementation of the shared helper and the domain scan check correctly
addresses the concern regarding duplicated formatter-id propagation. By
centralizing the logic in a single helper and restricting the domain scan to
temporal axes, the code is now more maintainable and efficient.
--
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]