manhattan: opt-in thinning of overlapping chromosome labels#82
Open
wdecoster wants to merge 1 commit into
Open
manhattan: opt-in thinning of overlapping chromosome labels#82wdecoster wants to merge 1 commit into
wdecoster wants to merge 1 commit into
Conversation
The Manhattan x-axis draws every chromosome's name at its band midpoint, suppressing only bands narrower than 6px. Adjacent narrow chromosomes (e.g. 17/19/21 on a default-width genome-wide plot) therefore print labels directly on top of each other. Add ManhattanPlot::with_thin_overlapping_labels() (off by default). When enabled, labels are placed in a single left-to-right pass and any label whose estimated horizontal footprint would collide with the previously drawn one is skipped, leaving a small gap. Spans are already in genomic order, so one pass thins the labels of crowded small chromosomes while keeping the rest readable. Works for both horizontal and rotated (with_x_tick_rotate) labels; rotation shrinks the footprint by cos(angle). Default behaviour is unchanged. Label width is estimated from glyph count since this stage has no font metrics; the estimate stays local to chromosome-label placement. Adds regression tests: labels are all drawn by default, thinned (and never overlapping) when enabled on a default-width plot, and fully drawn on a wide plot. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
|
Hey mate, This is looking good. Can you drop in a screen cap or 2 of what it looks like with an example code block? Cheers, |
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.
This feature was implemented using Claude, but supervised.
Description
Adds
ManhattanPlot::with_thin_overlapping_labels(), an opt-in that makes chromosome labelling on the Manhattan x-axis collision-aware.Problem.
add_manhattan_chr_labelsdraws every chromosome's name at its band midpoint, suppressing only bands narrower than 6px. Adjacent narrow chromosomes (e.g. 17 / 19 / 21 on a default-width genome-wide plot) are wider than 6px but their two-digit labels are wider than the band, so the labels overprint each other and become unreadable. There was no way to control this.Fix. A new builder flag (off by default) enables a single left-to-right pass that tracks the right edge of the last drawn label and skips any label whose estimated horizontal footprint would collide with it, leaving a small gap. Spans are already in genomic order, so one pass thins the labels of crowded small chromosomes while keeping the rest readable. It works for both horizontal and rotated (
Layout::with_x_tick_rotate) labels — rotation shrinks the horizontal footprint bycos(angle). Default behaviour is unchanged.Label width is estimated from glyph count (
len * tick_size * 0.6) because this stage has no font metrics; this matches the existing 6px band heuristic and the estimate stays local to chromosome-label placement.Before (default) vs. with
with_thin_overlapping_labels()on an hg38 genome-wide plot: the cluster17 18 19 20 21 22that previously overprinted is thinned to non-overlapping labels.Type of change
Checklist
Library (new plot type)
ManhattanPlot(src/plot/manhattan.rs: new field +with_thin_overlapping_labels()builder) andadd_manhattan_chr_labels(src/render/render.rs).Tests
tests/manhattan_svg.rs: labels all drawn by default, thinned (and verified non-overlapping) when enabled at default width, and fully drawn on a wide plot.cargo test --features cli,full— all 180 tests pass.CLI (if applicable)
manhattansubcommand. Happy to add a--thin-labelsflag if you'd like it wired through the CLI.Documentation
with_thin_overlapping_labels()with a usage example.Visual inspection
test_outputs/SVGs unaffected (feature is off by default).Housekeeping
CHANGELOG.md— entry added under## [Unreleased]→### Added.Branch / target: opened against
dev, single commit, rebased on the currentdevtip.