1
1
import { deepMix , isFunction } from '@antv/util' ;
2
2
import { Params } from '../../core/adaptor' ;
3
- import { flow , pick } from '../../utils' ;
3
+ import { flow , pick , log , LEVEL } from '../../utils' ;
4
4
import { ScatterOptions } from './types' ;
5
- import { tooltip } from '../../common/adaptor' ;
5
+ import { tooltip , interaction , animation , theme } from '../../common/adaptor' ;
6
6
import { findGeometry } from '../../common/helper' ;
7
7
import { AXIS_META_CONFIG_KEYS } from '../../constant' ;
8
8
import { REFLECTS } from './reflect' ;
@@ -13,16 +13,21 @@ import { REFLECTS } from './reflect';
13
13
*/
14
14
function field ( params : Params < ScatterOptions > ) : Params < ScatterOptions > {
15
15
const { chart, options } = params ;
16
- const { data, xField, yField, seriesField } = options ;
16
+ const { data, xField, yField, type } = options ;
17
17
18
18
// 散点图操作逻辑
19
19
chart . data ( data ) ;
20
20
const geometry = chart . point ( ) . position ( `${ xField } *${ yField } ` ) ;
21
21
22
+ // 数据调整
23
+ if ( type ) {
24
+ geometry . adjust ( type ) ;
25
+ }
26
+
22
27
// 统一处理 color、 size、 shape
23
28
const reflectKeys = Object . keys ( REFLECTS ) ;
24
29
reflectKeys . forEach ( ( key : string ) => {
25
- if ( options [ key ] ) {
30
+ if ( options [ key ] || options [ REFLECTS [ key ] . field ] ) {
26
31
let validateRules = false ;
27
32
( REFLECTS [ key ] . rules || [ ] ) . forEach ( ( fn : ( arg : any ) => boolean ) => {
28
33
// 满足任一规则即可
@@ -31,9 +36,12 @@ function field(params: Params<ScatterOptions>): Params<ScatterOptions> {
31
36
}
32
37
} ) ;
33
38
if ( validateRules ) {
34
- geometry [ REFLECTS [ key ] . action ] ( options [ REFLECTS [ key ] . field ] || seriesField || xField , options [ key ] ) ;
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 ] ) ;
35
43
} else {
36
- geometry [ REFLECTS [ key ] . action ] ( options [ key ] ) ;
44
+ geometry [ REFLECTS [ key ] . action ] ( options [ key ] || options [ REFLECTS [ key ] . field ] ) ;
37
45
}
38
46
}
39
47
} ) ;
@@ -80,10 +88,10 @@ function axis(params: Params<ScatterOptions>): Params<ScatterOptions> {
80
88
*/
81
89
function legend ( params : Params < ScatterOptions > ) : Params < ScatterOptions > {
82
90
const { chart, options } = params ;
83
- const { legend, seriesField } = options ;
91
+ const { legend, colorField } = options ;
84
92
85
- if ( legend && seriesField ) {
86
- chart . legend ( seriesField , legend ) ;
93
+ if ( legend && colorField ) {
94
+ chart . legend ( colorField , legend ) ;
87
95
}
88
96
89
97
return params ;
@@ -142,5 +150,5 @@ function label(params: Params<ScatterOptions>): Params<ScatterOptions> {
142
150
*/
143
151
export function adaptor ( params : Params < ScatterOptions > ) {
144
152
// flow 的方式处理所有的配置到 G2 API
145
- flow ( field , meta , axis , legend , tooltip , style , label ) ( params ) ;
153
+ flow ( field , meta , axis , legend , tooltip , style , label , interaction , animation , theme ) ( params ) ;
146
154
}
0 commit comments