Repository navigation
Layout scale bars and grids: fixes after #2660 (#2698) - #2706
jgregoriorincon merged 5 commits into
Conversation
… 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.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Code reviewI 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. Quality:
AGENTS.md: no breaks found. Checked the lock rule ( Already raised earlier: 0. There were no prior threads. Change sizeCompared with the base branch, merge base 90fcbe0 to PR head 7fb3556.
|
📖 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 |
| 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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Code reviewNo bugs, security issues, performance problems, or AGENTS.md violations found. I checked the changed lines against their call sites: the lock check ( Bugs: none found. Security: none found. Performance: none found. A moved scale bar now measures its labels on each Quality:
AGENTS.md: no violations. The new user-visible notice strings are plain Prior concerns: Surfaces: the PR body says which surfaces are reached. The Assistant and MCP tool descriptions don't mention Change sizeCompared with the base branch (main, merge base 90fcbe0 to PR head 7fb3556). Sizes are file sizes in bytes, shown in decimal KB or MB.
|
Summary
#2660 (#2581 part 2) merged before its last review round was pushed. This carries that round's fixes, listed in #2698.
crates/map/src/layout.rs):ElementKind::null_resetscounts a scale bar'stextSizeas it does a legend's, so a locked scale bar refuses"textSize": nullunless the same command gives"locked": false.crates/engine/src/cmd/layout.rs):layout.updatewithxoryon a scale bar says when a label runs off the page, as a change of its size, text size, units or divisions already does.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.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.crates/engine/src/cmd/layout.rs): the scale box is measured again when its frame'scenterormapchanges, as onscaleorw, 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.crates/engine/src/project_capabilities.rs):imported_layout_usestakes all of a capability's keys, so alayout.import's layout is parsed once rather than once per key.docs/user-guide/layouts.md.Reach every surface
layout.update. Phone: the touch interface has no layouts.layout.updatewithxandy, so it is measured when the drag stops. Undo and redo say nothing, as for texts.Testing
checks.shon this branch, onmainat 90fcbe0 (fmt, clippy on the touched crates, nextest on the whole workspace, doctests,cargo xtask layers,cargo xtask schema --check): all passed but one test of 8863,portable_projects reload::reload_reconverts_duckdb_table_and_keeps_only_its_original_geometry_branch, the DuckDB test that fails on this machine's DuckDB, as noted in feat(layout): a legend takes a text size, its rows and swatches following (#2581 part 1) #2590 and Layout scale bars and grids take a label size (#2581, part 2) #2660; it touches no layout code.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 tox: 250is told its label runs off the page; a locked bar refuses"textSize": nulland 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_shotruns on this branch and onmain: 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 tomain'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
Documentation