mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(echarts-funnel): Implement % calculation type (#26290)
This commit is contained in:
committed by
GitHub
parent
39ac45351b
commit
5400d30b20
@@ -27,6 +27,7 @@ import transformProps, {
|
||||
import {
|
||||
EchartsFunnelChartProps,
|
||||
EchartsFunnelLabelTypeType,
|
||||
PercentCalcType,
|
||||
} from '../../src/Funnel/types';
|
||||
|
||||
describe('Funnel transformProps', () => {
|
||||
@@ -81,12 +82,18 @@ describe('Funnel transformProps', () => {
|
||||
describe('formatFunnelLabel', () => {
|
||||
it('should generate a valid funnel chart label', () => {
|
||||
const numberFormatter = getNumberFormatter();
|
||||
const params = { name: 'My Label', value: 1234, percent: 12.34 };
|
||||
const params = {
|
||||
name: 'My Label',
|
||||
value: 1234,
|
||||
percent: 12.34,
|
||||
data: { firstStepPercent: 0.5, prevStepPercent: 0.85 },
|
||||
};
|
||||
expect(
|
||||
formatFunnelLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Key,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('My Label');
|
||||
expect(
|
||||
@@ -94,6 +101,7 @@ describe('formatFunnelLabel', () => {
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Value,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('1.23k');
|
||||
expect(
|
||||
@@ -101,13 +109,31 @@ describe('formatFunnelLabel', () => {
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Percent,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('12.34%');
|
||||
expect(
|
||||
formatFunnelLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Percent,
|
||||
percentCalculationType: PercentCalcType.FIRST_STEP,
|
||||
}),
|
||||
).toEqual('50.00%');
|
||||
expect(
|
||||
formatFunnelLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Percent,
|
||||
percentCalculationType: PercentCalcType.PREV_STEP,
|
||||
}),
|
||||
).toEqual('85.00%');
|
||||
expect(
|
||||
formatFunnelLabel({
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.KeyValue,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('My Label: 1.23k');
|
||||
expect(
|
||||
@@ -115,6 +141,7 @@ describe('formatFunnelLabel', () => {
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.KeyPercent,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('My Label: 12.34%');
|
||||
expect(
|
||||
@@ -122,6 +149,7 @@ describe('formatFunnelLabel', () => {
|
||||
params,
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.KeyValuePercent,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('My Label: 1.23k (12.34%)');
|
||||
expect(
|
||||
@@ -129,6 +157,7 @@ describe('formatFunnelLabel', () => {
|
||||
params: { ...params, name: '<NULL>' },
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Key,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
}),
|
||||
).toEqual('<NULL>');
|
||||
expect(
|
||||
@@ -136,6 +165,7 @@ describe('formatFunnelLabel', () => {
|
||||
params: { ...params, name: '<NULL>' },
|
||||
numberFormatter,
|
||||
labelType: EchartsFunnelLabelTypeType.Key,
|
||||
percentCalculationType: PercentCalcType.TOTAL,
|
||||
sanitizeName: true,
|
||||
}),
|
||||
).toEqual('<NULL>');
|
||||
|
||||
Reference in New Issue
Block a user