Skip to content

Commit e13196d

Browse files
committed
avoid illegible ticks when the size of the domain exceeds x times the desired number of ticks
1 parent e466abe commit e13196d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/axis.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ export class AxisX {
6464
labelOffset,
6565
line,
6666
name,
67+
ticks,
6768
tickRotate
6869
} = this;
70+
if (!x.interpolate && x.domain().length > 8 * ticks) return; // avoid a huge ordinal domain
6971
const offset = name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
7072
const offsetSign = axis === "top" ? -1 : 1;
7173
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
@@ -155,8 +157,10 @@ export class AxisY {
155157
labelOffset,
156158
line,
157159
name,
160+
ticks,
158161
tickRotate
159162
} = this;
163+
if (!y.interpolate && y.domain().length > 8 * ticks) return; // avoid a huge ordinal domain
160164
const offset = name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
161165
const offsetSign = axis === "left" ? -1 : 1;
162166
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);

src/plot.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ export function plot(options = {}) {
129129
const {fx, fy} = scales;
130130
const axisY = axes[facets !== undefined && fy ? "fy" : "y"];
131131
const axisX = axes[facets !== undefined && fx ? "fx" : "x"];
132-
if (axisY) svg.appendChild(axisY.render(null, scales, dimensions));
133-
if (axisX) svg.appendChild(axisX.render(null, scales, dimensions));
132+
if (axisY) {
133+
const node = axisY.render(null, scales, dimensions);
134+
if (node) svg.appendChild(node);
135+
}
136+
if (axisX) {
137+
const node = axisX.render(null, scales, dimensions);
138+
if (node) svg.appendChild(node);
139+
}
134140

135141
// Render (possibly faceted) marks.
136142
if (facets !== undefined) {

0 commit comments

Comments
 (0)