Skip to content

Layout scale bars and grids: fixes after #2660 (#2698) - #2706

Merged
jgregoriorincon merged 5 commits into
opengeos:mainfrom
jgregoriorincon:fix/2698-scale-bar-grid-followups
Nov 22, 2026
Merged

jgregoriorincon merged 5 commits into
opengeos:mainfrom
jgregoriorincon:fix/2698-scale-bar-grid-followups

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#2660 (#2581 part 2) merged before its last review round was pushed. This carries that round's fixes, listed in #2698.

  • Locks (crates/map/src/layout.rs): ElementKind::null_resets counts a scale bar's textSize as it does a legend's, so a locked scale bar refuses "textSize": null unless the same command gives "locked": false.
  • A moved scale bar is measured (crates/engine/src/cmd/layout.rs): layout.update with x or y on a scale bar says when a label runs off the page, as a change of its size, text size, units or divisions already does.
  • End label over the first (crates/render/src/layout.rs, bar_layout): above the default size, a box so narrow that the end label runs into the first is too small, and is said and reported by the export like a box too short. Both labels are always drawn, so this was the one overlap no check saw.
  • Grid labels across the frame (kept_labels): a label reaching further in from its edge than the frame is across is left out, as a label without room along its edge is, rather than drawn and cut by the frame. This holds at every size: on a frame smaller across than a default label (about 5 mm), the label is now left out instead of cut.
  • Publication (crates/engine/src/cmd/layout.rs): the scale box is measured again when its frame's center or map changes, as on scale or w, since the text under the bar fills {center} and {map} from them and the bar's length follows the map. The box basis records the frame's map; the width before the change is measured on the old map and centre, the width after on the new ones.
  • Advice: for scale bars alone, the export's cut-off notice says to move them inside the page or make their boxes larger, or reduce their text size, in the singular or plural by count.
  • Capabilities (crates/engine/src/project_capabilities.rs): imported_layout_uses takes all of a capability's keys, so a layout.import's layout is parsed once rather than once per key.
  • Docs: docs/user-guide/layouts.md.

Reach every surface

  • Desktop and browser: the same engine and renderer. Command line, Python, Assistant and MCP: through layout.update. Phone: the touch interface has no layouts.
  • Dragging a scale bar in the desktop page view ends in a layout.update with x and y, so it is measured when the drag stops. Undo and redo say nothing, as for texts.

Testing

New and extended tests:

  • render::layout::tests::a_scale_bars_labels_take_its_text_size: sizes 9 to 100 pt on widths 20 to 400 px never draw the end label over the first without the box being too small; 12 pt in a 48 px box is too small; the first label's reach at 16 pt matches the default's.
  • render::layout::tests::graticule_labels_keep_clear_of_each_other: a 30 px tall frame leaves out its top labels and a 15 px wide one its side labels.
  • render::layout::tests::a_scale_bars_labels_off_the_page_are_reported: the export's advice for one scale bar cut off.
  • engine::tests::scale_bars_and_grids_take_a_label_size: a scale bar moved to x: 250 is told its label runs off the page; a locked bar refuses "textSize": null and keeps its size.
  • engine::tests::publication_layouts_fit_their_pages: the scale box follows a new centre and a new map its text names ({scale} {center}, {scale} {map}).
  • engine::project::capabilities::tests::text_size_capability_follows_saved_layouts_and_commands, unchanged, still passes for imported layouts with a scale bar's or a grid's size, now read in one pass.

Each fix's regression test was run against the code without the fix and failed, for the lock, the move, the centre and map refit, the grid across check and the end-label clash.

Headless ui_shot runs on this branch and on main: the exported page with a graticule and the default scale bar, the same page with both at 14 pt, and the page after undo are byte-identical to main's.

UI evidence

No visible UI change at the default sizes. At larger sizes a grid label that a short frame used to cut is left out, and the notices above appear in the status bar.

Related issue

Closes #2698
Part of #2581

Summary by CodeRabbit

  • Bug Fixes

    • Publication scale boxes now update correctly when a map frame’s map or center changes.
    • Moving a scale bar can now trigger a fit warning. Warnings also account for overlapping scale-bar labels, and clipping guidance clarifies how to fix the issue.
    • Grid labels that extend too far into a frame are omitted. Locked scale bars reject text-size changes, including resets to the default.
  • Documentation

    • Updated layout guidance for grid labels, scale-bar warnings, and locked scale-bar text sizes.

… re-measure (opengeos#2698)

A scale bar's textSize given as null changes it, as a legend's does, so
a locked bar refuses it. A scale bar moved with x or y is told whether
its labels still fit. A publication's scale box is measured again when
its frame's centre or map changes, each basis on its own map: the text
under the bar fills {center} and {map} from them. A grid's label that
reaches further in from its edge than the frame is across is left out,
as a label without room is, rather than cut by the frame.
…e; review nits (opengeos#2698)

A test now covers a side's labels on a frame too narrow for them. The
kept_labels doc is rewrapped, bar_inset's doc says BAR_INSET is in
pixels, and say_text_fit names its notices without shadowing.
…eos#2698)

Above the default size, an end label running into the first label,
both always drawn, now counts as a box too small for its labels and
is said, as a label past the box's side is. TextLoss::below_box says
what it means for a scale bar, and the labels' middle over the bar is
one named constant.
…d once (opengeos#2698)

The export's advice for scale bars alone says to move them inside the
page or make their boxes larger, in the singular or the plural. A
layout.import's layout is read once for all the keys of a capability
rather than once per key. kept_labels says a label too large across is
left out at any size, and the inset test states the default's reach.
Grid labels reaching further in than the frame is across are left out;
a scale bar's move and an end label run into the first are said; a
locked scale bar refuses a new text size, null included.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Layout updates now refit publication scale boxes after frame center or map changes, and reevaluate scale-bar fit after movement. Rendering changes detect scale-bar label overlap and omit grid labels that exceed the frame’s inward space. Imported-layout capability checks now accept multiple keys.

Changes: Layout fitting and capability checks

Layer / File(s) Summary
Frame refits and scale-bar updates
crates/engine/src/cmd/layout.rs, crates/engine/src/tests.rs, crates/map/src/layout.rs
Frame center or map changes trigger scale-box refits using the prior and current basis maps. Scale-bar movement triggers fit checks. A locked scale bar rejects a null text-size reset.
Scale-bar fit detection and notices
crates/render/src/layout.rs, docs/user-guide/layouts.md
Scale-bar fit detection now flags end-label overlap above the default text size. Clipping advice and the guide describe the updated warnings and guidance.
Grid-label inward reach
crates/render/src/layout.rs, docs/user-guide/layouts.md
Grid-label placement omits labels whose inward reach exceeds the frame’s opposite dimension. Tests and the guide cover this rule.
Imported-layout capability checks
crates/engine/src/project_capabilities.rs
Capability checks pass relevant keys together. The shared helper accepts multiple keys and also parses layouts containing a backslash.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • opengeos/RustGIS#2703 — This PR reevaluates scale-bar fit when its position changes, but does not add the requested moved-text checks.

Possibly related PRs

  • opengeos/RustGIS#2660 — This follow-up changes scale-bar text-size reset behavior and publication scale-box refit rules introduced by that PR.
  • opengeos/RustGIS#2666 — Both PRs address when publication scale boxes are remeasured.

Suggested reviewers: giswqs, elpidioassinaturas

Merge Risk: Minimal · up to 7fb35

The change refits scale boxes after frame center or map edits, detects scale-bar label overlap, omits oversized grid labels, and batches imported-layout capability checks. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the work: fixes for layout scale bars and grids that follow up PR #2660 (issue #2698). The changeset covers scale-bar locks, scale-bar move measurement, end-label overlap, grid label c…
Description check Passed The description follows the template. It has a Summary that explains the change and why it exists. It has a Testing section that lists the checks run, the failing unrelated DuckDB test, and new regres…
Linked Issues check Passed Directly linked issue #2698 has four bugs and several smaller and publication items. The reviewed change set addresses each one, based on the whole-PR summary and the PR description:

1. Locked scale …
Out of Scope Changes check Passed Every changed area maps to a bullet in #2698 or supports one of those bullets:
- crates/map/src/layout.rs: the textSize lock (issue item 1).
- crates/engine/src/cmd/layout.rs: move measurement and pub…
Full details: Title check

Explanation

The title names the work: fixes for layout scale bars and grids that follow up PR #2660 (issue #2698). The changeset covers scale-bar locks, scale-bar move measurement, end-label overlap, grid label clipping, publication scale-box refit, cut-off advice, and capability parsing. The title names the two main element types but does not list every fix, which is acceptable for a short title. The title is specific enough for a teammate to see the primary change.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the change and why it exists. It has a Testing section that lists the checks run, the failing unrelated DuckDB test, and new regression tests. It has a UI evidence section that states no visible UI change at default sizes, with a note about larger sizes and the status-bar notices. It has a Related issue section that closes #2698 and is part of #2581. The text is detailed and specific. The UI evidence section does not include before-and-after screenshots, but the author marks the change as having no default-size visible UI change and provides headless ui_shot byte comparisons, which the template's no-visible-change path permits in part. The reviewer may still want screenshots for the larger-size grid label change.

Full details: Linked Issues check

Explanation

Directly linked issue #2698 has four bugs and several smaller and publication items. The reviewed change set addresses each one, based on the whole-PR summary and the PR description:

  1. Locked scale bar and textSize null: crates/map/src/layout.rs changes ElementKind::null_resets to include textSize for scale bars. The lock then refuses a null reset unless the command sets locked false. Test: engine::tests::scale_bars_and_grids_take_a_label_size.
  2. Move with x or y is measured: crates/engine/src/cmd/layout.rs re-evaluates scale-bar fit notices when x or y changes. Test: engine::tests::scale_bars_and_grids_take_a_label_size (x: 250 gets an off-page notice).
  3. End label over the first label: crates/render/src/layout.rs bar_layout flags an end label that overlaps the first label above the default size as a box that is too small. Test: render::layout::tests::a_scale_bars_labels_take_its_text_size (12 pt in 48 px is too small).
  4. Grid labels across the frame: kept_labels omits labels that reach farther inward than the frame is across, at every size. Test: render::layout::tests::graticule_labels_keep_clear_of_each_other.
  5. Publication scale box remeasure: the box basis records the frame's map. A change of center or map remeasures the box, using the old basis on the old map and centre and the new basis on the new ones. Test: engine::tests::publication_layouts_fit_their_pages.
  6. Cut-off advice: for scale bars alone, the export notice names moving the bar inside the page, enlarging its box, or reducing its text size, in singular or plural by count. Test: render::layout::tests::a_scale_bars_labels_off_the_page_are_reported.
  7. Capability read once: project_capabilities.rs imported_layout_uses takes all keys and parses the layout once. Existing test text_size_capability_follows_saved_layouts_and_commands covers this.
  8. Docs: docs/user-guide/layouts.md is updated.

The PR description reports that each regression test fails without its fix. I did not run the tests. The status rests on the code-change summary and the stated test coverage.

Full details: Out of Scope Changes check

Explanation

Every changed area maps to a bullet in #2698 or supports one of those bullets:

  • crates/map/src/layout.rs: the textSize lock (issue item 1).
  • crates/engine/src/cmd/layout.rs: move measurement and publication remeasure on center or map (items 2 and 5).
  • crates/render/src/layout.rs: end-label fit, grid across-frame check, and singular or plural advice (items 3, 4 and the advice bullet).
  • crates/engine/src/project_capabilities.rs: one-pass imported layout read (capability bullet).
  • crates/engine/src/tests.rs and render tests: regression tests the issue requires.
  • docs/user-guide/layouts.md: documentation of the changed behavior.
    The summary shows no unrelated feature or refactor. The PR description's note on the DuckDB test failure concerns an existing test that does not touch layout code. It is not a change in this PR.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the frame’s new place,
And measures maps at their own pace.
The labels fit, or leave the view,
The bars get checked when moved anew.
The rabbit hops; the layout’s true.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e81941be-8b3c-4b4d-8908-dae521a71f24
Commits

Reviewing files that changed from the base of the PR and between 5955e44 and 7fb3556.

Files selected for processing: 6

  • crates/engine/src/cmd/layout.rs
  • crates/engine/src/project_capabilities.rs
  • crates/engine/src/tests.rs
  • crates/map/src/layout.rs
  • crates/render/src/layout.rs
  • docs/user-guide/layouts.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, crashes, silent data loss, or AGENTS.md breaks in this change. The one inline nit I tried to post, on the scale-bar notice wording, is outside the diff, so GitHub rejected it and it is listed below instead. Nothing was posted inline. No earlier review threads exist on this PR, so there were none to dedupe.

Bugs: none confirmed.

Security: none.

Performance: none. imported_layout_uses now parses a layout.import text once instead of once per key, a small improvement.

Quality:

  • The clash notice wording in crates/render/src/layout.rs (around lines 484–486, scale_bar_fit_notices) says the labels or bar "run past" the box. For the new clash case the end label overlaps the first label inside the box, so the wording is slightly off. Suggested alternative: "its box is too small for its labels at their size, so they crowd each other, run past it, or leave its bar below it." Confidence: high that it's imprecise, low that it matters. Category: quality. Left for the release quality pass.
  • Low confidence, not raised inline: in refit_scale_box (crates/engine/src/cmd/layout.rs around line 5697), if a frame moves from a map that no longer exists to a valid one, map_of(before) returns None and the box is silently not refitted. The doc comment's list of skip cases doesn't mention this. I believe the old code also skipped it, so it's not a regression, but the comment doesn't say so.

AGENTS.md: no breaks found. Checked the lock rule (null_resets is only read in the changes check, so the new scale-bar case has no other effect), the regression tests for each fix, the ui_shot evidence in the PR body, and the layouts.md change. I did not run the build, tests, or the wasm check, since I have no shell here.

Already raised earlier: 0. There were no prior threads.

Change size

Compared with the base branch, merge base 90fcbe0 to PR head 7fb3556.

Measure Value
Files changed 6 (0 added, 6 modified, 0 removed, 0 renamed)
Size before 4.61 MB
Size after 4.61 MB
Total size change +6.1 KB
Path Before After Change
crates/render/src/layout.rs 506.8 KB 510.4 KB +3.7 KB
crates/engine/src/tests.rs 3.40 MB 3.40 MB +1.7 KB
crates/engine/src/cmd/layout.rs 366.1 KB 366.7 KB +643 B
docs/user-guide/layouts.md 63.9 KB 64.1 KB +180 B
crates/map/src/layout.rs 194.8 KB 194.8 KB +46 B
crates/engine/src/project_capabilities.rs 101.7 KB 101.7 KB 0 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2706/
Web app https://preview.rustgis.app/pr-2706/app/
Commit 7fb3556

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 preview label (once per commit).

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review November 22, 2026 16:58
let half = |s: &str| text::measure(s, b.px / 1.33, false) / 2.0;
let ((fx, fs), (ex, es)) = (&b.labels[0], &b.labels[b.labels.len() - 1]);
let clash = b.labels.len() > 1 && ex - half(es) < fx + half(fs);
assert!(!clash || b.cramped, "{pt} pt in {w} px: its end label over its first, not said");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop recomputes the clash predicate in the test (ex - half(es) < fx + half(fs)) and checks only the implication !clash || cramped. The test therefore passes if the production predicate is wrong in the same way as the copy, and it also passes if cramped is set for other reasons, so it does not show that the notice fires for the clash case. It would be stronger to assert on the observable result, for example that bar_labels_cut/text_loss report below_box exactly when the labels overlap above the default size, with a concrete size and width pair where the clash is known to happen.

Confidence: medium. This is test strength, not a defect in the code under test, so it may wait for the release quality pass.

Category: quality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. The loop does reach clashes: without the fix it failed at "12 pt in 48 px". But as written it asserts only the implication, so it would also pass if no clash occurred at all. A concrete case asserted on the reported loss (12 pt in a 48 px box gives below_box) would close that gap. This PR has merged; I've noted it for the release quality pass.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

No bugs, security issues, performance problems, or AGENTS.md violations found. I checked the changed lines against their call sites: the lock check (cmd/layout.rs, update), the refit path (refit_scale_box, frame_view_changed), kept_labels and draw_grid, bar_layout, the imported_layout_uses rewrite (same results as the old per-key any, with one parse), and the test changes. The new code has no unwrap/expect/indexing outside tests, and the PR doesn't change saved-file format, so no schema or fixture update is needed.

Bugs: none found.

Security: none found.

Performance: none found. A moved scale bar now measures its labels on each x/y update. That is one element's text measurement, not a full-page render.

Quality:

  • The inline comment on crates/render/src/layout.rs:8540 (confidence medium): the end-label clash test recomputes the predicate instead of checking the drawn result, so it would pass if the copy and the implementation were wrong in the same way. Posted inline. Left for the release quality pass.
  • Not posted inline (confidence high, wording only): the "box too small" notice at crates/render/src/layout.rs:485 says the labels or bar "run past it". The new clash rule makes the labels overlap each other inside the box, so that wording is inaccurate for that case. The line is unchanged in this PR (it comes from Layout scale bars and grids take a label size (#2581, part 2) #2660), so GitHub rejected an inline anchor there. Consider rewording it in the quality pass.
  • Nit (confidence high): the null_resets doc at crates/map/src/layout.rs:1489 reads awkwardly after the line break ("a legend's / or scale bar's textSize"). Also, the bar_inset doc comment is clumsy. Both can wait for the quality pass.

AGENTS.md: no violations. The new user-visible notice strings are plain format!/literals, which matches the existing render-crate notices (none use tl!), so this is not a new violation.

Prior concerns: prior-reviews.json had no threads, so nothing was left alone as already raised.

Surfaces: the PR body says which surfaces are reached. The Assistant and MCP tool descriptions don't mention textSize, so they need no update for the new scale-bar null rule.

Change size

Compared with the base branch (main, merge base 90fcbe0 to PR head 7fb3556). Sizes are file sizes in bytes, shown in decimal KB or MB.

Files changed Added Modified Removed Renamed Size before Size after Total change
6 0 6 0 0 4.83 MB 4.84 MB +6.4 KB
Path Before After Change
crates/render/src/layout.rs 519.0 KB 522.8 KB +3.8 KB
crates/engine/src/tests.rs 3.57 MB 3.57 MB +1.7 KB
crates/engine/src/cmd/layout.rs 374.8 KB 375.5 KB +643 B
docs/user-guide/layouts.md 65.4 KB 65.6 KB +180 B
crates/map/src/layout.rs 199.5 KB 199.6 KB +46 B
crates/engine/src/project_capabilities.rs 104.1 KB 104.1 KB 0 B

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 22, 2026
Merged via the queue into opengeos:main with commit 20f5654 Nov 22, 2026
27 checks passed
@jgregoriorincon
jgregoriorincon deleted the fix/2698-scale-bar-grid-followups branch November 22, 2026 17:24
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.

Layout scale bars and grids: fixes after #2660

1 participant