Skip to content

feat(layout): a legend takes the size of its line and polygon patches (#3559) - #3564

Draft
jgregoriorincon wants to merge 10 commits into
opengeos:mainfrom
jgregoriorincon:feat/3559-legend-patch-size
Draft

jgregoriorincon wants to merge 10 commits into
opengeos:mainfrom
jgregoriorincon:feat/3559-legend-patch-size

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A layout legend draws every line and polygon patch at one size, 16 × 9 pt at the default text size. This lets a legend set it: layout.addElement and layout.update take patchWidth (4 to 100) and patchHeight (3 to 100) for a legend, in points at the default text size, so they grow and shrink with textSize like the rest of the legend.

  • A taller patch makes the rows of lines and polygons taller (never shorter than a row is now); a wider one widens the column of patches, so the labels stay lined up.
  • A point symbol keeps the size the map draws it at, and its column is as wide as the wider of it and the patch. A layer's name and a web layer's legend picture are not changed, and a nested block keeps its marker sizes, though its markers and labels move with a widened column.
  • The fit (fit, columns, columnBreaks, oneRow) and the notices about a legend that doesn't fit measure with the patch, in the app, in layout.update's check and in an export.
  • The defaults (16 and 9) draw and save as before, with no new key in the layout. Any other value requires the new capability layout-legend-patch-size, wherever it is saved (project, layout file, layout.import, report.existingTemplate, task step, script, model), so an older release refuses the project instead of drawing the default patch and saving it again without the size. A file's value outside the range is brought into it when it is read.
  • layout.publication, its wizard and the QGIS importer are not touched. The Format pane's boxes come in the next pull request.

It reaches the desktop app, the browser, the command line, Python and the Assistant through the commands (the Assistant's layout skill lists the parameters); nothing is undone differently: a change is one undo step. Strings for the Format pane wait for that pull request. The MCP tool descriptions come from the same command parameters, so they list the two new ones with no separate change; the phone interface (ui-touch), the ribbon and command search have no legend settings to add them to, since the Format pane is where a legend is set in the app.

Testing

  • crates/engine/src/tests/layout_legend_patch.rs: setting, adding, limits, refusals that change nothing, the capability in every place it is saved, a file's out-of-range value, and the fit saying a taller or wider patch needs more room. Seen failing before the code, then passing.
  • crates/render/src/layout/tests/legend_patch.rs: the default is what it was, the patch drawn at its width and height (and at twice the pixels, and at a legend's other text size), row heights for lines and polygons but not points, the column's width, and the fit. Breaking the patch's height on purpose fails five of its seven.
  • The fixture schema/fixtures/layout_legend_patch_size.rgis is in the layout file round trip, and the schema and the command surface are regenerated.
  • Local checks on this branch after merging upstream/main: cargo fmt, cargo clippy -D warnings (whole workspace, all targets), cargo xtask layers, cargo xtask schema --check, cargo xtask test-hygiene, and the render and engine layout and legend tests (909 passed), all green. The full nextest run has 8 failures that are not in this diff and also fail without it: seven in rustgis-geolibre and smoke line_strokes_editor_edits_one_class.

UI evidence

No visible UI change: a legend draws as before unless it is given patchWidth or patchHeight through a command. The Format pane's boxes, with before and after captures, come in the next pull request.

Related issue

Part of #3559

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

Comment thread docs/user-guide/layouts.md Resolved
Comment thread crates/render/src/layout/legend.rs Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

No bugs, security problems, or performance problems found. Static review only: I did not run the build or tests. Tests the PR describes as passing were not re-run here.

Bugs

  • None found. I traced the file-read routes (layout.import, report.existingTemplate via layout::import, project.openText, saved requires headers), the clamp and its repair count, the fit and measure paths, and the row/swatch geometry. The defaults reduce to the old values (row 15, patch 16×9, zigzag and box offsets equal at the default).

Security

  • None found.

Performance

  • None found. The capability checks pre-filter on key names before parsing project text, as the existing checks do.

Quality

  • Docs overstate "nested sizes don't change" (docs/user-guide/layouts.md:576, confidence about 70%). nested::draw centres markers in the swatch column it is given, and that column widens with patchWidth, so a nested block's markers and labels move right. Inline suggestion posted. Category: quality.
  • Minor points, grouped (crates/render/src/layout/legend.rs:787, confidence about 60%): the swatch/patch naming is mixed, LEGEND_PATCH_HEIGHT duplicates the map constant, fit_legend_patched reads oddly, and Patch::new (line 807) does not clamp, though LegendAsked.patch is public. The engine validates first, so I found no crash path today. Category: quality.

AGENTS.md

  • None found. I checked: no unwrap/expect/panic in non-test code; capability added in project.rs, project_capabilities.rs, and schema/project.schema.json; command-surface.txt updated; fixture added and in the round-trip test; docs and the Assistant skill updated; clamp counted in LayoutRepairs, so out-of-range file values reach a notice.
  • Twins checked: every read route above is covered. project.open (path) relies on the saved requires header, which the same change extends. I did not open project.importQgis or project.importGeolibre; the diff does not touch them, and they import other formats.
  • The Format pane is not in this PR, and the PR body says so.

No prior review threads existed, so I left none alone.

Change size

Compared: the whole PR against main (merge base 342ebb8 to PR head 04f9e7b).

Measure Value
Files changed 29 (3 added, 26 modified, 0 removed, 0 renamed)
Size before 5.85 MB
Size after 5.88 MB
Total size change +34.0 KB
Path Before After Change
crates/engine/src/tests/layout_legend_patch.rs 0 B 8.7 KB +8.7 KB
crates/render/src/layout/tests/legend_patch.rs 0 B 7.5 KB +7.5 KB
crates/engine/src/project_capabilities.rs 292.6 KB 296.2 KB +3.6 KB
crates/render/src/layout/legend.rs 78.8 KB 81.8 KB +3.0 KB
crates/render/src/layout/tests.rs 489.6 KB 491.3 KB +1.7 KB
crates/engine/src/cmd/layout/legend.rs 35.8 KB 37.2 KB +1.5 KB
crates/map/src/layout/elements.rs 65.9 KB 66.9 KB +1.0 KB
crates/map/src/layout/legend.rs 14.7 KB 15.6 KB +0.8 KB
docs/user-guide/layouts.md 105.4 KB 106.2 KB +0.7 KB
schema/fixtures/layout_legend_patch_size.rgis 0 B 720 B +720 B
docs/maintaining.md 38.6 KB 39.2 KB +0.7 KB
crates/engine/src/cmd/layout.rs 64.5 KB 65.1 KB +0.6 KB
crates/engine/src/cmd/layout/elements.rs 83.4 KB 83.9 KB +0.5 KB
crates/engine/src/cmd/layout/update.rs 53.7 KB 54.2 KB +0.5 KB
crates/map/src/layout.rs 40.1 KB 40.5 KB +0.4 KB
crates/render/src/layout/swatch.rs 12.8 KB 13.2 KB +0.4 KB
crates/render/src/svg.rs 56.1 KB 56.4 KB +0.3 KB
crates/render/src/layout.rs 64.6 KB 64.9 KB +0.3 KB
crates/engine/src/tests.rs 3.84 MB 3.84 MB +179 B
crates/render/src/layout/legend/count_tests.rs 20.1 KB 20.3 KB +0.2 KB

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3564/
Web app https://preview.rustgis.app/pr-3564/app/
Commit 165f113

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).

/// the widest point symbol, so the labels line up.
pub(super) fn swatch_column(sides: impl IntoIterator<Item = f32>, size: f32) -> f32 {
sides.into_iter().fold(LEGEND_SWATCH * size, f32::max)
pub(super) fn swatch_column(sides: impl IntoIterator<Item = f32>, (patch, size): (Patch, f32)) -> f32 {

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.

Question on the design, not a defect: the column is widened to patch.width * size even when the legend has no line or polygon row. A legend of point layers only, with patchWidth set to 100, therefore gets a 100 pt column of blank space in front of its labels, and the patch it reserves is never drawn. The tests and the docs describe this behaviour, so it may be intended. If it is, a short note in the patchWidth doc would say so. If not, the fold could start from the default width unless a line or polygon row is present.

Category: quality

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

I reviewed the whole diff (29 files), the PR metadata, and the prior review threads. I did not build or run the tests; the findings below come from reading the code.

Bugs

None found. I checked these paths:

  • Clamping on read: Layout::clamp (crates/map/src/layout.rs ~692) brings out-of-range or non-finite patch values into range. The change shows up in elements_adjusted, because kind_changed compares before and after. So the value is reported, as the "Never silent" rule requires.
  • Serialization: the defaults are skipped on save. NaN and infinity cannot come from JSON, so no unreadable value can be written.
  • Render path: Patch::row, swatch_box and swatch_line give the same geometry as before at the default size (9/15 and 3 pt bends). The row cell is clipped by composited.
  • Measurement twins: Measured::part, column_widths, legend_missing, legend_column, asked_rows, legend_fitted_mm and the publication legend all carry patch.
  • Capability twins: layout.addElement/update, layout.import, report.existingTemplate, project.openText and script.run are all covered. The layout-level layout_capabilities check also covers saved projects.

Security

None found. The new parameters are range-checked through patch_param, and nothing is read or executed outside the existing parsers.

Performance

None found. The new work is a few comparisons per element and one extra parse of project.openText text, and only when a key name appears in it.

Quality

  • Point-only legends widen their column (crates/render/src/layout/legend.rs:529, inline). swatch_column folds the patch width in even when no line or polygon row exists, so a point-only legend with patchWidth 100 gets blank space. This may be intended, since the PR and the tests describe it. Confidence: medium.
  • Two representations of the patch. LegendAsked.patch is a (f64, f64) tuple and LegendOptions.patch is a Patch struct. Low impact; confidence high.
  • Duplicate constants. LEGEND_SWATCH and LEGEND_PATCH_HEIGHT repeat the map constants. The earlier thread covered this and the author answered it, so I left it alone.

AGENTS.md

No violations found. Checked:

  • command-surface.txt is updated.
  • schema/project.schema.json gets the new capability in both places. It does not list legend fields, so no field schema change was needed.
  • The fixture is added and listed in the round-trip test.
  • The docs and the Assistant skill are updated.
  • No new platform-specific code, so the wasm rule does not apply.

Other notes

  • Pre-existing twin gap (not in this diff, not verified by a test): command_uses_legend_subtitle (crates/engine/src/project_capabilities.rs:753) has no project.openText arm. command_uses_legend_counts lacks one too. The new patch check and command_uses_legend_one_row both have it. A subtitle inside an opened project text may therefore skip its capability check.

Prior threads

I left 4 earlier points alone, in 2 threads, as already raised and answered: the constant naming and duplication, the fit_legend_patched name, the unclamped Patch::new, and the nested-marker sentence (fixed in 165f113).

Change size

Compared with main (merge base 342ebb8 to PR head 165f113), the whole PR.

Measure Value
Files changed 29 (3 added, 26 modified, 0 removed, 0 renamed)
Size before 5.85 MB
Size after 5.87 MB
Total size change +34.9 KB
Path Before After Change
crates/engine/src/tests/layout_legend_patch.rs 0 B 8.7 KB +8.7 KB
crates/render/src/layout/tests/legend_patch.rs 0 B 7.5 KB +7.5 KB
crates/engine/src/project_capabilities.rs 292.6 KB 296.3 KB +3.6 KB
crates/render/src/layout/legend.rs 78.8 KB 81.8 KB +3.0 KB
crates/render/src/layout/tests.rs 489.6 KB 491.3 KB +1.7 KB
crates/engine/src/cmd/layout/legend.rs 35.8 KB 37.2 KB +1.5 KB
crates/map/src/layout/elements.rs 65.9 KB 67.2 KB +1.0 KB
docs/user-guide/layouts.md 105.4 KB 106.2 KB +856 B
crates/map/src/layout/legend.rs 14.7 KB 15.6 KB +855 B
schema/fixtures/layout_legend_patch_size.rgis 0 B 720 B +720 B
docs/maintaining.md 38.6 KB 39.2 KB +677 B
crates/engine/src/cmd/layout.rs 64.5 KB 65.1 KB +643 B
crates/engine/src/cmd/layout/elements.rs 83.4 KB 83.9 KB +557 B
crates/engine/src/cmd/layout/update.rs 53.7 KB 54.2 KB +545 B
crates/map/src/layout.rs 40.1 KB 40.5 KB +436 B
crates/render/src/layout/swatch.rs 12.8 KB 13.2 KB +410 B
crates/render/src/svg.rs 56.1 KB 56.4 KB +296 B
crates/render/src/layout.rs 64.6 KB 64.9 KB +271 B
crates/engine/src/tests.rs 3.8 MB 3.8 MB +179 B
crates/render/src/layout/legend/count_tests.rs 20.1 KB 20.3 KB +168 B

This branch has not been deployed

No deployments
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.

1 participant