Skip to content

Commit

Permalink
avoid illegible ticks when the size of the domain exceeds x times the…
Browse files Browse the repository at this point in the history
… desired number of ticks
  • Loading branch information
Fil committed Mar 23, 2022
1 parent e466abe commit e13196d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export class AxisX {
labelOffset,
line,
name,
ticks,
tickRotate
} = this;
if (!x.interpolate && x.domain().length > 8 * ticks) return; // avoid a huge ordinal domain
const offset = name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
const offsetSign = axis === "top" ? -1 : 1;
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
Expand Down Expand Up @@ -155,8 +157,10 @@ export class AxisY {
labelOffset,
line,
name,
ticks,
tickRotate
} = this;
if (!y.interpolate && y.domain().length > 8 * ticks) return; // avoid a huge ordinal domain
const offset = name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
const offsetSign = axis === "left" ? -1 : 1;
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);
Expand Down
10 changes: 8 additions & 2 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ export function plot(options = {}) {
const {fx, fy} = scales;
const axisY = axes[facets !== undefined && fy ? "fy" : "y"];
const axisX = axes[facets !== undefined && fx ? "fx" : "x"];
if (axisY) svg.appendChild(axisY.render(null, scales, dimensions));
if (axisX) svg.appendChild(axisX.render(null, scales, dimensions));
if (axisY) {
const node = axisY.render(null, scales, dimensions);
if (node) svg.appendChild(node);
}
if (axisX) {
const node = axisX.render(null, scales, dimensions);
if (node) svg.appendChild(node);
}

// Render (possibly faceted) marks.
if (facets !== undefined) {
Expand Down

0 comments on commit e13196d

Please sign in to comment.