mirror of
https://github.com/apache/superset.git
synced 2026-05-21 15:55:10 +00:00
Compare commits
6 Commits
fix-flakey
...
d3-localiz
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad2a1fe92f | ||
|
|
7d85b212ee | ||
|
|
9d55bed7ae | ||
|
|
65cfebd889 | ||
|
|
73eb0c11d4 | ||
|
|
6cb9819d10 |
@@ -86,14 +86,12 @@ export function getTooltipTimeFormatter(
|
|||||||
return String;
|
return String;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getXAxisFormatter(
|
export function getXAxisFormatter(format?: string): TimeFormatter | undefined {
|
||||||
format?: string,
|
if (format === SMART_DATE_ID) {
|
||||||
): TimeFormatter | StringConstructor | undefined {
|
return getSmartDateFormatter();
|
||||||
if (format === SMART_DATE_ID || !format) {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
if (format) {
|
if (format) {
|
||||||
return getTimeFormatter(format);
|
return getTimeFormatter(format);
|
||||||
}
|
}
|
||||||
return String;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,10 +63,14 @@ describe('Scatter Chart X-axis Time Formatting', () => {
|
|||||||
theme: supersetTheme,
|
theme: supersetTheme,
|
||||||
};
|
};
|
||||||
|
|
||||||
test('xAxisTimeFormat has no default formatter', () => {
|
test('xAxisTimeFormat has no formatter when explicitly undefined', () => {
|
||||||
const chartProps = new ChartProps({
|
const chartProps = new ChartProps({
|
||||||
...baseChartPropsConfig,
|
...baseChartPropsConfig,
|
||||||
formData: baseFormData,
|
formData: {
|
||||||
|
...baseFormData,
|
||||||
|
// Explicitly override the default smart_date format to test no-format case
|
||||||
|
xAxisTimeFormat: undefined,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const transformedProps = transformProps(
|
const transformedProps = transformProps(
|
||||||
@@ -77,6 +81,8 @@ describe('Scatter Chart X-axis Time Formatting', () => {
|
|||||||
expect(transformedProps.echartOptions.xAxis).toHaveProperty('axisLabel');
|
expect(transformedProps.echartOptions.xAxis).toHaveProperty('axisLabel');
|
||||||
const xAxis = transformedProps.echartOptions.xAxis as any;
|
const xAxis = transformedProps.echartOptions.xAxis as any;
|
||||||
expect(xAxis.axisLabel).toHaveProperty('formatter');
|
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();
|
expect(xAxis.axisLabel.formatter).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,10 +104,9 @@ describe('Scatter Chart X-axis Time Formatting', () => {
|
|||||||
|
|
||||||
const xAxis = transformedProps.echartOptions.xAxis as any;
|
const xAxis = transformedProps.echartOptions.xAxis as any;
|
||||||
expect(xAxis.axisLabel).toHaveProperty('formatter');
|
expect(xAxis.axisLabel).toHaveProperty('formatter');
|
||||||
if (format === SMART_DATE_ID) {
|
// All time formats including SMART_DATE should have a formatter function
|
||||||
expect(xAxis.axisLabel.formatter).toBeUndefined();
|
expect(typeof xAxis.axisLabel.formatter).toBe('function');
|
||||||
} else {
|
if (format !== SMART_DATE_ID) {
|
||||||
expect(typeof xAxis.axisLabel.formatter).toBe('function');
|
|
||||||
expect(xAxis.axisLabel.formatter.id).toBe(format);
|
expect(xAxis.axisLabel.formatter.id).toBe(format);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,8 +16,16 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { NumberFormats } from '@superset-ui/core';
|
import {
|
||||||
import { getPercentFormatter } from '../../src/utils/formatters';
|
NumberFormats,
|
||||||
|
SMART_DATE_ID,
|
||||||
|
getTimeFormatter,
|
||||||
|
} from '@superset-ui/core';
|
||||||
|
import {
|
||||||
|
getPercentFormatter,
|
||||||
|
getXAxisFormatter,
|
||||||
|
getSmartDateFormatter,
|
||||||
|
} from '../../src/utils/formatters';
|
||||||
|
|
||||||
describe('getPercentFormatter', () => {
|
describe('getPercentFormatter', () => {
|
||||||
const value = 0.6;
|
const value = 0.6;
|
||||||
@@ -35,3 +43,39 @@ describe('getPercentFormatter', () => {
|
|||||||
).toEqual('60.00%');
|
).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