1
- import { deepMix , isFunction } from '@antv/util' ;
1
+ import { deepMix , isFunction , isNumber , isString } from '@antv/util' ;
2
2
import { Params } from '../../core/adaptor' ;
3
- import { flow , pick , log , LEVEL } from '../../utils' ;
3
+ import { flow , pick } from '../../utils' ;
4
4
import { ScatterOptions } from './types' ;
5
5
import { tooltip , interaction , animation , theme } from '../../adaptor/common' ;
6
6
import { findGeometry } from '../../utils' ;
7
7
import { AXIS_META_CONFIG_KEYS } from '../../constant' ;
8
- import { REFLECTS } from './reflect' ;
9
8
10
9
/**
11
10
* 字段
12
11
* @param params
13
12
*/
14
13
function field ( params : Params < ScatterOptions > ) : Params < ScatterOptions > {
15
14
const { chart, options } = params ;
16
- const { data, xField, yField, type } = options ;
15
+ const { data, xField, yField, type, color , colorField , shape , shapeField , size , sizeField } = options ;
17
16
18
17
// 散点图操作逻辑
19
18
chart . data ( data ) ;
@@ -24,27 +23,32 @@ function field(params: Params<ScatterOptions>): Params<ScatterOptions> {
24
23
geometry . adjust ( type ) ;
25
24
}
26
25
27
- // 统一处理 color、 size、 shape
28
- const reflectKeys = Object . keys ( REFLECTS ) ;
29
- reflectKeys . forEach ( ( key : string ) => {
30
- if ( options [ key ] || options [ REFLECTS [ key ] . field ] ) {
31
- let validateRules = false ;
32
- ( REFLECTS [ key ] . rules || [ ] ) . forEach ( ( fn : ( arg : any ) => boolean ) => {
33
- // 满足任一规则即可
34
- if ( fn && fn ( options [ key ] ) ) {
35
- validateRules = true ;
36
- }
37
- } ) ;
38
- if ( validateRules ) {
39
- if ( ! options [ REFLECTS [ key ] . field ] ) {
40
- log ( LEVEL . WARN , false , '*** For accurate mapping, specify %s please. ***' , REFLECTS [ key ] . field ) ;
41
- }
42
- geometry [ REFLECTS [ key ] . action ] ( options [ REFLECTS [ key ] . field ] || xField , options [ key ] ) ;
43
- } else {
44
- geometry [ REFLECTS [ key ] . action ] ( options [ key ] || options [ REFLECTS [ key ] . field ] ) ;
45
- }
26
+ // shape
27
+ if ( shape ) {
28
+ if ( isString ( shape ) ) {
29
+ geometry . shape ( shape ) ;
30
+ } else {
31
+ geometry . shape ( shapeField || xField , shape ) ;
46
32
}
47
- } ) ;
33
+ }
34
+
35
+ // color
36
+ if ( color ) {
37
+ if ( isString ( color ) ) {
38
+ geometry . color ( color ) ;
39
+ } else {
40
+ geometry . color ( colorField || xField , color ) ;
41
+ }
42
+ }
43
+
44
+ // size
45
+ if ( size ) {
46
+ if ( isNumber ( size ) ) {
47
+ geometry . size ( size ) ;
48
+ } else {
49
+ geometry . size ( sizeField || xField , size ) ;
50
+ }
51
+ }
48
52
49
53
return params ;
50
54
}
0 commit comments