Skip to content

Commit

Permalink
fix(funnel): 修复漏斗图数据为0时,出现conversionTag 样式问题 (#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Oct 8, 2021
1 parent 078a358 commit 6a0512b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions __tests__/bugs/issue-2881-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Funnel } from '../../src';
import { createDiv } from '../utils/dom';

describe('#2651', () => {
it('funnel render normal when data is null or zero', () => {
const data = [
{ stage: '简历筛选', number: 10 },
{ stage: '初试人数', number: 8 },
{ stage: '复试人数', number: 7 },
{ stage: '录取人数', number: 6 },
{ stage: '入职人数', number: 5 },
];

const plot = new Funnel(createDiv(), {
data: data,
xField: 'stage',
yField: 'number',
legend: false,
});

plot.render();
expect(plot.chart.getController('annotation').getComponents().length).toBe(4);

plot.changeData([
{ stage: '简历筛选', number: 0 },
{ stage: '初试人数', number: 0 },
{ stage: '复试人数', number: 4 },
{ stage: '录取人数', number: 0 },
{ stage: '入职人数', number: 0 },
]);
expect(plot.chart.getController('annotation').getComponents().length).toBe(4);

plot.changeData([
{ stage: '简历筛选', number: 0 },
{ stage: '初试人数', number: 0 },
{ stage: '复试人数', number: 0 },
{ stage: '录取人数', number: 0 },
{ stage: '入职人数', number: 0 },
]);
expect(plot.chart.getController('annotation').getComponents().length).toBe(0);
});
});
2 changes: 1 addition & 1 deletion src/plots/funnel/geometries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function conversionTagComponent(
if (conversionTag) {
const { formatter } = conversionTag;
data.forEach((obj, index) => {
if (index <= 0) return;
if (index <= 0 || Number.isNaN(obj[FUNNEL_MAPPING_VALUE])) return;
const lineOption = getLineCoordinate(obj, index, data, {
top: true,
text: {
Expand Down

0 comments on commit 6a0512b

Please sign in to comment.