1
1
import { isFunction , isString , isNil , get , isArray , isNumber } from '@antv/util' ;
2
2
import { Params } from '../../core/adaptor' ;
3
- import { legend , tooltip , interaction , animation , theme , state , annotation } from '../../adaptor/common' ;
3
+ import { legend , interaction , animation , theme , state , annotation } from '../../adaptor/common' ;
4
+ import { getMappingFunction } from '../../adaptor/geometries/base' ;
4
5
import { interval } from '../../adaptor/geometries' ;
5
6
import { flow , template , transformLabel , deepAssign , renderStatistic } from '../../utils' ;
6
7
import { DEFAULT_OPTIONS } from './contants' ;
@@ -41,9 +42,6 @@ function geometry(params: Params<PieOptions>): Params<PieOptions> {
41
42
} ) ;
42
43
43
44
interval ( p ) ;
44
-
45
- // all zero 额外处理
46
- chart . geometries [ 0 ] . tooltip ( `${ colorField } *${ angleField } ` ) ;
47
45
} else {
48
46
chart . data ( processData ) ;
49
47
@@ -208,13 +206,30 @@ export function pieAnnotation(params: Params<PieOptions>): Params<PieOptions> {
208
206
}
209
207
210
208
/**
211
- * 饼图 tooltip 配置适配,强制 tooltip.shared 为 false
209
+ * 饼图 tooltip 配置
210
+ * 1. 强制 tooltip.shared 为 false
212
211
* @param params
213
212
*/
214
- function adaptorTooltipOptions ( params : Params < PieOptions > ) : Params < PieOptions > {
215
- return get ( params , [ 'options' , 'tooltip' ] ) !== false
216
- ? deepAssign ( { } , params , { options : { tooltip : { shared : false } } } )
217
- : params ;
213
+ function tooltip ( params : Params < PieOptions > ) : Params < PieOptions > {
214
+ const { chart, options } = params ;
215
+ const { tooltip, colorField, angleField } = options ;
216
+
217
+ if ( tooltip === false ) {
218
+ chart . tooltip ( tooltip ) ;
219
+ } else {
220
+ chart . tooltip ( deepAssign ( { } , tooltip , { shared : false } ) ) ;
221
+
222
+ const fields = get ( tooltip , 'fields' ) || [ colorField , angleField ] ;
223
+ let formatter = get ( tooltip , 'formatter' ) ;
224
+
225
+ if ( ! formatter ) {
226
+ // 主要解决 all zero, 对于非 all zero 也适用
227
+ formatter = ( datum ) => ( { name : datum [ colorField ] , value : datum [ angleField ] } ) ;
228
+ }
229
+ chart . geometries [ 0 ] . tooltip ( fields . join ( '*' ) , getMappingFunction ( fields , formatter ) ) ;
230
+ }
231
+
232
+ return params ;
218
233
}
219
234
220
235
/**
@@ -230,7 +245,7 @@ export function adaptor(params: Params<PieOptions>) {
230
245
theme ,
231
246
coordinate ,
232
247
legend ,
233
- ( args ) => tooltip ( adaptorTooltipOptions ( args ) ) ,
248
+ tooltip ,
234
249
label ,
235
250
state ,
236
251
/** 指标卡中心文本 放在下层 */
0 commit comments