-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix(#2124): fix funnel crash when data contains null, 0 * chore: fix ci * chore: fix function name typo * fix: typo
- Loading branch information
Showing
12 changed files
with
165 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Funnel } from '../../src'; | ||
import { createDiv } from '../utils/dom'; | ||
|
||
const DATA1 = [ | ||
{ stage: '简历筛选', number: 253 }, | ||
{ stage: '初试人数', number: 151 }, | ||
{ stage: '复试人数', number: 0 }, | ||
{ stage: '录取人数', number: 87 }, | ||
{ stage: '入职人数', number: null }, | ||
{ stage: '离职人数', number: 10 }, | ||
]; | ||
|
||
const DATA2 = [ | ||
{ stage: '简历筛选', number: 253, company: 'A公司' }, | ||
{ stage: '初试人数', number: 151, company: 'A公司' }, | ||
{ stage: '复试人数', number: 0, company: 'A公司' }, | ||
{ stage: '录取人数', number: 87, company: 'A公司' }, | ||
{ stage: '入职人数', number: null, company: 'A公司' }, | ||
{ stage: '离职人数', number: 10, company: 'A公司' }, | ||
{ stage: '简历筛选', number: 303, company: 'B公司' }, | ||
{ stage: '初试人数', number: 0, company: 'B公司' }, | ||
{ stage: '复试人数', number: 153, company: 'B公司' }, | ||
{ stage: '录取人数', number: 117, company: 'B公司' }, | ||
{ stage: '入职人数', number: 79, company: 'B公司' }, | ||
{ stage: '离职人数', number: 15, company: 'B公司' }, | ||
]; | ||
|
||
describe('#2124', () => { | ||
it('Funnel 数据为 null, 0 不能报错', async () => { | ||
const plot = new Funnel(createDiv(), { | ||
data: DATA1, | ||
xField: 'stage', | ||
yField: 'number', | ||
legend: false, | ||
minSize: 0.1, | ||
}); | ||
|
||
plot.render(); | ||
|
||
expect( | ||
plot.chart | ||
.getController('annotation') | ||
.getComponents() | ||
.map((co) => co.component.cfg.text.content) | ||
).toEqual(['转化率: 59.68%', '转化率: -∞', '转化率: ∞', '转化率: -', '转化率: -']); | ||
|
||
plot.destroy(); | ||
}); | ||
|
||
it('对称漏斗图', () => { | ||
const plot = new Funnel(createDiv(), { | ||
data: DATA2, | ||
xField: 'stage', | ||
yField: 'number', | ||
compareField: 'company', | ||
meta: { | ||
stage: { | ||
alias: '行为', | ||
}, | ||
pv: { | ||
alias: '人数', | ||
formatter: (v) => `${v}次`, | ||
}, | ||
}, | ||
tooltip: { | ||
fields: ['stage', 'number', 'company'], | ||
formatter: (v) => ({ | ||
name: `${v.company}的${v.stage}`, | ||
value: v.number, | ||
}), | ||
}, | ||
legend: false, | ||
}); | ||
|
||
plot.render(); | ||
|
||
expect( | ||
plot.chart.views[0] | ||
.getController('annotation') | ||
.getComponents() | ||
.filter((co) => co.component.cfg.type === 'line') | ||
.map((co) => co.component.cfg.text.content) | ||
).toEqual(['转化率: 59.68%', '转化率: -∞', '转化率: ∞', '转化率: -', '转化率: -']); | ||
|
||
expect( | ||
plot.chart.views[1] | ||
.getController('annotation') | ||
.getComponents() | ||
.filter((co) => co.component.cfg.type === 'line') | ||
.map((co) => co.component.cfg.text.content) | ||
).toEqual(['转化率: -∞', '转化率: ∞', '转化率: 76.47%', '转化率: 67.52%', '转化率: 18.99%']); | ||
|
||
plot.destroy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { conversionTagformatter } from '../../../src/utils/conversion'; | ||
import { conversionTagFormatter } from '../../../src/utils/conversion'; | ||
|
||
describe('conversionTagformatter', () => { | ||
it('conversionTagformatter', () => { | ||
expect(conversionTagformatter(0, 0)).toBe('0.00%'); | ||
expect(conversionTagformatter(0, 1)).toBe('∞'); | ||
expect(conversionTagformatter(1, 0)).toBe('-∞'); | ||
expect(conversionTagformatter(10, 20)).toBe('200.00%'); | ||
expect(conversionTagformatter(40, 20)).toBe('50.00%'); | ||
describe('conversionTagFormatter', () => { | ||
it('conversionTagFormatter', () => { | ||
expect(conversionTagFormatter(0, 0)).toBe('0.00%'); | ||
expect(conversionTagFormatter(0, 1)).toBe('∞'); | ||
expect(conversionTagFormatter(1, 0)).toBe('-∞'); | ||
expect(conversionTagFormatter(10, 20)).toBe('200.00%'); | ||
expect(conversionTagFormatter(40, 20)).toBe('50.00%'); | ||
|
||
expect(conversionTagformatter(null, 20)).toBe('-'); | ||
expect(conversionTagformatter(20, null)).toBe('-'); | ||
expect(conversionTagformatter(null, null)).toBe('-'); | ||
expect(conversionTagformatter(undefined, 20)).toBe('-'); | ||
expect(conversionTagformatter(20, undefined)).toBe('-'); | ||
expect(conversionTagformatter(undefined, undefined)).toBe('-'); | ||
expect(conversionTagFormatter(null, 20)).toBe('-'); | ||
expect(conversionTagFormatter(20, null)).toBe('-'); | ||
expect(conversionTagFormatter(null, null)).toBe('-'); | ||
expect(conversionTagFormatter(undefined, 20)).toBe('-'); | ||
expect(conversionTagFormatter(20, undefined)).toBe('-'); | ||
expect(conversionTagFormatter(undefined, undefined)).toBe('-'); | ||
|
||
// @ts-ignore | ||
expect(conversionTagformatter(false, 20)).toBe('-'); | ||
expect(conversionTagFormatter(false, 20)).toBe('-'); | ||
// @ts-ignore | ||
expect(conversionTagformatter(20, 'wef')).toBe('-'); | ||
expect(conversionTagFormatter(20, 'wef')).toBe('-'); | ||
// @ts-ignore | ||
expect(conversionTagformatter(30, {})).toBe('-'); | ||
expect(conversionTagFormatter(30, {})).toBe('-'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters