Skip to content

Commit

Permalink
fix(#2272): 当映射数据中不存在 x 和 y 时,不绘制 label
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Apr 7, 2020
1 parent 4b29fea commit 060c2f9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/geometry/label/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class GeometryLabel {
// 获取 label 相关的 x,y 的值,获取具体的 x, y,防止存在数组
each(mapppingArray, (mappingData: MappingDatum, index: number) => {
const labelCfg = labelCfgs[index];
if (!labelCfg) {
if (!labelCfg || isNil(mappingData.x) || isNil(mappingData.y)) {
items.push(null);
return;
}
Expand Down
57 changes: 57 additions & 0 deletions tests/bugs/2272-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';

describe('#2272', () => {
it('#2272', () => {
const data = [
{ type: '一线城市', value: 0.19 },
{ type: '二线城市', value: 0.21 },
{ type: '三线城市', value: 0.27 },
{ type: '四线及以下', value: null },
];
const chart = new Chart({
container: createDiv(),
width: 400,
height: 300,
localRefresh: false, // 暂时关闭
});
chart.data(data);
chart.coordinate('theta', {
radius: 0.75,
innerRadius: 0.4
});
chart.tooltip({
showMarkers: false
});

const interval = chart
.interval()
.adjust('stack')
.position('value')
.color('type', ['#063d8a', '#1770d6', '#47abfc', '#38c060'])
.label('type', (val) => {
const opacity = val === '四线及以下' ? 1 : 0.5;
return {
offset: -10,
style: {
opacity,
fill: 'white',
fontSize: 12,
shadowBlur: 2,
shadowColor: 'rgba(0, 0, 0, .45)',
},
content: (obj) => {
return obj.type + '\n' + obj.value + '%';
},
};
});

expect(() => {
chart.render();
}).not.toThrow();

expect(interval.elements.length).toBe(4);
// expect(interval.container.getBBox().width).not.toBe(Infinity);
// expect(interval.container.getBBox().height).not.toBe(Infinity);
});
});

0 comments on commit 060c2f9

Please sign in to comment.