From 84fdef1a329091749d29911f2bee0c5fbeffe2a0 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 02:22:28 -0300 Subject: [PATCH 1/4] feat(layout): write a publication's coverage grid on request (#1379) "coverage": "path.png" writes the grid the placement searched, as it settled on it, three pixels a cell: what the map draws dark, free cells white, both tinted blue in the strips the graticule's labels keep, and the surrounds placed over the map outlined in red. The answer gives the path. Asking for it adds the Files effect; the path is checked before anything changes, and a file that can't be written is a warning, the layout kept. Part of #1379. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layout.rs | 71 ++++++++++++++++++++++++++++- crates/engine/src/policy/effects.rs | 4 ++ crates/engine/src/tests.rs | 45 ++++++++++++++++++ docs/user-guide/layouts.md | 4 +- 4 files changed, 121 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 2ca805d4fc..5cc0c2bd36 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -32,7 +32,7 @@ pub fn commands() -> Vec { r#"{"name"?: string, "page"?: "letter"|"legal"|"tabloid"|"a5"|"a4"|"a3"|"a2"|"a1"|"a0", "orientation"?: "landscape"|"portrait", "width"?: mm, "height"?: mm, "template"?: "map" (frame, title, legend, north arrow, scale bar; the default)|"blank"}"#, ), C::new("layout.publication", "New Publication Layout", "Publish › Layout", publication).inputs(publication_inputs).roles(&[]).effects(crate::policy::Effects::NONE).params( - r#"{"profile"?: "a4" (the default) | "a3" | "a2" (a sheet turned to portrait or landscape, whichever the area's map comes out larger on: its extent east to west against north to south, on the map's projection) | "a4-portrait"|"a4-landscape"|"a3-portrait"|"a3-landscape"|"a2-portrait"|"a2-landscape" (a sheet: frame, title, subtitle, the map, a boxed footer)|"figure-1col" (90 mm)|"figure-1.5col" (140 mm)|"figure-2col" (190 mm)|"thesis-full" (160 × 225 mm)|"thesis-half" (160 × 110 mm) (a figure: the map edge to edge, its title and sources left to the caption), "extent"?: [west, south, east, north] in degrees that must fit (default: the map view), "name"?: string, "title"?: text, "subtitle"?: text, "sources"?: text | [texts], "reference"?: text | [texts] (default: the projection, datum and graticule), "note"?: text, "author"?: text (default: "Made with RustGIS · {date}"; "" or [] for none), "headings"?: [the sources' heading, the reference's heading, an editorial column's heading], "locator"?: "globe" (a globe with the area outlined; the default on sheets) | "inset" (the surrounding region, the area outlined) | "none" (the default on figures), "decimal"?: "." (the default) | "," (graticule, scale bar and colorbar numbers and {scale} with a decimal comma: 0,05 and 1:6.300.000), "colorbar"?: "auto" (the default: the top visible raster with a colour scale, not drawn by classes, gets one, under the legend in its box; a raster drawn by classes has them in the legend's rows instead) | "none" (no colorbar, and the legend's box has no room for one), "veil"?: true (the default: when no shape of the legend fits, a map that runs on past the extent, with a long legend, has what is outside the extent veiled and its surrounds grouped there, at up to half the scale on a sheet) | false (never veiled, and drawn at its scale; the map may still move aside), "style"?: "classic" (the default: the title over the map, the footer under it) | "banner" (the title and subtitle in a band of the accent colour across the top) | "panel" (the map at the left, a panel at the right with the title, locator, legend, sources and reference) | "editorial" (the title large in serif, a column at the right with the note, the locator and the legend) | "modular" (cards on a light page: the map, the locator and the legend each in one, the sources and reference in tinted ones) | "poster" (the page in the accent colour, the title in light text, the map in a light card, the footer in darker blocks) (a sheet's arrangement; figures leave it to the caption), "accent"?: a colour as #RRGGBB (the style's colour: its band, panel tint, headings and rules, a poster's page), "arrangement"?: "best" (the default: the favourite and each arrangement by name laid out, the one moving the least area off its corners kept, then the one leaving the least over the data, the favourite on a tie) | "favourite" (layout.arrangement's) | an arrangement by name or corner by corner, as layout.arrangement takes (the corners the locator, north arrow, legend and scale bar are at home in; one covering what the map draws there still moves)} → a new layout of the active map at a round scale, its texts wrapped to their boxes; {projection}, {datum} and {grid} in the texts are filled from the map"#, + r#"{"profile"?: "a4" (the default) | "a3" | "a2" (a sheet turned to portrait or landscape, whichever the area's map comes out larger on: its extent east to west against north to south, on the map's projection) | "a4-portrait"|"a4-landscape"|"a3-portrait"|"a3-landscape"|"a2-portrait"|"a2-landscape" (a sheet: frame, title, subtitle, the map, a boxed footer)|"figure-1col" (90 mm)|"figure-1.5col" (140 mm)|"figure-2col" (190 mm)|"thesis-full" (160 × 225 mm)|"thesis-half" (160 × 110 mm) (a figure: the map edge to edge, its title and sources left to the caption), "extent"?: [west, south, east, north] in degrees that must fit (default: the map view), "name"?: string, "title"?: text, "subtitle"?: text, "sources"?: text | [texts], "reference"?: text | [texts] (default: the projection, datum and graticule), "note"?: text, "author"?: text (default: "Made with RustGIS · {date}"; "" or [] for none), "headings"?: [the sources' heading, the reference's heading, an editorial column's heading], "locator"?: "globe" (a globe with the area outlined; the default on sheets) | "inset" (the surrounding region, the area outlined) | "none" (the default on figures), "decimal"?: "." (the default) | "," (graticule, scale bar and colorbar numbers and {scale} with a decimal comma: 0,05 and 1:6.300.000), "colorbar"?: "auto" (the default: the top visible raster with a colour scale, not drawn by classes, gets one, under the legend in its box; a raster drawn by classes has them in the legend's rows instead) | "none" (no colorbar, and the legend's box has no room for one), "veil"?: true (the default: when no shape of the legend fits, a map that runs on past the extent, with a long legend, has what is outside the extent veiled and its surrounds grouped there, at up to half the scale on a sheet) | false (never veiled, and drawn at its scale; the map may still move aside), "style"?: "classic" (the default: the title over the map, the footer under it) | "banner" (the title and subtitle in a band of the accent colour across the top) | "panel" (the map at the left, a panel at the right with the title, locator, legend, sources and reference) | "editorial" (the title large in serif, a column at the right with the note, the locator and the legend) | "modular" (cards on a light page: the map, the locator and the legend each in one, the sources and reference in tinted ones) | "poster" (the page in the accent colour, the title in light text, the map in a light card, the footer in darker blocks) (a sheet's arrangement; figures leave it to the caption), "accent"?: a colour as #RRGGBB (the style's colour: its band, panel tint, headings and rules, a poster's page), "arrangement"?: "best" (the default: the favourite and each arrangement by name laid out, the one moving the least area off its corners kept, then the one leaving the least over the data, the favourite on a tie) | "favourite" (layout.arrangement's) | an arrangement by name or corner by corner, as layout.arrangement takes (the corners the locator, north arrow, legend and scale bar are at home in; one covering what the map draws there still moves), "coverage"?: "*.png" (writes the coverage grid the placement searched, as it settled on it, three pixels a cell: what the map draws dark, the free cells white, both tinted blue in the strips the graticule's labels keep, the surrounds placed over the map outlined in red; the answer gives its path)} → a new layout of the active map at a round scale, its texts wrapped to their boxes; {projection}, {datum} and {grid} in the texts are filled from the map"#, ), C::new("layout.arrangement", "Favourite Arrangement", "Publish › Layout", arrangement).roles(&[]).effects(crate::policy::Effects::NONE).view().params( r#"{"favourite"?: "classic" (the locator top left, the north arrow top right, the legend bottom left, the scale bar bottom right) | "mirrored" | "legendRight" | "legendTop" | {"locator", "northArrow", "legend", "scaleBar": "top-left"|"top-right"|"bottom-left"|"bottom-right", each a corner of its own}} → the favourite arrangement of publication layouts (kept with the app's preferences), its corners and the arrangements by name; with no favourite given, it is only shown"#, @@ -1050,6 +1050,12 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { if accent.a() != 255 { return Err("accent is an opaque colour as #RRGGBB".into()); } + // Where the coverage grid the placement searches is written as an image (#1379). + let coverage_path = match p.get("coverage") { + None | Some(Value::Null) => None, + Some(Value::String(path)) if path.trim().to_ascii_lowercase().ends_with(".png") => Some(path.trim().to_string()), + Some(_) => return Err("coverage is the path of a .png file to write the coverage grid to".into()), + }; // No orientation asked: the one the area's map comes out larger on, from its extents east to // west and north to south on the map's projection and the room the style leaves the map. let profile = match &auto { @@ -2467,6 +2473,21 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { for (n, r, kind) in around { l.add(&n, r, kind); } + // The coverage grid as the placement searched it, with what was placed on it, for a look at + // why a surround moved (#1379). The layout is made by then: a file that can't be written is + // said, and the layout kept. + let mut coverage_written = Value::Null; + if let Some(path) = &coverage_path { + let rects: Vec = placed.iter().map(|(_, r)| *r).collect(); + let png = coverage + .as_ref() + .ok_or_else(|| "the map couldn't be drawn for it".to_string()) + .and_then(|grid| coverage_png(grid, (fx, fy, fw, fh), area, &rects)); + match png.and_then(|bytes| rustgis_data::io::write_atomic(Path::new(path), &bytes).map_err(|e| format!("{path}: {e}"))) { + Ok(()) => coverage_written = json!(path), + Err(why) => warnings.push(format!("the coverage image isn't written: {why}")), + } + } // Every element by name and id, for `layout.update`. let elements: Vec = l.elements.iter().map(|e| json!({"element": e.id, "name": e.name, "kind": e.kind.code()})).collect(); if s.project.layouts.len() >= crate::project::MAX_LAYOUTS { @@ -2477,10 +2498,56 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { s.active_layout = Some(i); let locator = locator_map.map(|(map, ..)| map); Ok( - json!({"layout": i, "name": name, "profile": profile.id, "page": [w, h], "scale": scale, "grid": step, "locator": locator, "style": style.code(), "arrangement": arrangement_used, "legendColumns": legend_cols, "mapShift": [map_shift.0, map_shift.1], "veiled": veiled.is_some(), "elements": elements, "moved": moved, "warnings": warnings}), + json!({"layout": i, "name": name, "profile": profile.id, "page": [w, h], "scale": scale, "grid": step, "locator": locator, "style": style.code(), "arrangement": arrangement_used, "legendColumns": legend_cols, "mapShift": [map_shift.0, map_shift.1], "veiled": veiled.is_some(), "elements": elements, "moved": moved, "coverage": coverage_written, "warnings": warnings}), ) } +/// The coverage grid of a publication's frame (`frame`, page mm) as a PNG, three pixels a cell +/// (#1379): a cell the map draws dark, a free one white, both tinted blue outside `area` (the +/// strips the grid's labels keep, which the search leaves out), and each surround placed over the +/// map (`placed`, page mm) outlined in red. +fn coverage_png( + (gw, gh, cells): &(u32, u32, Vec), + frame: Rect, + area: (f64, f64, f64, f64), + placed: &[Rect], +) -> Result, String> { + const CELL_PX: u32 = 3; + let (fx, fy, fw, fh) = frame; + let mut pm = tiny_skia::Pixmap::new(gw * CELL_PX, gh * CELL_PX).ok_or("the coverage grid is empty")?; + let paint = |r: u8, g: u8, b: u8| { + let mut paint = tiny_skia::Paint::default(); + paint.set_color_rgba8(r, g, b, 255); + paint + }; + let (dark, free, dark_band, free_band) = + (paint(0x33, 0x33, 0x33), paint(0xFF, 0xFF, 0xFF), paint(0x2E, 0x4A, 0x7A), paint(0xC9, 0xDD, 0xF2)); + for (i, drawn) in cells.iter().enumerate() { + let (col, row) = ((i % *gw as usize) as f64, (i / *gw as usize) as f64); + let (x, y) = (fx + (col + 0.5) / f64::from(*gw) * fw, fy + (row + 0.5) / f64::from(*gh) * fh); + let band = x < area.0 || x > area.2 || y < area.1 || y > area.3; + let colour = match (*drawn, band) { + (true, false) => &dark, + (false, false) => &free, + (true, true) => &dark_band, + (false, true) => &free_band, + }; + let px = CELL_PX as f32; + if let Some(cell) = tiny_skia::Rect::from_xywh(col as f32 * px, row as f32 * px, px, px) { + pm.fill_rect(cell, colour, tiny_skia::Transform::identity(), None); + } + } + let (sx, sy) = (f64::from(pm.width()) / fw, f64::from(pm.height()) / fh); + let line = tiny_skia::Stroke { width: 2.0, ..tiny_skia::Stroke::default() }; + for (x, y, w, h) in placed { + let r = tiny_skia::Rect::from_xywh(((x - fx) * sx) as f32, ((y - fy) * sy) as f32, (w * sx) as f32, (h * sy) as f32); + if let Some(r) = r { + pm.stroke_path(&tiny_skia::PathBuilder::from_rect(r), &paint(0xD6, 0x27, 0x28), &line, tiny_skia::Transform::identity(), None); + } + } + pm.encode_png().map_err(|e| e.to_string()) +} + fn page(s: &mut Session, p: &Value) -> CmdResult { let i = index(s, p)?; let cur = s.project.layouts.get(i).map(|l| (l.width, l.height)); diff --git a/crates/engine/src/policy/effects.rs b/crates/engine/src/policy/effects.rs index 819b790204..35b399bfa9 100644 --- a/crates/engine/src/policy/effects.rs +++ b/crates/engine/src/policy/effects.rs @@ -60,6 +60,10 @@ pub(super) fn declared(spec: &CommandSpec, params: &Value) -> Effects { if spec.id == "cube.open" && crate::cmd::cube_catalog::opens_zarr(params) { effects = effects.with(Effect::Files).with(Effect::Network); } + // A publication layout writes its coverage grid where it is asked to (#1379). + if spec.id == "layout.publication" && params.get("coverage").is_some_and(|v| !v.is_null()) { + effects = effects.with(Effect::Files); + } if spec.id == "map.addTiles" { effects = effects.union(crate::cmd::tiles::add_reach(params)); } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 650c3703fd..20d372c40b 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -41658,3 +41658,48 @@ fn a_layer_read_from_a_file_says_whether_it_and_the_file_are_in_step() { assert!(s.run("source.syncState", &json!({"layer": "Cities"})).is_err()); std::fs::remove_dir_all(dir).unwrap(); } + +/// `"coverage"` (#1379) writes the grid the placement searched as a PNG, three pixels a cell: dark +/// where the map draws, white where it is free, tinted in the graticule's label strips, the placed +/// surrounds outlined in red; the answer names it, and asking for it reaches files. A path that +/// isn't a .png is refused with nothing changed; one that can't be written is said, the layout +/// made all the same. +#[test] +fn publication_writes_its_coverage_grid() { + use crate::policy::{Effect, command_effects}; + let dir = std::env::temp_dir().join(format!("rustgis-coverage-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let mut s = world(); + let piaui = json!([-46.8, -11.6, -38.5, -2.2]); + let path = dir.join("coverage.png").display().to_string(); + let asked = json!({"extent": piaui, "coverage": path}); + let spec = s.registry.get("layout.publication").unwrap(); + assert!(command_effects(spec, &asked).contains(Effect::Files)); + assert!(!command_effects(spec, &json!({"extent": piaui})).contains(Effect::Files)); + let r = s.run("layout.publication", &asked).unwrap(); + assert_eq!(r["coverage"], json!(path), "{r}"); + let img = image::open(&path).unwrap().to_rgba8(); + assert_eq!(img.width().max(img.height()), 384 * 3); + let count = |keep: &dyn Fn([u8; 3]) -> bool| img.pixels().filter(|p| keep([p.0[0], p.0[1], p.0[2]])).count(); + let (dark, white) = (count(&|c| c == [0x33; 3] || c == [0x2E, 0x4A, 0x7A]), count(&|c| c == [0xFF; 3] || c == [0xC9, 0xDD, 0xF2])); + let strips = count(&|c| c == [0xC9, 0xDD, 0xF2] || c == [0x2E, 0x4A, 0x7A]); + let red = count(&|[r, g, b]| r > 180 && g < 90 && b < 90); + assert!(dark > 0 && white > 0 && strips > 0 && red > 0, "dark {dark}, white {white}, strips {strips}, outlines {red}"); + // Refused before anything changes. + let layouts = s.project.layouts.len(); + for bad in [json!("coverage.jpg"), json!(3)] { + let e = s.run("layout.publication", &json!({"extent": piaui, "coverage": bad})).unwrap_err(); + assert!(e.contains("coverage is the path of a .png file"), "{e}"); + } + assert_eq!(s.project.layouts.len(), layouts); + // A folder that isn't there: said, the layout made, no path in the answer. + let nowhere = dir.join("missing").join("coverage.png").display().to_string(); + let r = s.run("layout.publication", &json!({"extent": piaui, "coverage": nowhere})).unwrap(); + assert!(r["coverage"].is_null(), "{r}"); + assert!(r["warnings"].as_array().unwrap().iter().any(|w| w.as_str().unwrap().contains("the coverage image isn't written")), "{r}"); + assert_eq!(s.project.layouts.len(), layouts + 1); + // Without it, no file and no warning about one. + let r = s.run("layout.publication", &json!({"extent": piaui})).unwrap(); + assert!(r["coverage"].is_null() && !r["warnings"].to_string().contains("coverage"), "{r}"); + std::fs::remove_dir_all(dir).unwrap(); +} diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 27ba5a7575..819d551da0 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -50,7 +50,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu (by area, so moving the north arrow costs less than moving the legend), then the one leaving the least over the data; the favourite wins a tie. `"favourite"` always takes the favourite. The answer names the arrangement taken (`"arrangement"`) and the surrounds - moved off their corners (`"moved"`). Where nowhere is freer, a surround stays. One warning + moved off their corners (`"moved"`). To see why one moved, **`"coverage": "grid.png"`** + writes the grid the placement searched: what the map draws dark, the free cells white, the + strips the graticule's labels keep tinted blue, and the surrounds placed outlined in red. Where nowhere is freer, a surround stays. One warning names those left with more than a quarter of their area on the data while a corner of their size had more than a quarter less, to move by hand if that matters (data under every corner alike, such as a context layer filling the frame, isn't worth a warning); two that overlap (a From f6e6c084d048d798175dcad79276df4495ab9c2f Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 02:54:35 -0300 Subject: [PATCH 2/4] docs(layout): put the coverage image after the placement's warnings (#1379) Review round 1 on #1831: the sentence no longer splits the one on what stays put from the paragraph it belongs to, and is rewrapped. Co-Authored-By: Claude Opus 5.5 --- docs/user-guide/layouts.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 819d551da0..f6ec9e0525 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -50,13 +50,14 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu (by area, so moving the north arrow costs less than moving the legend), then the one leaving the least over the data; the favourite wins a tie. `"favourite"` always takes the favourite. The answer names the arrangement taken (`"arrangement"`) and the surrounds - moved off their corners (`"moved"`). To see why one moved, **`"coverage": "grid.png"`** - writes the grid the placement searched: what the map draws dark, the free cells white, the - strips the graticule's labels keep tinted blue, and the surrounds placed outlined in red. Where nowhere is freer, a surround stays. One warning + moved off their corners (`"moved"`). Where nowhere is freer, a surround stays. One warning names those left with more than a quarter of their area on the data while a corner of their size had more than a quarter less, to move by hand if that matters (data under every corner alike, such as a context layer filling the frame, isn't worth a warning); two that overlap (a - frame too small) are said too. + frame too small) are said too. To see why a surround moved or stayed, + **`"coverage": "grid.png"`** writes the grid the placement searched: what the map draws dark, + the free cells white, the strips the graticule's labels keep tinted blue, and the surrounds + placed outlined in red. The top visible raster with a colour scale, not drawn by classes (Stretch, a tinted hillshade), gets a colorbar beneath the legend; RGB and untinted hillshade do not, so an RGB composite over a DEM leaves it to the DEM. A raster drawn by classes (Colormap, Unique Values, Classify) has From 26498a801f0654b3b453f532094d2e5d1bdf93ed Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 03:25:46 -0300 Subject: [PATCH 3/4] fix(layout): refuse a full project before writing the coverage image (#1379) Review on #1831: the layout cap was checked after the coverage PNG was written, so a project holding all the layouts it can got the file and an error. The cap is now checked first; tested. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layout.rs | 10 +++++----- crates/engine/src/tests.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 5cc0c2bd36..8368f5683c 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -2473,9 +2473,12 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { for (n, r, kind) in around { l.add(&n, r, kind); } + if s.project.layouts.len() >= crate::project::MAX_LAYOUTS { + return Err(format!("a project holds at most {} layouts; remove one first", crate::project::MAX_LAYOUTS)); + } // The coverage grid as the placement searched it, with what was placed on it, for a look at - // why a surround moved (#1379). The layout is made by then: a file that can't be written is - // said, and the layout kept. + // why a surround moved (#1379). The layout is made by then (nothing below refuses it): a file + // that can't be written is said, and the layout kept. let mut coverage_written = Value::Null; if let Some(path) = &coverage_path { let rects: Vec = placed.iter().map(|(_, r)| *r).collect(); @@ -2490,9 +2493,6 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { } // Every element by name and id, for `layout.update`. let elements: Vec = l.elements.iter().map(|e| json!({"element": e.id, "name": e.name, "kind": e.kind.code()})).collect(); - if s.project.layouts.len() >= crate::project::MAX_LAYOUTS { - return Err(format!("a project holds at most {} layouts; remove one first", crate::project::MAX_LAYOUTS)); - } s.project.layouts.push(l); let i = s.project.layouts.len() - 1; s.active_layout = Some(i); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 20d372c40b..a013c0b8eb 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -41698,6 +41698,14 @@ fn publication_writes_its_coverage_grid() { assert!(r["coverage"].is_null(), "{r}"); assert!(r["warnings"].as_array().unwrap().iter().any(|w| w.as_str().unwrap().contains("the coverage image isn't written")), "{r}"); assert_eq!(s.project.layouts.len(), layouts + 1); + // A project holding all the layouts it can is refused before the file is written. + let full = dir.join("full.png"); + let blank = s.project.layouts[0].clone(); + s.project.layouts.resize(crate::project::MAX_LAYOUTS, blank); + let e = s.run("layout.publication", &json!({"extent": piaui, "coverage": full.display().to_string()})).unwrap_err(); + assert!(e.contains("at most"), "{e}"); + assert!(!full.exists()); + s.project.layouts.truncate(layouts + 1); // Without it, no file and no warning about one. let r = s.run("layout.publication", &json!({"extent": piaui})).unwrap(); assert!(r["coverage"].is_null() && !r["warnings"].to_string().contains("coverage"), "{r}"); From 828cf449657939dcb3202ea477f19c88e74d5002 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 07:22:56 -0300 Subject: [PATCH 4/4] test(layout): coverage image test starts clean; docs say what it shows (#1379) CodeRabbit's first review on #1831: the refusal test removes a full.png an earlier run may have left, and the docs say the image is the map's frame only, its surrounds outlined, without what sits outside it. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 2 ++ docs/user-guide/layouts.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index a013c0b8eb..11f2fce481 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -41700,6 +41700,8 @@ fn publication_writes_its_coverage_grid() { assert_eq!(s.project.layouts.len(), layouts + 1); // A project holding all the layouts it can is refused before the file is written. let full = dir.join("full.png"); + // One a run before left behind would pass for not written. + let _ = std::fs::remove_file(&full); let blank = s.project.layouts[0].clone(); s.project.layouts.resize(crate::project::MAX_LAYOUTS, blank); let e = s.run("layout.publication", &json!({"extent": piaui, "coverage": full.display().to_string()})).unwrap_err(); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index f6ec9e0525..6a6ff1c4e6 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -57,7 +57,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu frame too small) are said too. To see why a surround moved or stayed, **`"coverage": "grid.png"`** writes the grid the placement searched: what the map draws dark, the free cells white, the strips the graticule's labels keep tinted blue, and the surrounds - placed outlined in red. + placed over the map outlined in red. It shows the map's frame only: what sits outside it (a + side column's locator and legend, as `"style": "panel"` places them, the titles and the + footer) isn't on it. The top visible raster with a colour scale, not drawn by classes (Stretch, a tinted hillshade), gets a colorbar beneath the legend; RGB and untinted hillshade do not, so an RGB composite over a DEM leaves it to the DEM. A raster drawn by classes (Colormap, Unique Values, Classify) has