@@ -199,43 +199,79 @@ describe('compile/scale', () => {
199
199
} ) ;
200
200
201
201
describe ( 'zero' , ( ) => {
202
- it ( 'should return true when mapping a quantitative field to x with scale.domain = "unaggregated"' , ( ) => {
202
+ it ( 'should return default (undefined) when mapping a quantitative field to x with scale.domain = "unaggregated"' , ( ) => {
203
203
expect (
204
- rules . zero ( 'x' , { field : 'a' , type : 'quantitative' } , 'unaggregated' , { type : 'point' } , 'linear' )
205
- ) . toBeTruthy ( ) ;
204
+ rules . zero ( 'x' , { field : 'a' , type : 'quantitative' } , 'unaggregated' , { type : 'point' } , 'linear' , undefined , false )
205
+ ) . toBeUndefined ( ) ;
206
206
} ) ;
207
207
208
208
it ( 'should return true when mapping a quantitative field to size' , ( ) => {
209
- expect ( rules . zero ( 'size' , { field : 'a' , type : 'quantitative' } , undefined , { type : 'point' } , 'linear' ) ) . toBeTruthy ( ) ;
209
+ expect (
210
+ rules . zero ( 'size' , { field : 'a' , type : 'quantitative' } , undefined , { type : 'point' } , 'linear' , undefined , false )
211
+ ) . toBeTruthy ( ) ;
210
212
} ) ;
211
213
212
214
it ( 'should return false when mapping a ordinal field to size' , ( ) => {
213
- expect ( ! rules . zero ( 'size' , { field : 'a' , type : 'ordinal' } , undefined , { type : 'point' } , 'linear' ) ) . toBeTruthy ( ) ;
215
+ expect (
216
+ ! rules . zero ( 'size' , { field : 'a' , type : 'ordinal' } , undefined , { type : 'point' } , 'linear' , undefined , false )
217
+ ) . toBeTruthy ( ) ;
214
218
} ) ;
215
219
216
- it ( 'should return true when mapping a non-binned quantitative field to x/y of point' , ( ) => {
220
+ it ( 'should return default (undefined) when mapping a non-binned quantitative field to x/y of point' , ( ) => {
217
221
for ( const channel of [ 'x' , 'y' ] as const ) {
218
222
expect (
219
- rules . zero ( channel , { field : 'a' , type : 'quantitative' } , undefined , { type : 'point' } , 'linear' )
220
- ) . toBeTruthy ( ) ;
223
+ rules . zero (
224
+ channel ,
225
+ { field : 'a' , type : 'quantitative' } ,
226
+ undefined ,
227
+ { type : 'point' } ,
228
+ 'linear' ,
229
+ undefined ,
230
+ false
231
+ )
232
+ ) . toBeUndefined ( ) ;
221
233
}
222
234
} ) ;
223
235
224
236
it ( 'should return false when mapping a quantitative field to dimension axis of bar, line, and area' , ( ) => {
225
237
for ( const mark of [ BAR , AREA , LINE ] ) {
226
238
expect (
227
- rules . zero ( 'x' , { field : 'a' , type : 'quantitative' } , undefined , { type : mark , orient : 'vertical' } , 'linear' )
239
+ rules . zero (
240
+ 'x' ,
241
+ { field : 'a' , type : 'quantitative' } ,
242
+ undefined ,
243
+ { type : mark , orient : 'vertical' } ,
244
+ 'linear' ,
245
+ undefined ,
246
+ false
247
+ )
228
248
) . toBe ( false ) ;
229
249
expect (
230
- rules . zero ( 'y' , { field : 'a' , type : 'quantitative' } , undefined , { type : mark , orient : 'horizontal' } , 'linear' )
250
+ rules . zero (
251
+ 'y' ,
252
+ { field : 'a' , type : 'quantitative' } ,
253
+ undefined ,
254
+ { type : mark , orient : 'horizontal' } ,
255
+ 'linear' ,
256
+ undefined ,
257
+ false
258
+ )
231
259
) . toBe ( false ) ;
232
260
}
233
261
} ) ;
234
262
235
263
it ( 'should return false when mapping a binned quantitative field to x/y' , ( ) => {
236
264
for ( const channel of [ 'x' , 'y' ] as const ) {
237
265
expect (
238
- ! rules . zero ( channel , { bin : true , field : 'a' , type : 'quantitative' } , undefined , { type : 'point' } , 'linear' )
266
+ ! rules . zero (
267
+ channel ,
268
+ { bin : true , field : 'a' , type : 'quantitative' } ,
269
+ undefined ,
270
+ { type : 'point' } ,
271
+ 'linear' ,
272
+ undefined ,
273
+ false
274
+ )
239
275
) . toBeTruthy ( ) ;
240
276
}
241
277
} ) ;
@@ -252,10 +288,78 @@ describe('compile/scale', () => {
252
288
} ,
253
289
[ 3 , 5 ] ,
254
290
{ type : 'point' } ,
255
- 'linear'
291
+ 'linear' ,
292
+ undefined ,
293
+ false
256
294
)
257
295
) . toBeTruthy ( ) ;
258
296
}
259
297
} ) ;
298
+
299
+ it ( `should return config.scale.zero instead of true if it is specified` , ( ) => {
300
+ const configZero = false ;
301
+ for ( const channel of [ 'x' , 'y' ] as const ) {
302
+ expect (
303
+ rules . zero (
304
+ channel ,
305
+ { field : 'a' , type : 'quantitative' } ,
306
+ undefined ,
307
+ { type : 'point' } ,
308
+ 'linear' ,
309
+ { zero : configZero } ,
310
+ false
311
+ )
312
+ ) . toBe ( configZero ) ;
313
+ }
314
+
315
+ expect (
316
+ rules . zero (
317
+ 'size' ,
318
+ { field : 'a' , type : 'ordinal' } ,
319
+ undefined ,
320
+ { type : 'point' } ,
321
+ 'linear' ,
322
+ { zero : configZero } ,
323
+ false
324
+ )
325
+ ) . toBe ( configZero ) ;
326
+
327
+ // ranged bar/area should take default configZero
328
+ expect (
329
+ rules . zero ( 'x' , { field : 'a' , type : 'quantitative' } , undefined , { type : BAR } , 'linear' , { zero : configZero } , true )
330
+ ) . toBe ( configZero ) ;
331
+ } ) ;
332
+
333
+ it ( `should return true for x/y scales of the non-ranged area/bar charts regardless to config` , ( ) => {
334
+ for ( const mark of [ BAR , AREA ] ) {
335
+ for ( const channel of [ 'x' , 'y' ] as const ) {
336
+ expect (
337
+ rules . zero (
338
+ channel ,
339
+ { field : 'a' , type : 'quantitative' } ,
340
+ undefined ,
341
+ { type : mark } ,
342
+ 'linear' ,
343
+ { zero : false } ,
344
+ false
345
+ )
346
+ ) . toBe ( true ) ;
347
+ }
348
+ }
349
+ } ) ;
350
+
351
+ it ( `should return true for the continuous & quantitative size scale regardless to config` , ( ) => {
352
+ expect (
353
+ rules . zero (
354
+ 'size' ,
355
+ { field : 'a' , type : 'quantitative' } ,
356
+ undefined ,
357
+ { type : 'point' } ,
358
+ 'linear' ,
359
+ { zero : false } ,
360
+ false
361
+ )
362
+ ) . toBe ( true ) ;
363
+ } ) ;
260
364
} ) ;
261
365
} ) ;
0 commit comments