1
- import { isFunction , isObject } from '@antv/util' ;
1
+ import { isArray } from '@antv/util' ;
2
2
import { Params } from '../../core/adaptor' ;
3
- import { interaction , animation , theme } from '../../adaptor/common' ;
4
- import { findGeometry } from '../../utils ' ;
3
+ import { interaction , animation , theme , tooltip } from '../../adaptor/common' ;
4
+ import { point , schema } from '../../adaptor/geometries ' ;
5
5
import { flow , pick , deepAssign } from '../../utils' ;
6
6
import { AXIS_META_CONFIG_KEYS } from '../../constant' ;
7
7
import { BoxOptions } from './types' ;
@@ -14,18 +14,38 @@ import { transformData } from './utils';
14
14
*/
15
15
function field ( params : Params < BoxOptions > ) : Params < BoxOptions > {
16
16
const { chart, options } = params ;
17
- const { xField, yField, groupField, color } = options ;
17
+ const { xField, yField, groupField, color, tooltip , boxStyle } = options ;
18
18
19
- const yFieldName = Array . isArray ( yField ) ? BOX_RANGE : yField ;
19
+ chart . data ( transformData ( options . data , yField ) ) ;
20
20
21
- const geometry = chart . schema ( ) . position ( `${ xField } *${ yFieldName } ` ) . shape ( 'box' ) ;
21
+ const yFieldName = isArray ( yField ) ? BOX_RANGE : yField ;
22
+ const rawFields = yField ? ( isArray ( yField ) ? yField : [ yField ] ) : [ ] ;
22
23
23
- // set group field as color channel
24
- if ( groupField ) {
25
- geometry . color ( groupField , color ) . adjust ( 'dodge' ) ;
24
+ let tooltipOptions = tooltip ;
25
+ if ( tooltipOptions !== false ) {
26
+ tooltipOptions = deepAssign ( { } , { fields : isArray ( yField ) ? yField : [ ] } , tooltipOptions ) ;
26
27
}
27
28
28
- chart . data ( transformData ( options . data , yField ) ) ;
29
+ const { ext } = schema (
30
+ deepAssign ( { } , params , {
31
+ options : {
32
+ xField,
33
+ yField : yFieldName ,
34
+ seriesField : groupField ,
35
+ tooltip : tooltipOptions ,
36
+ rawFields,
37
+ schema : {
38
+ shape : 'box' ,
39
+ color,
40
+ style : boxStyle ,
41
+ } ,
42
+ } ,
43
+ } )
44
+ ) ;
45
+
46
+ if ( groupField ) {
47
+ ext . geometry . adjust ( 'dodge' ) ;
48
+ }
29
49
30
50
return params ;
31
51
}
@@ -38,24 +58,17 @@ function outliersPoint(params: Params<BoxOptions>): Params<BoxOptions> {
38
58
39
59
const outliersView = chart . createView ( { padding, id : OUTLIERS_VIEW_ID } ) ;
40
60
outliersView . data ( data ) ;
61
+
62
+ point ( {
63
+ chart : outliersView ,
64
+ options : {
65
+ xField,
66
+ yField : outliersField ,
67
+ point : { shape : 'circle' , style : outliersStyle } ,
68
+ } ,
69
+ } ) ;
70
+
41
71
outliersView . axis ( false ) ;
42
- const geometry = outliersView . point ( ) . position ( `${ xField } *${ outliersField } ` ) . shape ( 'circle' ) ;
43
-
44
- /**
45
- * style 的几种情况
46
- * g.style({ fill: 'red' });
47
- * g.style('x*y*color', (x, y, color) => ({ fill: 'red' }));
48
- */
49
- if ( isFunction ( outliersStyle ) ) {
50
- geometry . style ( `${ xField } *${ outliersField } ` , ( _x : string , _outliers : number ) => {
51
- return outliersStyle ( {
52
- [ xField ] : _x ,
53
- [ outliersField ] : _outliers ,
54
- } ) ;
55
- } ) ;
56
- } else if ( isObject ( outliersStyle ) ) {
57
- geometry . style ( outliersStyle ) ;
58
- }
59
72
60
73
return params ;
61
74
}
@@ -137,55 +150,10 @@ export function legend(params: Params<BoxOptions>): Params<BoxOptions> {
137
150
return params ;
138
151
}
139
152
140
- /**
141
- * 样式
142
- * @param params
143
- */
144
- function style ( params : Params < BoxOptions > ) : Params < BoxOptions > {
145
- const { chart, options } = params ;
146
- const { xField, yField, boxStyle } = options ;
147
-
148
- const geometry = findGeometry ( chart , 'schema' ) ;
149
- const yFieldName = Array . isArray ( yField ) ? BOX_RANGE : yField ;
150
-
151
- /**
152
- * style 的几种情况
153
- * g.style({ fill: 'red' });
154
- * g.style('x*y*color', (x, y, color) => ({ fill: 'red' }));
155
- */
156
- if ( isFunction ( boxStyle ) ) {
157
- geometry . style ( `${ xField } *${ yFieldName } ` , ( _x : string , _y : number ) => {
158
- return boxStyle ( {
159
- [ xField ] : _x ,
160
- [ yFieldName ] : _y ,
161
- } ) ;
162
- } ) ;
163
- } else if ( isObject ( boxStyle ) ) {
164
- geometry . style ( boxStyle ) ;
165
- }
166
-
167
- return params ;
168
- }
169
-
170
- /**
171
- * tooltip 配置
172
- * @param params
173
- */
174
- export function tooltip ( params : Params < BoxOptions > ) : Params < BoxOptions > {
175
- const { chart, options } = params ;
176
- const { tooltip } = options ;
177
-
178
- if ( tooltip !== undefined ) {
179
- chart . tooltip ( tooltip ) ;
180
- }
181
-
182
- return params ;
183
- }
184
-
185
153
/**
186
154
* 箱型图适配器
187
155
* @param params
188
156
*/
189
157
export function adaptor ( params : Params < BoxOptions > ) {
190
- return flow ( field , outliersPoint , meta , axis , style , legend , tooltip , interaction , animation , theme ) ( params ) ;
158
+ return flow ( field , outliersPoint , meta , axis , legend , tooltip , interaction , animation , theme ) ( params ) ;
191
159
}
0 commit comments