Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 970f638

Browse files
committedNov 15, 2024··
fix tickFormat type inference for empty domain
1 parent 700c6ee commit 970f638

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed
 

‎src/marks/axis.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ export function inferTickFormat(scale, data, ticks, tickFormat, anchor) {
672672
? inferTimeFormat(scale.type, data, anchor) ?? formatDefault
673673
: scale.tickFormat
674674
? scale.tickFormat(typeof ticks === "number" ? ticks : null, tickFormat)
675+
: typeof tickFormat === "string" && scale.domain().length > 0
676+
? (isTemporal(scale.domain()) ? utcFormat : format)(tickFormat)
675677
: tickFormat === undefined
676678
? formatDefault
677-
: typeof tickFormat === "string"
678-
? (isTemporal(scale.domain()) ? utcFormat : format)(tickFormat)
679679
: constant(tickFormat);
680680
}
681681

‎test/output/tickFormatEmptyDomain.svg

+17
Loading
+17
Loading

‎test/plots/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export * from "./style-overrides.js";
308308
export * from "./symbol-set.js";
309309
export * from "./text-overflow.js";
310310
export * from "./this-is-just-to-say.js";
311+
export * from "./tick-format.js";
311312
export * from "./time-axis.js";
312313
export * from "./tip-format.js";
313314
export * from "./tip.js";

‎test/plots/tick-format.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export async function tickFormatEmptyDomain() {
4+
return Plot.plot({y: {tickFormat: "%W"}, marks: [Plot.barX([]), Plot.frame()]});
5+
}
6+
7+
export async function tickFormatEmptyFacetDomain() {
8+
return Plot.plot({fy: {tickFormat: "%W"}, marks: [Plot.barX([]), Plot.frame()]});
9+
}

0 commit comments

Comments
 (0)
Please sign in to comment.