Skip to content

Commit 90f71ce

Browse files
committed
move tickFormat function detection
1 parent afcb8bc commit 90f71ce

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/legends/swatches.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function legendItems(scale, options = {}, swatch) {
8686
} = options;
8787
const context = createContext(options);
8888
className = maybeClassName(className);
89-
if (typeof tickFormat !== "function") tickFormat = inferTickFormat(scale.scale, scale.domain, undefined, tickFormat);
89+
tickFormat = inferTickFormat(scale.scale, scale.domain, undefined, tickFormat);
9090

9191
const swatches = create("div", context).attr(
9292
"class",

src/marks/axis.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,7 @@ function inferTickCount(scale, tickSpacing) {
628628
}
629629

630630
function inferTextChannel(scale, data, ticks, tickFormat, anchor) {
631-
return {
632-
value: typeof tickFormat === "function" ? tickFormat : inferTickFormat(scale, data, ticks, tickFormat, anchor)
633-
};
631+
return {value: inferTickFormat(scale, data, ticks, tickFormat, anchor)};
634632
}
635633

636634
// 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) {
640638
// possible, or the default ISO format (2014-01-26). TODO We need a better way
641639
// to infer whether the ordinal scale is UTC or local time.
642640
export function inferTickFormat(scale, data, ticks, tickFormat, anchor) {
643-
return tickFormat === undefined && data && isTemporal(data)
641+
return typeof tickFormat === "function"
642+
? tickFormat
643+
: tickFormat === undefined && data && isTemporal(data)
644644
? inferTimeFormat(data, anchor) ?? formatDefault
645645
: scale.tickFormat
646646
? scale.tickFormat(typeof ticks === "number" ? ticks : null, tickFormat)

0 commit comments

Comments
 (0)