@@ -4,12 +4,31 @@ import { Datum } from '../../types';
4
4
import { Params } from '../../core/adaptor' ;
5
5
import { interaction , animation , theme , state , scale , annotation } from '../../adaptor/common' ;
6
6
import { interval } from '../../adaptor/geometries' ;
7
+ import { getLocale } from '../../core/locale' ;
7
8
import { findGeometry , flow , transformLabel , deepAssign } from '../../utils' ;
8
9
import { Y_FIELD , ABSOLUTE_FIELD , DIFF_FIELD , IS_TOTAL } from './constant' ;
9
10
import { WaterfallOptions } from './types' ;
10
11
import { transformData } from './utils' ;
11
12
import './shape' ;
12
13
14
+ /**
15
+ * 处理默认配置项
16
+ * @param params
17
+ * @returns
18
+ */
19
+ function defaultOptions ( params : Params < WaterfallOptions > ) : Params < WaterfallOptions > {
20
+ const { locale, total } = params . options ;
21
+
22
+ const localeTotalLabel = getLocale ( locale ) . get ( [ 'waterfall' , 'total' ] ) ;
23
+
24
+ if ( total && typeof total . label !== 'string' && localeTotalLabel ) {
25
+ // @ts -ignore
26
+ params . options . total . label = localeTotalLabel ;
27
+ }
28
+
29
+ return params ;
30
+ }
31
+
13
32
/**
14
33
* 字段
15
34
* @param params
@@ -109,23 +128,26 @@ function axis(params: Params<WaterfallOptions>): Params<WaterfallOptions> {
109
128
*/
110
129
function legend ( params : Params < WaterfallOptions > ) : Params < WaterfallOptions > {
111
130
const { chart, options } = params ;
112
- const { legend, total, risingFill, fallingFill } = options ;
131
+ const { legend, total, risingFill, fallingFill, locale } = options ;
132
+
133
+ const i18n = getLocale ( locale ) ;
113
134
114
135
if ( legend === false ) {
115
136
chart . legend ( false ) ;
116
137
} else {
117
138
const items = [
118
139
{
119
- name : '增加' ,
140
+ name : i18n . get ( [ 'general' , 'increase' ] ) ,
120
141
value : 'increase' ,
121
142
marker : { symbol : 'square' , style : { r : 5 , fill : risingFill } } ,
122
143
} ,
123
144
{
124
- name : '减少' ,
145
+ name : i18n . get ( [ 'general' , 'decrease' ] ) ,
125
146
value : 'decrease' ,
126
147
marker : { symbol : 'square' , style : { r : 5 , fill : fallingFill } } ,
127
148
} ,
128
149
] ;
150
+
129
151
if ( total ) {
130
152
items . push ( {
131
153
name : total . label || '' ,
@@ -209,5 +231,18 @@ export function tooltip(params: Params<WaterfallOptions>): Params<WaterfallOptio
209
231
* @param params
210
232
*/
211
233
export function adaptor ( params : Params < WaterfallOptions > ) {
212
- return flow ( geometry , meta , axis , legend , tooltip , label , state , theme , interaction , animation , annotation ( ) ) ( params ) ;
234
+ return flow (
235
+ defaultOptions ,
236
+ theme ,
237
+ geometry ,
238
+ meta ,
239
+ axis ,
240
+ legend ,
241
+ tooltip ,
242
+ label ,
243
+ state ,
244
+ interaction ,
245
+ animation ,
246
+ annotation ( )
247
+ ) ( params ) ;
213
248
}
0 commit comments