File tree 2 files changed +58
-0
lines changed
__tests__/unit/plots/radial-bar
2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,15 @@ export class RadialBar extends Plot<RadialBarOptions> {
13
13
/** 图表类型 */
14
14
public type : string = 'radial-bar' ;
15
15
16
+ /**
17
+ * @override
18
+ * @param data
19
+ */
20
+ public changeData ( data ) {
21
+ this . updateOption ( { data } ) ;
22
+ this . chart . changeData ( data ) ;
23
+ }
24
+
16
25
/**
17
26
* 获取默认配置
18
27
*/
You can’t perform that action at this time.
0 commit comments