Skip to content

Fix #171: auto-skip crowded X-axis labels on CategoryChart#954

Merged
timmolter merged 1 commit into
developfrom
timmolter/fix-x-labels-overlap
May 27, 2026
Merged

Fix #171: auto-skip crowded X-axis labels on CategoryChart#954
timmolter merged 1 commit into
developfrom
timmolter/fix-x-labels-overlap

Conversation

@timmolter
Copy link
Copy Markdown
Member

Problem

When a CategoryChart has many categories (e.g. 161 values from -80 to 80), all X-axis labels are rendered and they overlap. The user's call to setXAxisTickMarkSpacingHint() had no effect because AxisTickCalculator_Category completely ignored that hint.

PR #344 added setXAxisMaxLabelCount() as a manual workaround, but the original complaint — that setXAxisTickMarkSpacingHint doesn't work — remained unresolved.

Fix

AxisTickCalculator_Category now respects xAxisTickMarkSpacingHint (default 74 px). When no explicit xAxisMaxLabelCount is set and the per-tick pixel spacing is smaller than the hint, a skipFactor is computed:

skipFactor = (int) Math.ceil(spacingHint / gridStep);

Only every skipFactor-th label is then rendered, eliminating overlap automatically — no user configuration required.

Behaviour

Scenario Before After
Many categories, default settings All labels, overlapping Auto-skipped, no overlap
Few categories, enough space All labels shown All labels shown (unchanged)
setXAxisMaxLabelCount(N) set Manual cap respected Manual cap respected (unchanged)
setXAxisTickMarkSpacingHint(0) No effect Disables auto-skip, shows all labels

Files changed

  • AxisTickCalculator_Category.java — core fix
  • AxisTickCalculatorCategoryTest.java — two new tests
  • TestForIssue171.java — standalone demo reproducing the 161-category histogram

Fixes: #171

AxisTickCalculator_Category now respects xAxisTickMarkSpacingHint (default
74 px).  When no explicit xAxisMaxLabelCount is set and the per-tick pixel
spacing is smaller than the hint, a skipFactor is computed so only every
Nth label is rendered — eliminating overlap automatically.

Users can still override via setXAxisTickMarkSpacingHint() or
setXAxisMaxLabelCount() for fine-grained control.  Setting the hint to 0
disables auto-skip and restores the old 'show all' behaviour.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@timmolter timmolter merged commit 44cf77c into develop May 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

X labels overlap

1 participant