diff --git a/src/legends/swatches.js b/src/legends/swatches.js index 5685f5c9e3..e5876aa546 100644 --- a/src/legends/swatches.js +++ b/src/legends/swatches.js @@ -86,7 +86,7 @@ function legendItems(scale, options = {}, swatch) { } = options; const context = createContext(options); className = maybeClassName(className); - if (typeof tickFormat !== "function") tickFormat = inferTickFormat(scale.scale, scale.domain, undefined, tickFormat); + tickFormat = inferTickFormat(scale.scale, scale.domain, undefined, tickFormat); const swatches = create("div", context).attr( "class", diff --git a/src/marks/axis.js b/src/marks/axis.js index 007425e9d9..e34fc34833 100644 --- a/src/marks/axis.js +++ b/src/marks/axis.js @@ -628,9 +628,7 @@ function inferTickCount(scale, tickSpacing) { } function inferTextChannel(scale, data, ticks, tickFormat, anchor) { - return { - value: typeof tickFormat === "function" ? tickFormat : inferTickFormat(scale, data, ticks, tickFormat, anchor) - }; + return {value: inferTickFormat(scale, data, ticks, tickFormat, anchor)}; } // D3’s ordinal scales simply use toString by default, but if the ordinal scale @@ -640,7 +638,9 @@ function inferTextChannel(scale, data, ticks, tickFormat, anchor) { // possible, or the default ISO format (2014-01-26). TODO We need a better way // to infer whether the ordinal scale is UTC or local time. export function inferTickFormat(scale, data, ticks, tickFormat, anchor) { - return tickFormat === undefined && data && isTemporal(data) + return typeof tickFormat === "function" + ? tickFormat + : tickFormat === undefined && data && isTemporal(data) ? inferTimeFormat(data, anchor) ?? formatDefault : scale.tickFormat ? scale.tickFormat(typeof ticks === "number" ? ticks : null, tickFormat)