1
+ import { each } from '@antv/util' ;
2
+ import { Element } from '@antv/g2' ;
1
3
import { Plot } from '../../core/plot' ;
2
4
import { Adaptor } from '../../core/adaptor' ;
3
- import { ChordOptions } from './types' ;
5
+ import { StateName , StateCondition , StateObject } from '../../types' ;
6
+ import { getAllElementsRecursively } from '../../utils' ;
4
7
import { adaptor } from './adaptor' ;
5
8
import { DEFAULT_OPTIONS } from './constant' ;
9
+ import { ChordOptions } from './types' ;
6
10
7
11
export type { ChordOptions } ;
8
12
@@ -20,6 +24,42 @@ export class Chord extends Plot<ChordOptions> {
20
24
/** 图表类型 */
21
25
public type : string = 'chord' ;
22
26
27
+ /**
28
+ * @override
29
+ * 设置状态
30
+ * @param type 状态类型,支持 'active' | 'inactive' | 'selected' 三种
31
+ * @param conditions 条件,支持数组
32
+ * @param status 是否激活,默认 true
33
+ */
34
+ public setState ( type : StateName , condition : StateCondition , status : boolean = true ) {
35
+ const elements = getAllElementsRecursively ( this . chart ) ;
36
+
37
+ each ( elements , ( ele : Element ) => {
38
+ if ( condition ( ele . getData ( ) ) ) {
39
+ ele . setState ( type , status ) ;
40
+ }
41
+ } ) ;
42
+ }
43
+
44
+ /**
45
+ * @override
46
+ * 获取状态
47
+ */
48
+ public getStates ( ) : StateObject [ ] {
49
+ const elements = getAllElementsRecursively ( this . chart ) ;
50
+
51
+ const stateObjects : StateObject [ ] = [ ] ;
52
+ each ( elements , ( element : Element ) => {
53
+ const data = element . getData ( ) ;
54
+ const states = element . getStates ( ) ;
55
+ each ( states , ( state ) => {
56
+ stateObjects . push ( { data, state, geometry : element . geometry , element } ) ;
57
+ } ) ;
58
+ } ) ;
59
+
60
+ return stateObjects ;
61
+ }
62
+
23
63
protected getDefaultOptions ( ) {
24
64
return Chord . getDefaultOptions ( ) ;
25
65
}
0 commit comments