@@ -24,10 +24,10 @@ export class AxisX {
24
24
} = { } ) {
25
25
this . name = name ;
26
26
this . axis = keyword ( axis , "axis" , [ "top" , "bottom" ] ) ;
27
- this . ticks = ticks ;
27
+ this . ticks = maybeTicks ( ticks ) ;
28
28
this . tickSize = number ( tickSize ) ;
29
29
this . tickPadding = number ( tickPadding ) ;
30
- this . tickFormat = tickFormat ;
30
+ this . tickFormat = maybeTickFormat ( tickFormat ) ;
31
31
this . fontVariant = impliedString ( fontVariant , "normal" ) ;
32
32
this . grid = boolean ( grid ) ;
33
33
this . label = string ( label ) ;
@@ -117,10 +117,10 @@ export class AxisY {
117
117
} = { } ) {
118
118
this . name = name ;
119
119
this . axis = keyword ( axis , "axis" , [ "left" , "right" ] ) ;
120
- this . ticks = ticks ;
120
+ this . ticks = maybeTicks ( ticks ) ;
121
121
this . tickSize = number ( tickSize ) ;
122
122
this . tickPadding = number ( tickPadding ) ;
123
- this . tickFormat = tickFormat ;
123
+ this . tickFormat = maybeTickFormat ( tickFormat ) ;
124
124
this . fontVariant = impliedString ( fontVariant , "normal" ) ;
125
125
this . grid = boolean ( grid ) ;
126
126
this . label = string ( label ) ;
@@ -234,10 +234,18 @@ function gridFacetY(index, fx, tx) {
234
234
. attr ( "d" , ( index ? take ( domain , index ) : domain ) . map ( v => `M${ fx ( v ) + tx } ,0h${ dx } ` ) . join ( "" ) ) ;
235
235
}
236
236
237
+ function maybeTicks ( ticks ) {
238
+ return ticks === null ? [ ] : ticks ;
239
+ }
240
+
241
+ function maybeTickFormat ( tickFormat ) {
242
+ return tickFormat === null ? ( ) => null : tickFormat ;
243
+ }
244
+
237
245
// D3 doesn’t provide a tick format for ordinal scales; we want shorthand when
238
246
// an ordinal domain is numbers or dates, and we want null to mean the empty
239
247
// string, not the default identity format.
240
- export function maybeTickFormat ( tickFormat , domain ) {
248
+ export function maybeAutoTickFormat ( tickFormat , domain ) {
241
249
return tickFormat === undefined ? ( isTemporal ( domain ) ? formatIsoDate : string )
242
250
: typeof tickFormat === "function" ? tickFormat
243
251
: ( typeof tickFormat === "string" ? ( isTemporal ( domain ) ? utcFormat : format )
@@ -246,7 +254,7 @@ export function maybeTickFormat(tickFormat, domain) {
246
254
247
255
function createAxis ( axis , scale , { ticks, tickSize, tickPadding, tickFormat} ) {
248
256
if ( ! scale . tickFormat ) {
249
- tickFormat = maybeTickFormat ( tickFormat , scale . domain ( ) ) ;
257
+ tickFormat = maybeAutoTickFormat ( tickFormat , scale . domain ( ) ) ;
250
258
}
251
259
return axis ( scale )
252
260
. ticks ( Array . isArray ( ticks ) ? null : ticks , typeof tickFormat === "function" ? null : tickFormat )
0 commit comments