Skip to content

Commit

Permalink
fix(issue-2161): 修复数据项存在非法 undefined 时,获取数据 max 为 NaN,导致玉珏图渲染页面崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Jan 2, 2021
1 parent 2468149 commit 640be7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
37 changes: 37 additions & 0 deletions __tests__/bugs/issue-2161-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { RadialBar } from '../../src';
import { createDiv } from '../utils/dom';

describe('#2161', () => {
it('[玉珏图] 当某一数据项 value 为 undefined 时,页面崩溃', () => {
const data = [
{ name: 'X6', star: 297 },
{ name: 'G' },
{ name: 'AVA', star: 805 },
{ name: 'G2Plot', star: 1478 },
{ name: 'L7', star: 2029 },
{ name: 'G6', star: 7100 },
{ name: 'F2', star: 7346 },
{ name: 'G2', star: 10178 },
];

const bar = new RadialBar(createDiv(), {
width: 400,
height: 300,
data,
xField: 'name',
yField: 'star',
radius: 0.8,
innerRadius: 0.2,
tooltip: {
formatter: (datum) => {
return { name: 'star数', value: datum.star };
},
},
});
bar.render();

expect(bar.chart).toBeDefined();

bar.destroy();
});
});
5 changes: 5 additions & 0 deletions __tests__/unit/plots/radial-bar/utils-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ describe('utils of radial-bar', () => {
expect(getScaleMax(-300, yField, antvStar)).toBe((maxValue * 360) / 300);
expect(getScaleMax(660, yField, antvStar)).toBe((maxValue * 360) / 300);
});

it('getScaleMax: existed nil value', () => {
expect(getScaleMax(-300, yField, [...antvStar, { name: 'c', star: undefined }])).toBe((maxValue * 360) / 300);
expect(getScaleMax(-300, yField, [...antvStar, { name: 'c', star: null }])).toBe((maxValue * 360) / 300);
});
});
2 changes: 1 addition & 1 deletion src/plots/radial-bar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Data } from '../../types';

export function getScaleMax(maxAngle: number, yField: string, data: Data): number {
const yData = data.map((item) => item[yField]);
const maxValue = Math.max(...yData);
const maxValue = Math.max(...yData.filter((v) => v !== undefined));
const formatRadian = Math.abs(maxAngle) % 360;
if (!formatRadian) {
return maxValue;
Expand Down

0 comments on commit 640be7c

Please sign in to comment.