Skip to content

Commit dcd9ec4

Browse files
authored
null ticks, null tickFormat (#781)
1 parent c9062a6 commit dcd9ec4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/axis.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export class AxisX {
2424
} = {}) {
2525
this.name = name;
2626
this.axis = keyword(axis, "axis", ["top", "bottom"]);
27-
this.ticks = ticks;
27+
this.ticks = maybeTicks(ticks);
2828
this.tickSize = number(tickSize);
2929
this.tickPadding = number(tickPadding);
30-
this.tickFormat = tickFormat;
30+
this.tickFormat = maybeTickFormat(tickFormat);
3131
this.fontVariant = impliedString(fontVariant, "normal");
3232
this.grid = boolean(grid);
3333
this.label = string(label);
@@ -117,10 +117,10 @@ export class AxisY {
117117
} = {}) {
118118
this.name = name;
119119
this.axis = keyword(axis, "axis", ["left", "right"]);
120-
this.ticks = ticks;
120+
this.ticks = maybeTicks(ticks);
121121
this.tickSize = number(tickSize);
122122
this.tickPadding = number(tickPadding);
123-
this.tickFormat = tickFormat;
123+
this.tickFormat = maybeTickFormat(tickFormat);
124124
this.fontVariant = impliedString(fontVariant, "normal");
125125
this.grid = boolean(grid);
126126
this.label = string(label);
@@ -234,10 +234,18 @@ function gridFacetY(index, fx, tx) {
234234
.attr("d", (index ? take(domain, index) : domain).map(v => `M${fx(v) + tx},0h${dx}`).join(""));
235235
}
236236

237+
function maybeTicks(ticks) {
238+
return ticks === null ? [] : ticks;
239+
}
240+
241+
function maybeTickFormat(tickFormat) {
242+
return tickFormat === null ? () => null : tickFormat;
243+
}
244+
237245
// D3 doesn’t provide a tick format for ordinal scales; we want shorthand when
238246
// an ordinal domain is numbers or dates, and we want null to mean the empty
239247
// string, not the default identity format.
240-
export function maybeTickFormat(tickFormat, domain) {
248+
export function maybeAutoTickFormat(tickFormat, domain) {
241249
return tickFormat === undefined ? (isTemporal(domain) ? formatIsoDate : string)
242250
: typeof tickFormat === "function" ? tickFormat
243251
: (typeof tickFormat === "string" ? (isTemporal(domain) ? utcFormat : format)
@@ -246,7 +254,7 @@ export function maybeTickFormat(tickFormat, domain) {
246254

247255
function createAxis(axis, scale, {ticks, tickSize, tickPadding, tickFormat}) {
248256
if (!scale.tickFormat) {
249-
tickFormat = maybeTickFormat(tickFormat, scale.domain());
257+
tickFormat = maybeAutoTickFormat(tickFormat, scale.domain());
250258
}
251259
return axis(scale)
252260
.ticks(Array.isArray(ticks) ? null : ticks, typeof tickFormat === "function" ? null : tickFormat)

src/legends/swatches.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {create, path} from "d3";
22
import {inferFontVariant} from "../axes.js";
3-
import {maybeTickFormat} from "../axis.js";
3+
import {maybeAutoTickFormat} from "../axis.js";
44
import {isNoneish, maybeColorChannel, maybeNumberChannel} from "../options.js";
55
import {applyInlineStyles, impliedString, maybeClassName} from "../style.js";
66

@@ -84,7 +84,7 @@ function legendItems(scale, {
8484
width
8585
} = {}, swatch, swatchStyle) {
8686
className = maybeClassName(className);
87-
tickFormat = maybeTickFormat(tickFormat, scale.domain);
87+
tickFormat = maybeAutoTickFormat(tickFormat, scale.domain);
8888

8989
const swatches = create("div")
9090
.attr("class", className)

0 commit comments

Comments
 (0)