Skip to content

Commit

Permalink
fix tickFormat type inference for empty domain (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Nov 15, 2024
1 parent 653af62 commit ff7d83c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/marks/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,10 @@ export function inferTickFormat(scale, data, ticks, tickFormat, anchor) {
? inferTimeFormat(scale.type, data, anchor) ?? formatDefault
: scale.tickFormat
? scale.tickFormat(typeof ticks === "number" ? ticks : null, tickFormat)
: typeof tickFormat === "string" && scale.domain().length > 0
? (isTemporal(scale.domain()) ? utcFormat : format)(tickFormat)
: tickFormat === undefined
? formatDefault
: typeof tickFormat === "string"
? (isTemporal(scale.domain()) ? utcFormat : format)(tickFormat)
: constant(tickFormat);
}

Expand Down
17 changes: 17 additions & 0 deletions test/output/tickFormatEmptyDomain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions test/output/tickFormatEmptyFacetDomain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export * from "./style-overrides.js";
export * from "./symbol-set.js";
export * from "./text-overflow.js";
export * from "./this-is-just-to-say.js";
export * from "./tick-format.js";
export * from "./time-axis.js";
export * from "./tip-format.js";
export * from "./tip.js";
Expand Down
9 changes: 9 additions & 0 deletions test/plots/tick-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Plot from "@observablehq/plot";

export async function tickFormatEmptyDomain() {
return Plot.plot({y: {tickFormat: "%W"}, marks: [Plot.barX([]), Plot.frame()]});
}

export async function tickFormatEmptyFacetDomain() {
return Plot.plot({fy: {tickFormat: "%W"}, marks: [Plot.barX([]), Plot.frame()]});
}

0 comments on commit ff7d83c

Please sign in to comment.