Skip to content

fix(layout): a dark basemap keeps the publication legend's box (#1379) - #2226

Closed
elpidioassinaturas wants to merge 1 commit into
opengeos:mainfrom
elpidioassinaturas:fix/1379-dark-basemap-legend-box
Closed

elpidioassinaturas wants to merge 1 commit into
opengeos:mainfrom
elpidioassinaturas:fix/1379-dark-basemap-legend-box

Conversation

@elpidioassinaturas

@elpidioassinaturas elpidioassinaturas commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1379. Follow-up to #2164, from its last review thread, which came in after the merge.

The bug

#2164 leaves a publication legend's box clear when the frame shows only the basemap's water or land colour under it. Any built-in basemap's colours counted, Midnight's too: its water is #1A1F26 and its land #2E333A. The legend's text is fixed at LEGEND_TEXT = #222222, so over Midnight's open water the box was cleared and the legend was dark text on near-black (about 1.1:1 contrast).

To reproduce: add a free corner under the Midnight basemap to frame_plain_under_counts_everything_drawn_but_the_background. On main it reads as plain: the sampled colour is (26, 31, 38), Midnight's water. The legend would then lose its box.

The fix

frame_plain_under counts a background as plain only when it is light. Lightness is weighted 3:6:1, as the renderer's greys are, and must be at least LIGHT_BACKGROUND = 160. Water / land lightness of the built-in basemaps:

Basemap Water Land Plain
Paper 226 244 yes
Ocean 188 227 yes
Atlas 205 225 yes
Blank 255 255 yes
Midnight 30 50 no: keeps the box

On another body the background is the land's grey from Map::palette; with Paper that is 244, so it stays plain.

Tests

  • frame_plain_under_counts_everything_drawn_but_the_background: Midnight's water keeps the box (this case fails on main), and Ocean's light water is plain.
  • Local: cargo fmt --check, cargo clippy -p rustgis-render -p rustgis-engine --all-targets -D warnings, cargo test -p rustgis-render -p rustgis-engine. Two tests fail on this Windows machine only, as they do on main: gdal_formats_open_when_gdal_is_installed (the local GDAL 3.7.1) and reload::wrong_geometry_missing_file_and_missing_chosen_table_leave_the_layer_unchanged (a Portuguese Windows error message).

The user guide's legend box paragraph says a dark background keeps the box.

Limits

  • The threshold is fixed and isn't a parameter. It only decides between the built-in basemaps, which sit far apart (Midnight at 30 and 50, the others at 188 or more).
  • The legend's text colour is unchanged. A light legend over a dark basemap would be a separate change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Legend boxes now remain visible over dark basemap backgrounds, while light backgrounds can remain clear when no map content, graticule line, web tiles, or veil is underneath.
  • Documentation
    • Clarified when legend boxes are displayed and how to keep a white box using legendBox: "always".

opengeos#2164 cleared a publication legend's box over any built-in basemap's water
or land, Midnight's near-black too, under the legend's #222222 text. Only a
light background (3:6:1 lightness of 160 or more) counts as plain now:
Paper, Ocean, Atlas and Blank stay clear, Midnight keeps the box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

frame_plain_under now requires a matching basemap water or land background to have weighted RGB lightness of at least 160. Tests cover dark and light basemaps. The layout guide describes when the legend area remains clear and how legendBox affects the box.

Changes: Legend box background detection

Layer / File(s) Summary
Background detection and validation
crates/render/src/layout.rs, docs/user-guide/layouts.md
frame_plain_under checks that a matching water or land background meets the lightness threshold. Tests verify the behavior for Midnight and Ocean. The guide describes the clear-area condition and the legendBox setting.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: giswqs, huzaifffa, choupeanut

Merge Risk: Minimal · up to 1b46d

Publication legends keep their box over dark basemaps such as Midnight and stay clear over light ones. The change is narrow and easy to revert, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a dark basemap (Midnight) now keeps the publication legend's box. The diff matches it: frame_plain_under only treats light water or land colours as plain, so dark base…
Description check Passed The description follows the template's main sections. Summary explains the bug, cause, fix, and limits. Testing lists fmt, clippy, and test commands with results, plus two pre-existing Windows-only fa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a dark basemap (Midnight) now keeps the publication legend's box. The diff matches it: frame_plain_under only treats light water or land colours as plain, so dark basemaps keep the box. It also cites the related issue #1379, which the description links as its parent.

Full details: Description check

Explanation

The description follows the template's main sections. Summary explains the bug, cause, fix, and limits. Testing lists fmt, clippy, and test commands with results, plus two pre-existing Windows-only failures. The UI evidence section is missing its required 'No visible UI change.' line only in the sense that it is present; the author kept it, so the section is satisfied. The Related issue section is left as placeholder text and does not name an issue, although the description says 'Part of #1379' in the body.

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 colors bright,
And leaves the legend space alight.
Dark waters keep the box in place,
While Ocean clears a little space.
Then hops away with tidy grace.

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: eedcdaec-0be6-48ff-b034-485e5616fe31
Commits

Reviewing files that changed from the base of the PR and between 3fbe255 and 1b46d3b.

Files selected for processing: 2

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

@elpidioassinaturas

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread crates/render/src/layout.rs Resolved
Comment thread crates/render/src/layout.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no correctness bugs. The threshold logic, the Midnight and Ocean test cases, and the basemap lightness values in the PR description all check out against crates/map/src/lib.rs and the engine caller (crates/engine/src/cmd/layout.rs:2716). Prior review threads: none, so nothing was skipped as already raised.

Bugs

  • None found. Confidence: high.

Security

  • None. The change is pure render-side logic and adds no input handling.

Performance

  • None. The added work is one lightness check per candidate background colour.

Quality

  • The weighted-lightness formula (3R + 6G + B) / 10 now appears in both frame_plain_under and Map::palette. They could drift apart. Inline comment posted at crates/render/src/layout.rs:2599. Confidence: high. Left for the release quality pass.
  • The rewrap of the frame_plain_under doc paragraph is ragged around lines 2541–2544. Inline comment posted. Confidence: high. Left for the release quality pass.
  • Behaviour beyond the stated case: frame_plain_under now rejects any dark background, not only Midnight's. On non-Earth bodies the background is the land grey, so a dark-land body with a Midnight basemap now keeps its legend box too. That is consistent with the rule, but neither the PR nor docs/user-guide/layouts.md says so, and no test covers it. Confidence: medium.

AGENTS.md

  • The PR is a visible rendering change, but its body has no before/after screenshots. AGENTS.md requires them for any visible change, so this needs them before merge. Confidence: high.
  • The PR body does not say which surfaces the change reaches (desktop, browser, CLI, Python, phone, ribbon, Assistant/MCP, plugins, undo). AGENTS.md asks for that statement. Confidence: high.
  • The docs and the layout tests were updated together, and the change is pure render code with no std::time, filesystem, or wasm-specific code, so no other AGENTS.md rule is affected.

Test coverage

  • The new assertions live in the layout-level test frame_plain_under_counts_everything_drawn_but_the_background. The engine-level legendBox test near crates/engine/src/tests.rs:50455 only uses the Blank basemap. Nothing checks that layout.publication on Midnight now returns legendBox: true end to end. Suggested addition, low to medium priority.

Change size

Compared with main (merge base f437463 to PR head 1b46d3b), the whole PR.

Measure Value
Files changed 2 (added 0, modified 2, removed 0, renamed 0)
Size before 354.5 KB
Size after 355.5 KB
Total size change +1.0 KB
Path Before After Change
crates/render/src/layout.rs 307.1 KB 308.0 KB +938 B
docs/user-guide/layouts.md 47.3 KB 47.4 KB +116 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2226/
Web app https://preview.rustgis.app/pr-2226/app/
Commit 1b46d3b

GitHub Pages takes a minute or two to publish a new commit.

@elpidioassinaturas

Copy link
Copy Markdown
Contributor Author

Superseded by #2194, which fixes the same bug on main: a publication legend over a dark basemap such as Midnight keeps its box. That PR has its own test, plain_dark_basemaps_keep_the_legend_paper_while_light_ones_clear_it. Closing this one.

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.

2 participants