Compare commits

...

6 Commits

Author SHA1 Message Date
Evan Rusackas
ad2a1fe92f style(formatters): fix prettier formatting
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 00:36:55 -08:00
Evan Rusackas
7d85b212ee fix(tests): update scatter chart x-axis formatter tests for smart_date
Update tests to reflect the intentional behavior change where smart_date
now returns a formatter function instead of undefined. The first test
now explicitly sets xAxisTimeFormat to undefined to test the no-format
case, and the test.each loop now expects all formats including smart_date
to return a formatter function.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 00:36:24 -08:00
Evan Rusackas
9d55bed7ae fix: regenerate package-lock.json to resolve dependency conflicts
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 22:24:40 -08:00
Evan Rusackas
65cfebd889 fix: remove unused StringConstructor from return type
Address review feedback from @michael-s-molina: Since the function
no longer returns String, remove StringConstructor from the return
type and update the misleading test description.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 21:55:14 -08:00
Evan Rusackas
73eb0c11d4 Update formatters.ts 2026-02-05 21:55:14 -08:00
Evan Rusackas
6cb9819d10 fix(echarts): Apply D3 locale formatting to adaptive datetime x-axis
Fixes #31790

When the "Adaptive" datetime format option was selected for x-axis in ECharts
visualizations, the custom D3 locale settings (like localized month names) were
being ignored. This was because getXAxisFormatter() was returning undefined for
SMART_DATE_ID, causing ECharts to use its default formatter instead of the
configured D3 locale formatter.

The fix ensures that when SMART_DATE_ID is selected, the smart date formatter
with proper locale support is returned, allowing custom D3 time formats with
localized month and day names to work correctly with the adaptive option.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-05 21:55:13 -08:00
3 changed files with 61 additions and 14 deletions

View File

@@ -86,14 +86,12 @@ export function getTooltipTimeFormatter(
return String;
}
export function getXAxisFormatter(
format?: string,
): TimeFormatter | StringConstructor | undefined {
if (format === SMART_DATE_ID || !format) {
return undefined;
export function getXAxisFormatter(format?: string): TimeFormatter | undefined {
if (format === SMART_DATE_ID) {
return getSmartDateFormatter();
}
if (format) {
return getTimeFormatter(format);
}
return String;
return undefined;
}

View File

@@ -63,10 +63,14 @@ describe('Scatter Chart X-axis Time Formatting', () => {
theme: supersetTheme,
};
test('xAxisTimeFormat has no default formatter', () => {
test('xAxisTimeFormat has no formatter when explicitly undefined', () => {
const chartProps = new ChartProps({
...baseChartPropsConfig,
formData: baseFormData,
formData: {
...baseFormData,
// Explicitly override the default smart_date format to test no-format case
xAxisTimeFormat: undefined,
},
});
const transformedProps = transformProps(
@@ -77,6 +81,8 @@ describe('Scatter Chart X-axis Time Formatting', () => {
expect(transformedProps.echartOptions.xAxis).toHaveProperty('axisLabel');
const xAxis = transformedProps.echartOptions.xAxis as any;
expect(xAxis.axisLabel).toHaveProperty('formatter');
// When no format is specified, formatter should be undefined
// (D3 locale formatting is only applied when a format is explicitly set)
expect(xAxis.axisLabel.formatter).toBeUndefined();
});
@@ -98,10 +104,9 @@ describe('Scatter Chart X-axis Time Formatting', () => {
const xAxis = transformedProps.echartOptions.xAxis as any;
expect(xAxis.axisLabel).toHaveProperty('formatter');
if (format === SMART_DATE_ID) {
expect(xAxis.axisLabel.formatter).toBeUndefined();
} else {
expect(typeof xAxis.axisLabel.formatter).toBe('function');
// All time formats including SMART_DATE should have a formatter function
expect(typeof xAxis.axisLabel.formatter).toBe('function');
if (format !== SMART_DATE_ID) {
expect(xAxis.axisLabel.formatter.id).toBe(format);
}
},

View File

@@ -16,8 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
import { NumberFormats } from '@superset-ui/core';
import { getPercentFormatter } from '../../src/utils/formatters';
import {
NumberFormats,
SMART_DATE_ID,
getTimeFormatter,
} from '@superset-ui/core';
import {
getPercentFormatter,
getXAxisFormatter,
getSmartDateFormatter,
} from '../../src/utils/formatters';
describe('getPercentFormatter', () => {
const value = 0.6;
@@ -35,3 +43,39 @@ describe('getPercentFormatter', () => {
).toEqual('60.00%');
});
});
describe('getXAxisFormatter', () => {
it('should return smart date formatter when SMART_DATE_ID is specified', () => {
const formatter = getXAxisFormatter(SMART_DATE_ID);
expect(formatter).toBeDefined();
expect(formatter).toBeInstanceOf(Function);
// The formatter should be the same as getSmartDateFormatter()
const smartDateFormatter = getSmartDateFormatter();
expect(formatter).toEqual(smartDateFormatter);
});
it('should return undefined when format is not specified', () => {
const formatter = getXAxisFormatter();
expect(formatter).toBeUndefined();
});
it('should return undefined when format is empty string', () => {
const formatter = getXAxisFormatter('');
expect(formatter).toBeUndefined();
});
it('should return the appropriate time formatter for a specific format', () => {
const format = '%Y-%m-%d';
const formatter = getXAxisFormatter(format);
expect(formatter).toBeDefined();
expect(formatter).toBeInstanceOf(Function);
// Should return the same formatter as getTimeFormatter
const expectedFormatter = getTimeFormatter(format);
expect(formatter).toEqual(expectedFormatter);
});
it('should return undefined for falsy values', () => {
const formatter = getXAxisFormatter(null as any);
expect(formatter).toBeUndefined();
});
});