Repository navigation
fix(layout): keep a scale bar's labels evenly spaced when they don't all fit - #3499
jgregoriorincon merged 3 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Code reviewI found no bugs, security problems or AGENTS.md breaks. The new Bugs: none found. Security: none found. Performance: none. The thinning search is a few divisors over at most about ten divisions per draw, and the function uses Quality (four inline comments, all category
AGENTS.md: none. Checked against the rules that apply here:
Twins checked: the colorbar's greedy tick thinning ( Prior concerns: none, since the review threads list is empty. Change sizeCompared with
|
Code reviewI read the diff, the base Bugs: none found (confidence: high). I checked:
Security: none found. The change adds no input parsing or I/O. Performance: none found. The new function is O(divisors × divisions) on at most 11 labels. Text measurement happens once per label, as the old loop did. Quality (2 inline, plus notes):
AGENTS.md: no violations found. I checked:
Earlier concerns: I left 4 alone. Three were answered or addressed ( Change sizeCompared against
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
Summary
When a layout scale bar's labels don't all fit, they were skipped from left to right: each was kept if it cleared the one before it and the last one. A bar of four divisions could read
0 2500 5000 ........ 10000 km, with7500left out although an even0 5000 10000 kmfits.Now the bar labels its ends and every
stepth division from zero, wherestepis the smallest even share of the divisions after zero at which no two labels touch (0 · 5000 · 10000 km; six divisions may read every second or every third). When no step fits, only the ends are labelled, which are always drawn, as before. With divisions before zero the step counts from zero and the first label is always drawn, so the stretch at the left end can be shorter than the step (-1 0 2 4); if that first label would touch zero, only the ends are left.The rule is one pure function,
scale_bar_keptincrates/render/src/layout/scale_bar.rs; the drawing, the cut-off check and the box measure all read the labels from there.What changes: a bar that already shows all its labels draws as before. A crowded one can now show fewer labels than before, evenly spaced. The pinned hash of
scale_bars_without_details_draw_as_beforechanges for this: of its 648 drawings, 186 differ, all of them ones where the old loop had already left labels out. With a prime number of divisions (3, 5, 7) there is no even step in between, so a crowded bar labels only its ends, where the old loop could keep a few unevenly spaced labels.Reach: the change is in the page renderer, so it reaches the layout view, PNG, PDF and SVG exports, desktop, browser, command line and Python alike. No command, parameter, pane or saved field changes, so ribbon, search, Assistant, MCP and plugins have nothing new to show; undo is unaffected.
Testing
crates/render/src/layout/tests/scale_bar_labels.rs: the rule on its own spans (no fonts involved) and a sweep over widths, text sizes, divisions and faces. Four failed with the old loop.rustgis-geolibre, 1 symbology smoke test), in code this change doesn't touch. After the last wording commit: fmt, clippy and the 1,159rustgis-rendertests pass.ui_shotbefore and after on the sample project (120 mm bar, Kilometers, 4 divisions, 12 to 18 pt, sans and serif): 12 and 14 pt export the same bytes, 16 and 18 pt differ.UI evidence
A four-division bar, sans at 16 pt (top) and serif at 18 pt (bottom).
Related issue
Closes #3490
Summary by CodeRabbit