diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index ce11f715d0..17553ae834 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -74,7 +74,7 @@ pub fn commands() -> Vec { r#""title"?: text, "#, r#""subtitle"?: text, "#, r#""sources"?: text | [texts] (any of the texts may hold a layer's figure as the layout's texts do: {count:Layer}, {sum:Layer:field}, {mean:…}, {min:…}, {max:…}, filled in when the page is drawn), "#, - r#""reference"?: text | [texts] (default: the projection, datum and graticule), "#, + r#""reference"?: text | [texts] (default: the projection, datum and graticule; the projection and datum alone with "grid": "none"), "#, r#""note"?: text, "#, r#""author"?: text (default: "Made with RustGIS · {date}"; "" or [] for none), "#, r#""headings"?: [the sources' heading, the reference's heading, an editorial column's heading], "#, diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 33a121ab95..af6eb5fa7f 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -194,11 +194,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let strip_scale = grid.as_ref().map_or(k, |g| k * (g.label_size / grid_pt)); let room_side = if labelled.left || labelled.right { LABEL_ROOM_SIDE * strip_scale } else { 0.0 }; let room_end = if labelled.top || labelled.bottom { LABEL_ROOM_END * strip_scale } else { 0.0 }; - let reference = reference.unwrap_or_else(|| { - let [projection_line, datum_and_grid] = PUBLICATION_DEFAULT_REFERENCE; - let line = if step.is_some() { datum_and_grid } else { "Datum: {datum}" }; - vec![projection_line.into(), line.into()] - }); + let reference = reference.unwrap_or_else(|| publication_default_reference(step.is_some()).map(Into::into).to_vec()); let step_said = step.map_or_else(|| "—".to_string(), step_text); let fill = |t: &str| t.replace("{projection}", &projection).replace("{datum}", &datum).replace("{grid}", &step_said); // Text is measured as it is drawn: bold as bold, and the tokens the layout fills only when it diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index 6430cd7733..8f2453879f 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -63,10 +63,11 @@ pub const PUBLICATION_DEFAULT_CREDIT: &str = "Made with RustGIS · {date}"; /// give them. pub const PUBLICATION_HEADINGS: [&str; 2] = ["Sources", "Cartographic reference"]; -/// The cartographic reference's lines when `"reference"` isn't given, on a sheet with a graticule -/// (`{projection}`, `{datum}` and `{grid}` are filled with the sheet's). Without one the command -/// writes the datum alone in place of the second. -pub const PUBLICATION_DEFAULT_REFERENCE: [&str; 2] = ["Projection: {projection}", "Datum: {datum} · Graticule: {grid}"]; +/// The cartographic reference's lines when `"reference"` isn't given, with a graticule or without +/// one (`{projection}`, `{datum}` and `{grid}` are filled with the sheet's). +pub fn publication_default_reference(graticule: bool) -> [&'static str; 2] { + ["Projection: {projection}", if graticule { "Datum: {datum} · Graticule: {grid}" } else { "Datum: {datum}" }] +} /// The most texts a publication layout takes in one list, such as its sources. pub const MAX_PUBLICATION_LINES: usize = 50; diff --git a/crates/ui-egui/src/publicationwizard/elements.rs b/crates/ui-egui/src/publicationwizard/elements.rs index 67ccc831ee..93bebbbe08 100644 --- a/crates/ui-egui/src/publicationwizard/elements.rs +++ b/crates/ui-egui/src/publicationwizard/elements.rs @@ -50,6 +50,8 @@ pub struct Elements { pub scale_bar: bool, /// Whether the map outside the extent may be veiled for the legend's room. pub veil: bool, + /// Whether the map frame has its grid; the map's own graticule is drawn either way. + pub frame_grid: bool, /// A decimal comma rather than a point. pub comma: bool, pub north_style: ArrowStyle, @@ -74,6 +76,7 @@ impl Default for Elements { colorbar: true, scale_bar: true, veil: true, + frame_grid: true, comma: false, north_style: ArrowStyle::default(), scale_units: ScaleUnits::default(), @@ -256,6 +259,7 @@ impl Draft { ("contextInLegend", (e.context && self.usable(Control::Context, s)).then(|| true.into())), ("colorbar", (!e.colorbar && self.usable(Control::Colorbar, s)).then(|| "none".into())), ("scaleBar", scale_bar), + ("grid", (!e.frame_grid).then(|| "none".into())), ("veil", (!e.veil && self.usable(Control::Veil, s)).then(|| false.into())), ("decimal", e.comma.then(|| ",".into())), ] { @@ -370,6 +374,7 @@ pub(super) fn elements_value(s: &Session, d: &Draft) -> String { push_if(e.context && d.usable(Control::Context, s), tl!("Context layers listed")); push_if(d.draws_colorbar(s), tl!("Colorbar")); push_if(d.draws_scale_bar(s), &scale); + push_if(!e.frame_grid, tl!("No frame grid")); push_if(!e.veil && d.usable(Control::Veil, s), tl!("No veil")); push_if(true, if e.comma { tl!("Decimal comma") } else { tl!("Decimal point") }); on.join("\n") @@ -440,6 +445,7 @@ pub(super) fn elements_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { tl!(v.label()) }); }); + ui.checkbox(&mut d.elements.frame_grid, tl!("Frame grid")); let usable = d.usable(Control::Veil, s); let why = if d.column() { tl!("In this style the map isn't veiled.") } else { tl!("There is no legend or colorbar to make room for.") }; tick(ui, usable, &mut d.elements.veil, tl!("Veil the map outside the extent if the legend needs room"), why); @@ -549,7 +555,8 @@ mod tests { type Wizard = egui_kittest::Harness<'static, RustGisApp>; /// The keys the step may send. - const KEYS: [&str; 9] = ["locator", "northArrow", "legend", "legendBox", "contextInLegend", "colorbar", "scaleBar", "veil", "decimal"]; + const KEYS: [&str; 10] = + ["grid", "locator", "northArrow", "legend", "legendBox", "contextInLegend", "colorbar", "scaleBar", "veil", "decimal"]; /// What the step adds to the command's parameters, by key. fn added(s: &Session, d: &Draft) -> Value { @@ -618,7 +625,8 @@ mod tests { let mut app = app(); raster(&mut app); type Set = fn(&mut Elements); - let cases: [(Set, Value); 12] = [ + let cases: [(Set, Value); 13] = [ + (|e| e.frame_grid = false, json!({"grid": "none"})), (|e| e.locator = LocatorChoice::Globe, json!({"locator": "globe"})), (|e| e.locator = LocatorChoice::Inset, json!({"locator": "inset"})), (|e| e.locator = LocatorChoice::None, json!({"locator": "none"})), @@ -1238,6 +1246,31 @@ mod tests { assert!(h.query_by_label(want).is_some()); } + /// The frame grid's box is on, and unticked it sends no grid, on a whole globe too. + #[test] + fn the_frame_grid_box_sets_the_answer() { + for prepare in [(|_| {}) as fn(&mut RustGisApp), globe] { + let mut h = step_of(prepare); + assert!(!off(&h, "Frame grid")); + click_box(&mut h, "Frame grid"); + assert!(!draft(&h).elements.frame_grid); + assert_eq!(draft(&h).sent(&h.state().session)["grid"], "none"); + click_box(&mut h, "Frame grid"); + assert!(draft(&h).sent(&h.state().session).get("grid").is_none()); + } + } + + /// The review says a frame grid left out, and nothing for the default. + #[test] + fn the_review_says_there_is_no_frame_grid() { + let mut h = step_of(|app| app.dialogs.publication.as_mut().unwrap().step = Step::Review); + assert!(h.query_by_label_contains("No frame grid").is_none()); + h.state_mut().dialogs.publication.as_mut().unwrap().elements.frame_grid = false; + h.run_steps(4); + let want = "Locator: Default (globe)\nNorth arrow: Auto (none from 20°)\nLegend\nScale bar\nNo frame grid\nDecimal point"; + assert!(h.query_by_label(want).is_some()); + } + /// Create makes the layout the step asked for; Undo takes it away. #[test] fn create_leaves_out_what_the_step_left_out() { diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 34a93d6486..3fc22b110a 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -20,7 +20,7 @@ use map::{Area, area_extent, map_step}; use review::review_step; use rustgis_engine::Session; use rustgis_engine::cmd::layout::{ - MAX_PUBLICATION_LINES, MAX_PUBLICATION_TEXT, PUBLICATION_DEFAULT_REFERENCE, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, + MAX_PUBLICATION_LINES, MAX_PUBLICATION_TEXT, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, publication_default_reference, publication_style_accent, }; use rustgis_engine::geom::Extent; diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 474f2e5d0f..2062c2dff8 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -66,7 +66,10 @@ fn reference_value(d: &Draft) -> String { match d.left_out(Field::Reference) { Some(_) if typed.is_empty() => tl!("(none)").to_string(), Some(_) => tl!("(none; the lines typed aren't used)").to_string(), - None if typed.is_empty() => tl!("The default: projection, datum and graticule, filled in on the sheet").to_string(), + None if typed.is_empty() && d.elements.frame_grid => { + tl!("The default: projection, datum and graticule, filled in on the sheet").to_string() + } + None if typed.is_empty() => tl!("The default: projection and datum, filled in on the sheet").to_string(), None => typed, } } diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index a5849955bf..853f1dbf7c 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -21,7 +21,8 @@ pub(super) fn reference_step(ui: &mut egui::Ui, d: &mut Draft) { /// The reference's box and the tick that leaves it out, as two rows of a step's grid. fn reference_rows(ui: &mut egui::Ui, d: &mut Draft) { - list(ui, d, tl!("Reference"), Field::Reference, &PUBLICATION_DEFAULT_REFERENCE.join("\n"), 2); + let hint = publication_default_reference(d.elements.frame_grid).join("\n"); + list(ui, d, tl!("Reference"), Field::Reference, &hint, 2); ui.label(""); // Wrapped to the column: a long label would widen the narrowed window. let width = field_width(ui); @@ -495,6 +496,76 @@ mod tests { } } + /// Without a frame grid the review's default names the projection and datum alone, on a sheet + /// and on a figure; lines typed and no reference read as with one. + #[test] + fn without_a_frame_grid_the_default_reference_names_no_graticule() { + let with = "The default: projection, datum and graticule, filled in on the sheet"; + let without = "The default: projection and datum, filled in on the sheet"; + for size in ["a4", "figure-1col"] { + let mut h = at(Step::Review, |d| (d.size, d.elements.frame_grid) = (size.into(), false)); + assert!(h.query_by_label(without).is_some() && h.query_by_label(with).is_none(), "{size}"); + h.state_mut().dialogs.publication.as_mut().unwrap().reference = "UTM 23S".into(); + h.run_steps(4); + assert!(h.query_by_label("UTM 23S").is_some() && h.query_by_label(without).is_none(), "{size}"); + assert_eq!(wizard(&h).params()["reference"], json!(["UTM 23S"]), "{size}"); + let d = h.state_mut().dialogs.publication.as_mut().unwrap(); + (d.reference, d.no_reference) = (String::new(), true); + h.run_steps(4); + assert!(h.query_by_label(without).is_none(), "{size}: left out"); + } + } + + /// The reference's box hints the default's lines, following the frame grid's tick, on a sheet + /// and on a figure. + #[test] + fn the_reference_box_hints_the_default() { + let with = "Projection: {projection}\nDatum: {datum} · Graticule: {grid}"; + let without = "Projection: {projection}\nDatum: {datum}"; + for (step, size) in [(Step::Sources, "a4"), (Step::Reference, "figure-1col")] { + let mut h = at(step, |d| d.size = size.into()); + let hint = |h: &Wizard| { + let edit = h.get_by_role_and_label(Role::MultilineTextInput, "Reference"); + edit.accesskit_node().placeholder().map(str::to_owned) + }; + assert_eq!(hint(&h).as_deref(), Some(with), "{size}"); + h.state_mut().dialogs.publication.as_mut().unwrap().elements.frame_grid = false; + h.run_steps(4); + assert_eq!(hint(&h).as_deref(), Some(without), "{size}"); + } + } + + /// Create draws the default reference with a frame grid and without one, a figure's on one + /// line; the frame's grid follows, and Undo takes the layout away. + #[test] + fn create_draws_the_default_reference() { + let sheet = "Projection: Web Mercator\nDatum: WGS 84"; + let figure = "Projection: Web Mercator · Datum: WGS 84"; + for (size, graticule, want) in [ + ("a4", true, format!("{sheet} · Graticule: 30°")), + ("a4", false, sheet.to_string()), + ("figure-1col", true, format!("{figure} · Graticule: 30°")), + ("figure-1col", false, figure.to_string()), + ] { + let mut h = at(Step::Review, |d| (d.size, d.elements.frame_grid) = (size.into(), graticule)); + let before = h.state().session.project.layouts.len(); + click(&mut h, "Create"); + let layout = h.state().session.project.layouts.last().unwrap(); + let text = layout.elements.iter().find_map(|e| match &e.kind { + ElementKind::Text { text, .. } if e.name == "Reference" => Some(text.as_str()), + _ => None, + }); + assert_eq!(text, Some(want.as_str()), "{size} {graticule}"); + let grid = layout.elements.iter().find_map(|e| match &e.kind { + ElementKind::MapFrame { grid, extent_of: None, .. } => Some(grid.is_some()), + _ => None, + }); + assert_eq!(grid, Some(graticule), "{size}"); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } + } + /// Create puts the sources, the reference and the heading given on the sheet, and Undo takes /// it away. #[test] diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 4e1744ba58..afbee908f6 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -57,11 +57,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu `Publication`; the review says when a layout has that name, so the new one is numbered. The **elements** are what is drawn around the map: the locator (the default, named as what it will be, a globe, an inset or none), the north arrow (auto, always or none), the legend or not, which - can be set always on a box and to list the context layers, the colorbar and the scale bar or - not, whether the map may be veiled for the legend's room, and the decimal mark; a choice the - sheet can't use is off and isn't sent. Under them, the north arrow's style, the scale bar's - units and style, and the legend's title and columns (Auto, or 1 to 6) can be picked, and - layers ticked to be left out of the legend (every layer of that name). The + can be set always on a box and to list the context layers, the colorbar, the scale bar and the + frame grid or not (without it the default reference leaves the graticule out; the map's own + graticule is still drawn when on), whether the map may be veiled for the legend's room, and the + decimal mark; a choice the sheet can't use is off and isn't sent. Under them, the north + arrow's style, the scale bar's units and style, and the legend's title and columns (Auto, or 1 + to 6) can be picked, and layers ticked to be left out of the legend (every layer of that + name). The **placement** is the arrangement (below): `best`, the favourite, one by name or one saved, or **Custom**, a corner for each surround (a corner another has swaps the two; on Panel, Editorial and Modular only the north arrow and scale bar take one, the locator and legend sitting in the @@ -201,8 +203,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu font (the title and headings bold, as drawn) and wrapped to their box, so none runs past it, and each box grows to hold them. `{projection}`, `{datum}` and `{grid}` are filled from the map when the layout is made. `{date}` and the other dynamic text - tokens stay live. The reference defaults to the projection, datum and graticule, and the - authorship to "Made with RustGIS · {date}" (`"author": ""` leaves it out). `headings` renames the two columns. + tokens stay live. The reference defaults to the projection, datum and graticule (the + projection and datum alone with `"grid": "none"`), and the authorship to + "Made with RustGIS · {date}" (`"author": ""` leaves it out). `headings` renames the two columns. - **The locator** (at the frame's top left unless the data is there): `"locator": "globe"` (a sheet's default) adds a separate globe map with simplified copies of the map's visible polygon layers held in the project. Streamed layers, rasters, points, lines and labels are left out.