mirror of
https://github.com/apache/superset.git
synced 2026-04-29 13:04:22 +00:00
Compare commits
6 Commits
amin/execu
...
d3-localiz
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad2a1fe92f | ||
|
|
7d85b212ee | ||
|
|
9d55bed7ae | ||
|
|
65cfebd889 | ||
|
|
73eb0c11d4 | ||
|
|
6cb9819d10 |
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user