Skip to content

feat(layout): the Dynamic Text menus offer a layer's count, sum, mean, least and greatest (#3036) - #3040

Merged
jgregoriorincon merged 6 commits into
opengeos:mainfrom
jgregoriorincon:feat/2853-statistic-menu
Nov 26, 2026
Merged

jgregoriorincon merged 6 commits into
opengeos:mainfrom
jgregoriorincon:feat/2853-statistic-menu

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A layout text can show a layer's figure (#2853, #2980), but its token had to be typed by hand. Both Dynamic Text menus of a layout now have a Layer statistic submenu:

  • the Format pane's Insert Dynamic Text adds the token to the selected text;
  • Publish › Text › Dynamic Text adds a text holding it.

It lists each layer of the first map frame's map, with Count and, under each numeric field, Sum, Mean, Least and Greatest. Raster layers, graphics layers and names a token can't hold ({, }, or a : in a field's name) are not listed. With no map frame or no such layer there is no section, and a map's text graphics don't get it.

Both menus draw one function (textform::stat_menu) over one list (textform::StatLayer::of), so they offer the same entries. A layer under another of the same name, and a field after another of the same name (case aside), are not listed, since a token reads the first one.

The change is in the egui interface (desktop and browser) only: no command, project format, CLI, Python or Assistant change. The command line, Python, the Assistant, MCP and plugins already write these tokens with layout.addElement and layout.update, so they need nothing new. The phone interface (ui-touch) has no layout text menu, and shortcuts and command search are unaffected, since no command is added. Each pick is one layout.addElement or layout.update, so one undo step. The new strings wait for the release translation pass.

Testing

  • a_layer_statistic_is_added_from_its_layers_submenu: the Format pane's submenu adds each token; no layers, no section.
  • the_layers_offered_are_the_first_frames_with_their_numeric_fields: the list, including what is left out (the repeated layer and field names seen failing before their fixes).
  • publish_dynamic_text_adds_a_layer_statistic: the ribbon adds and selects a text with the token; no frame, no section (seen failing before the ribbon change).
  • cargo fmt --all --check, cargo clippy -p rustgis-ui-egui, doctests, cargo xtask layers and schema --check: pass.
  • cargo nextest run (workspace, the local DuckDB tests left out): 9763 of 9764 pass. The one failure, tests::layout_title::a_wrapped_map_title_is_sized_for_its_drawn_lines, also fails in the CI of main; this PR does not touch the engine.
  • A paragraph in the user guide (layouts.md).

UI evidence

Headless ui_shot, before (left) and after (right).

Publish › Text › Dynamic Text:

3036-ribbon.png

Format pane › Insert Dynamic Text:

3036-pane.png

Related issue

Closes #3036

Summary by CodeRabbit

  • New Features
    • Added dynamic text tokens for layer counts and numeric-field statistics, including sum, mean, minimum, and maximum. Available options depend on the layers in the layout’s first map frame.
  • Documentation
    • Updated the layout guide to explain the new layer statistic tokens and which layers are eligible.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Dynamic Text menus now offer layer counts and numeric-field statistics. Selecting a statistic inserts its token into layout text. The menus use eligible layers from the first map frame, and the user guide describes the available options and exclusions.

Changes: Layer Statistic Dynamic Text

Layer / File(s) Summary
Statistic discovery and menu
crates/ui-egui/src/textform.rs
StatLayer::of selects eligible layers and numeric fields from the first map frame. The statistic menu offers count per layer and sum, mean, minimum, and maximum per numeric field. Tests cover layer and field filtering.
Dynamic Text integration
crates/ui-egui/src/textform.rs, crates/ui-egui/src/layoutview.rs, crates/ui-egui/src/ribbon.rs, crates/ui-egui/src/graphicformat.rs, docs/user-guide/layouts.md
The shared text form accepts a layer provider and inserts a selected statistic token. Layout menus provide the available layers. Tests cover token insertion and the empty-layer case; the guide documents the menu and its exclusions.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant layout_groups
  participant StatLayer
  participant stat_menu
  participant TextElement
  layout_groups->>StatLayer: Provide layout and maps
  StatLayer-->>layout_groups: Return eligible layers and fields
  layout_groups->>stat_menu: Provide layers
  User->>stat_menu: Select statistic
  stat_menu-->>layout_groups: Return statistic token
  layout_groups->>TextElement: Add token as dynamic text
Loading

Possibly related issues

  • Issue 2853 requests layer-statistic tokens in the Dynamic Text menus. This change adds the menu entries that issue describes.

Possibly related PRs

Suggested reviewers: giswqs, elpidioassinaturas, deniial00

Merge Risk: Minimal · up to 22890

This adds a Layer statistic submenu to the layout Dynamic Text menus. The change is limited to the desktop and browser UI, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(layout): the Dynamic Text menus offer a layer's count, sum, mean, least and greatest (#3036)" matches the main change. The PR adds a Layer statistic submenu to both layout Dynamic Text…
Linked Issues check Passed [#3036] Requirements: a Layer statistic submenu in both Dynamic Text menus; layers of the first map frame's map; Count, and Sum, Mean, Least, Greatest under each numeric field; raster and graphics lay…
Out of Scope Changes check Passed Changed files per the summary: textform.rs (the feature), ribbon.rs (ribbon entry and test), layoutview.rs (passes layers to the shared form), graphicformat.rs (passes an empty layer list for text gra…
Description check Passed The description covers the required sections. The Summary explains the change and its motivation: a Layer statistic submenu in both layout Dynamic Text menus, with the exclusion rules and the one-undo…
Full details: Title check

Explanation

The title "feat(layout): the Dynamic Text menus offer a layer's count, sum, mean, least and greatest (#3036)" matches the main change. The PR adds a Layer statistic submenu to both layout Dynamic Text menus, listing Count, Sum, Mean, Least and Greatest for layers in the first map frame. The title is long (97 characters) but specific and accurate.

Full details: Linked Issues check

Explanation

[#3036] Requirements: a Layer statistic submenu in both Dynamic Text menus; layers of the first map frame's map; Count, and Sum, Mean, Least, Greatest under each numeric field; raster and graphics layers and unrepresentable names excluded; no section without a frame or eligible layer; map text graphics excluded. Evidence at the reviewed head: textform.rs adds StatLayer::of, which takes the first frame's map, filters out graphics and raster layers, names containing '{' or '}', and field names containing ':', and keeps only the first layer and field of each name. stat_menu emits Count plus sum/mean/min/max tokens per numeric field and returns early when the list is empty. textform::show, used by the Format pane's Insert Dynamic Text, calls stat_menu. ribbon.rs adds the same submenu to Publish > Text > Dynamic Text (+31 lines, with a test). graphicformat.rs passes an empty layer list, so map text graphics get no section. layoutview.rs supplies the layers for layout text. The user guide (layouts.md) gains a paragraph. The author-reported tests (a_layer_statistic_is_added_from_its_layers_submenu, the_layers_offered_are_the_first_frames_with_their_numeric_fields, publish_dynamic_text_adds_a_layer_statistic) were not run by this review. Their existence is taken from the summary. Only the textform.rs source was read. The ribbon.rs and layoutview.rs logic is taken from the summary. All coding requirements appear implemented.

Full details: Out of Scope Changes check

Explanation

Changed files per the summary: textform.rs (the feature), ribbon.rs (ribbon entry and test), layoutview.rs (passes layers to the shared form), graphicformat.rs (passes an empty layer list for text graphics, plus the show signature change), and docs/user-guide/layouts.md (the documentation paragraph). Each serves the Layer statistic feature or its test or documentation. The PR states no command, project format, CLI, Python, or Assistant changes. No unrelated change was found in the read source. The failing test a_wrapped_map_title_is_sized_for_its_drawn_lines is reported as failing on main CI and is not part of this PR's changes.

Full details: Description check

Explanation

The description covers the required sections. The Summary explains the change and its motivation: a Layer statistic submenu in both layout Dynamic Text menus, with the exclusion rules and the one-undo-step behavior. The Testing section lists new tests, the commands run, and one pre-existing failure that the author says also fails on main. The UI evidence section has before and after screenshots for both menus, which the template requires for visible UI changes. The Related issue section says Closes #3036. The description does not state which DuckDB tests were excluded beyond the note in the Testing section, and the image links are external attachments, so a reviewer cannot confirm them from the text alone. These gaps are minor, so the check passes.

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 taps a token in,
Count and sums now join the din.
Fields are filtered, names fit right,
Text grows statistics overnight.
The bunny hops; the menus gleam.

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: 2e0ecbde-3786-4676-b566-e2414ddda0dd
Commits

Reviewing files that changed from the base of the PR and between e185e02 and 22890a5.

Files selected for processing: 5

  • crates/ui-egui/src/graphicformat.rs
  • crates/ui-egui/src/layoutview.rs
  • crates/ui-egui/src/ribbon.rs
  • crates/ui-egui/src/textform.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; 3 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security problems or crash paths in the changed code, so I posted no inline comments. I did not compile or run the tests (no shell here). Prior review threads: none, so there were no earlier concerns to leave alone.

Bugs: none.

  • The token list and the figures agree. StatLayer::of takes the first frame's map with a case-insensitive name match, as the renderer does (render/src/layout.rs map_index). It keeps the first layer of each name (layer_by_name) and the first field of each name (field_index), and the renderer's figures_of reads the same ones.
  • The parser splits a layer from its field at the last colon (layout.rs scan_stat_tokens). So colons are fine in layer names, and the PR's rule that a field's name may not hold : is the one that matters. Braces are excluded from both names.
  • layers() runs only inside the menu_button closure, so it is evaluated only while the menu is open, as the doc comment says.
  • Each pick goes through add or the Format pane's text update, so it is one undo step.

Security: none. The new code only builds menu labels and token strings from project data.

Performance (low, not raised): StatLayer::of is O(fields²) per layer and runs each frame while the menu is open. For realistic layer widths this is negligible.

Quality: nothing worth an inline comment. The format! in the menu label follows the existing Dynamic Text button code, so I left it.

AGENTS.md (low confidence, about 50%): the PR body says the change reaches the desktop and browser, and that the CLI, Python and Assistant are unchanged. It does not say whether the phone interface (ui-touch) or shortcuts and command search are reached, which the "Reach every surface" rule asks for. I found no ui-touch use of textform, so the answer is probably "not reached", but the PR should state it.

Twins checked:

  • graphicformat.rs passes Vec::new for map text graphics. That leaves them without a section, as the PR intends.
  • The other textform::show caller is the Format pane in layoutview.rs, which the PR updates.
  • The map view's ui.dynamicText is a map graphic tool, not a layout menu.
  • No command, saved-file or command-surface change, so schema and command-surface.txt need no update.

Change size

Compared with the base branch (merge base e185e02 to PR head 22890a5), not the latest push.

Measure Value
Files changed 5 (0 added, 5 modified, 0 removed, 0 renamed)
Size before 710.4 KB
Size after 720.4 KB
Total size change +10.1 KB
Path Before After Change
crates/ui-egui/src/textform.rs 27.9 KB 35.6 KB +7.7 KB
crates/ui-egui/src/ribbon.rs 303.9 KB 305.7 KB +1.8 KB
docs/user-guide/layouts.md 73.4 KB 73.8 KB +392 B
crates/ui-egui/src/layoutview.rs 280.9 KB 281.0 KB +115 B
crates/ui-egui/src/graphicformat.rs 24.2 KB 24.2 KB +22 B

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3040/
Web app https://preview.rustgis.app/pr-3040/app/
Commit 22890a5

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

Merged via the queue into opengeos:main with commit 5d49160 Nov 26, 2026
28 checks passed
@jgregoriorincon
jgregoriorincon deleted the feat/2853-statistic-menu branch November 26, 2026 19:27
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.

[Feature]: The Dynamic Text menus offer a layer's count, sum, mean, least and greatest

1 participant