mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat: Utility function to render chart tooltips (#27950)
This commit is contained in:
committed by
GitHub
parent
467e612533
commit
b549977f05
@@ -22,8 +22,8 @@ import {
|
||||
SqlaFormData,
|
||||
supersetTheme,
|
||||
} from '@superset-ui/core';
|
||||
import transformProps, { formatPieLabel } from '../../src/Pie/transformProps';
|
||||
import { EchartsPieChartProps, EchartsPieLabelType } from '../../src/Pie/types';
|
||||
import transformProps, { parseParams } from '../../src/Pie/transformProps';
|
||||
import { EchartsPieChartProps } from '../../src/Pie/types';
|
||||
|
||||
describe('Pie transformProps', () => {
|
||||
const formData: SqlaFormData = {
|
||||
@@ -81,61 +81,23 @@ describe('formatPieLabel', () => {
|
||||
const numberFormatter = getNumberFormatter();
|
||||
const params = { name: 'My Label', value: 1234, percent: 12.34 };
|
||||
expect(
|
||||
formatPieLabel({
|
||||
parseParams({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.Key,
|
||||
}),
|
||||
).toEqual('My Label');
|
||||
).toEqual(['My Label', '1.23k', '12.34%']);
|
||||
expect(
|
||||
formatPieLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.Value,
|
||||
}),
|
||||
).toEqual('1.23k');
|
||||
expect(
|
||||
formatPieLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.Percent,
|
||||
}),
|
||||
).toEqual('12.34%');
|
||||
expect(
|
||||
formatPieLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.KeyValue,
|
||||
}),
|
||||
).toEqual('My Label: 1.23k');
|
||||
expect(
|
||||
formatPieLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.KeyPercent,
|
||||
}),
|
||||
).toEqual('My Label: 12.34%');
|
||||
expect(
|
||||
formatPieLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.KeyValuePercent,
|
||||
}),
|
||||
).toEqual('My Label: 1.23k (12.34%)');
|
||||
expect(
|
||||
formatPieLabel({
|
||||
parseParams({
|
||||
params: { ...params, name: '<NULL>' },
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.Key,
|
||||
}),
|
||||
).toEqual('<NULL>');
|
||||
).toEqual(['<NULL>', '1.23k', '12.34%']);
|
||||
expect(
|
||||
formatPieLabel({
|
||||
parseParams({
|
||||
params: { ...params, name: '<NULL>' },
|
||||
numberFormatter,
|
||||
labelType: EchartsPieLabelType.Key,
|
||||
sanitizeName: true,
|
||||
}),
|
||||
).toEqual('<NULL>');
|
||||
).toEqual(['<NULL>', '1.23k', '12.34%']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user