Skip to content

Commit 71868f2

Browse files
yp0413150120沈建斌
and
沈建斌
authored
feat: 玉珏图重写changeData方法 && 添加单测 (#2206)
Co-authored-by: 沈建斌 <[email protected]>
1 parent 144cf23 commit 71868f2

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { RadialBar } from '../../../../src';
2+
import { createDiv } from '../../../utils/dom';
3+
import { antvStar } from '../../../data/antv-star';
4+
5+
describe('radial-bar changeData', () => {
6+
it('changeData: normal', () => {
7+
const bar = new RadialBar(createDiv(), {
8+
width: 400,
9+
height: 300,
10+
data: antvStar,
11+
xField: 'name',
12+
yField: 'start',
13+
radius: 0.8,
14+
innerRadius: 0.2,
15+
});
16+
bar.render();
17+
18+
expect(bar.chart.geometries[0].elements.length).toEqual(antvStar.length);
19+
20+
const newData = antvStar.slice(0, 4);
21+
bar.changeData(newData);
22+
expect(bar.chart.geometries[0].elements.length).toEqual(newData.length);
23+
expect(bar.options.data).toEqual(newData);
24+
25+
bar.destroy();
26+
});
27+
28+
it('changeData: from empty to have data', () => {
29+
const bar = new RadialBar(createDiv(), {
30+
width: 400,
31+
height: 300,
32+
data: [],
33+
xField: 'name',
34+
yField: 'start',
35+
radius: 0.8,
36+
innerRadius: 0.2,
37+
});
38+
39+
bar.render();
40+
41+
expect(bar.chart.geometries[0].elements.length).toEqual(0);
42+
43+
bar.changeData(antvStar);
44+
expect(bar.chart.geometries[0].elements.length).toEqual(antvStar.length);
45+
expect(bar.options.data).toEqual(antvStar);
46+
47+
bar.destroy();
48+
});
49+
});

src/plots/radial-bar/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export class RadialBar extends Plot<RadialBarOptions> {
1313
/** 图表类型 */
1414
public type: string = 'radial-bar';
1515

16+
/**
17+
* @override
18+
* @param data
19+
*/
20+
public changeData(data) {
21+
this.updateOption({ data });
22+
this.chart.changeData(data);
23+
}
24+
1625
/**
1726
* 获取默认配置
1827
*/

0 commit comments

Comments
 (0)