1
- import { isFunction } from '@antv/util' ;
1
+ import { isNil } from '@antv/util' ;
2
2
import { Params } from '../../core/adaptor' ;
3
3
import { flow } from '../../utils' ;
4
- import { scale } from '../../adaptor/common' ;
4
+ import { scale , animation , theme } from '../../adaptor/common' ;
5
+ import { geometry } from '../ring-progress/adaptor' ;
5
6
import { ProgressOptions } from './types' ;
6
7
7
8
/**
8
- * 字段
9
- * @param params
10
- */
11
- function field ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
12
- const { chart, options } = params ;
13
- const { percent, color } = options ;
14
-
15
- const data = [
16
- {
17
- type : 'current' ,
18
- percent : percent ,
19
- } ,
20
- {
21
- type : 'target' ,
22
- percent : 1 - percent ,
23
- } ,
24
- ] ;
25
-
26
- chart . data ( data ) ;
27
-
28
- const geometry = chart . interval ( ) . position ( '1*percent' ) . adjust ( 'stack' ) ;
29
- const values = isFunction ( color ) ? color ( percent ) : color || [ '#FAAD14' , '#E8EDF3' ] ;
30
-
31
- geometry . color ( 'type' , values ) ;
32
-
33
- return params ;
34
- }
35
-
36
- /**
37
- * axis 配置
38
- * @param params
39
- */
40
- function axis ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
41
- const { chart } = params ;
42
-
43
- chart . axis ( false ) ;
44
-
45
- return params ;
46
- }
47
-
48
- /**
49
- * legend 配置
50
- * @param params
51
- */
52
- function legend ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
53
- const { chart } = params ;
54
-
55
- chart . legend ( false ) ;
56
-
57
- return params ;
58
- }
59
-
60
- /**
61
- * tooltip 配置
9
+ * coordinate 配置
62
10
* @param params
63
11
*/
64
- function tooltip ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
12
+ function coordinate ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
65
13
const { chart } = params ;
66
14
67
- chart . tooltip ( false ) ;
15
+ chart . coordinate ( 'rect' ) . transpose ( ) ;
68
16
69
17
return params ;
70
18
}
71
19
72
20
/**
73
- * 样式
21
+ * widthRatio 配置
74
22
* @param params
75
23
*/
76
- function style ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
24
+ function widthRatio ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
77
25
const { chart, options } = params ;
78
- const { progressStyle } = options ;
26
+ const { barWidthRatio } = options ;
79
27
80
- const geometry = chart . geometries [ 0 ] ;
81
- if ( progressStyle && geometry ) {
82
- if ( isFunction ( progressStyle ) ) {
83
- geometry . style ( '1*percent*type' , progressStyle ) ;
84
- } else {
85
- geometry . style ( progressStyle ) ;
86
- }
28
+ if ( ! isNil ( widthRatio ) ) {
29
+ chart . theme ( {
30
+ columnWidthRatio : barWidthRatio ,
31
+ } ) ;
87
32
}
88
- return params ;
89
- }
90
-
91
- /**
92
- * coordinate 配置
93
- * @param params
94
- */
95
- function coordinate ( params : Params < ProgressOptions > ) : Params < ProgressOptions > {
96
- const { chart } = params ;
97
-
98
- chart . coordinate ( 'rect' ) . transpose ( ) ;
99
33
100
34
return params ;
101
35
}
@@ -106,5 +40,5 @@ function coordinate(params: Params<ProgressOptions>): Params<ProgressOptions> {
106
40
* @param options
107
41
*/
108
42
export function adaptor ( params : Params < ProgressOptions > ) {
109
- return flow ( field , scale ( { } ) , axis , legend , tooltip , style , coordinate ) ( params ) ;
43
+ return flow ( geometry , scale ( { } ) , coordinate , widthRatio , animation , theme ) ( params ) ;
110
44
}
0 commit comments