Fix #171: auto-skip crowded X-axis labels on CategoryChart#954
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
CategoryCharthas many categories (e.g. 161 values from -80 to 80), all X-axis labels are rendered and they overlap. The user's call tosetXAxisTickMarkSpacingHint()had no effect becauseAxisTickCalculator_Categorycompletely ignored that hint.PR #344 added
setXAxisMaxLabelCount()as a manual workaround, but the original complaint — thatsetXAxisTickMarkSpacingHintdoesn't work — remained unresolved.Fix
AxisTickCalculator_Categorynow respectsxAxisTickMarkSpacingHint(default 74 px). When no explicitxAxisMaxLabelCountis set and the per-tick pixel spacing is smaller than the hint, askipFactoris computed:Only every
skipFactor-th label is then rendered, eliminating overlap automatically — no user configuration required.Behaviour
setXAxisMaxLabelCount(N)setsetXAxisTickMarkSpacingHint(0)Files changed
AxisTickCalculator_Category.java— core fixAxisTickCalculatorCategoryTest.java— two new testsTestForIssue171.java— standalone demo reproducing the 161-category histogramFixes: #171