Skip to content

Commit

Permalink
move tickFormat function detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 23, 2023
1 parent afcb8bc commit 90f71ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/legends/swatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/marks/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 90f71ce

Please sign in to comment.