From 54f9af0a02903c725c8de22ffa56815a6f661fad Mon Sep 17 00:00:00 2001 From: m-hollis-1 <207106921+m-hollis-1@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:49:36 -0600 Subject: [PATCH 01/28] test(render): pin how a layout legend draws, is measured and exports, and what it says A legend with none of the coming fitting settings is pinned by hashes of main's drawing, its measured sizes, its SVG and its PDF, and main's fit notices and publication layouts, in the built-in face in a child process. Co-Authored-By: Claude Fable 5.2 --- crates/engine/src/tests.rs | 65 +++++++++++ crates/render/src/layout.rs | 211 ++++++++++++++++++++++++++++++++++++ crates/render/src/svg.rs | 35 ++++++ 3 files changed, 311 insertions(+) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 398bf87c1c..90a4306f60 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12899,6 +12899,71 @@ fn layout_scale_bars_take_their_details() { assert_eq!(back, s.project.layouts[0]); } +/// 64-bit FNV-1a over one byte slice. +#[cfg(not(target_arch = "wasm32"))] +fn fnv_bytes(b: &[u8]) -> u64 { + b.iter().fold(0xcbf2_9ce4_8422_2325, |h, b| (h ^ u64::from(*b)).wrapping_mul(0x0100_0000_01b3)) +} + +/// What [`legend_notices_and_publications_are_as_before`] heard and laid out before legends had a +/// fit or more than three columns; in the built-in face. +#[cfg(not(target_arch = "wasm32"))] +const PINNED_LEGEND_NOTICES: u64 = 0xd5f4_a138_dbbc_c84f; +#[cfg(not(target_arch = "wasm32"))] +const PINNED_PUBLICATIONS: u64 = 0x5588_2d64_179a_9eea; + +/// What main says about a legend's fit in its box, word for word, as added and when made 12 mm +/// tall, and how `layout.publication` lays out the sample, its answer and its layout (the legend, +/// its column count and box included) for a legend in one, two and three columns, before legends +/// had a fit or more than three columns; in the built-in face, in a process of its own. +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn legend_notices_and_publications_are_as_before() { + if std::env::var_os("RUSTGIS_LEGEND_NOTICE_PIN_CHILD").is_none() { + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", "tests::legend_notices_and_publications_are_as_before", "--nocapture"]) + .env("RUSTGIS_LEGEND_NOTICE_PIN_CHILD", "1") + .env("RUSTGIS_BUILTIN_FONTS", "1") + .output() + .unwrap(); + assert!(output.status.success(), "{}\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr)); + assert!(String::from_utf8_lossy(&output.stdout).contains("1 passed"), "the test didn't run in the child process"); + return; + } + let mut s = world(); + s.run("layout.new", &json!({"name": "Notices", "page": "a4", "orientation": "landscape"})).unwrap(); + let mut said = String::new(); + for p in [ + // Too narrow and too short in two columns. + json!({"kind": "legend", "columns": 2, "allClasses": true, "w": 30, "h": 20}), + // One column, too narrow. + json!({"kind": "legend", "columns": 1, "allClasses": true, "w": 15, "h": 80}), + json!({"kind": "legend", "textSize": 20, "allClasses": true, "w": 60, "h": 30}), + // Fits as added: said only once it is made 12 mm tall. + json!({"kind": "legend", "columns": 3, "allClasses": true, "w": 200, "h": 150}), + json!({"kind": "legend", "showNoData": true, "w": 40, "h": 10}), + ] { + let mark = s.notice_mark(); + let id = s.run("layout.addElement", &p).unwrap()["element"].clone(); + let added: Vec<_> = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + let mark = s.notice_mark(); + s.run("layout.update", &json!({"element": id, "h": 12})).unwrap(); + let updated: Vec<_> = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + said.push_str(&format!("{p}: {added:?} {updated:?}\n")); + } + assert!(said.contains("its last rows are left out") && said.contains("close up"), "{said}"); + let mut laid = String::new(); + // The sample's publications lay their legend in two columns (the default), one (a panel) and + // three (a thesis's half page). + for p in [json!({}), json!({"style": "panel"}), json!({"profile": "thesis-half"})] { + let mut s = world(); + let r = s.run("layout.publication", &p).unwrap(); + laid.push_str(&format!("{r}\n{}\n", serde_json::to_string(s.project.layouts.last().unwrap()).unwrap())); + } + let (n, p) = (fnv_bytes(said.as_bytes()), fnv_bytes(laid.as_bytes())); + assert_eq!((n, p), (PINNED_LEGEND_NOTICES, PINNED_PUBLICATIONS), "{n:#x} {p:#x}\n{said}\n{laid}"); +} + /// A publication's scale bar box is measured from every setting its bar has (#1379), as the /// renderer draws it: a detail given measures it again for the detailed bar, its frame drawn at /// another scale measures it again, and made plain again it is the plain bar's box once more. A diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index ba64990cff..699b92591e 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -5249,6 +5249,168 @@ pub(crate) fn plain_text_pages() -> Vec { pages } +/// The map `"Pins"` the legend pin pages key: polygons `"Parks"` in one symbol, points `"Sites"` in +/// Unique Values (12 classes, `c0` drawn at 30 points, and a feature of another value), lines +/// `"Roads"` in one dashed symbol, polygons `"Zones"` in Unique Values (5 classes, one with a +/// 60-character label) and points `"Counts"` in Graduated Colors with a feature without a number, +/// so a legend that shows no-data rows has one. One feature per class near (0, 0), so a legend of +/// what the frame draws has rows. +#[cfg(all(test, not(target_arch = "wasm32")))] +fn legend_pin_map() -> Map { + use rustgis_data::{Dataset, Field, FieldType, Geometry, Value}; + use rustgis_map::{Renderer, Symbol}; + let square = |x: f64, y: f64| { + Some(Geometry::Polygon(vec![vec![ + [(0.0, 0.0), (0.02, 0.0), (0.02, 0.02), (0.0, 0.02), (0.0, 0.0)].map(|(dx, dy)| Coord::new(x + dx, y + dy)).to_vec(), + ]])) + }; + let unique = |classes: Vec<(String, Symbol)>, other: Symbol, class_labels: BTreeMap| Renderer::Unique { + field: "kind".into(), + classes, + other, + ramp: rustgis_map::Ramp::Ember, + class_labels, + other_label: None, + class_strokes: Default::default(), + other_strokes: Vec::new(), + class_fills: Default::default(), + other_fills: Vec::new(), + expression: None, + }; + let kind = || vec![Field::new("kind", FieldType::Text)]; + let mut map = Map::new("Pins"); + let mut parks = Dataset::new("Parks", GeometryType::Polygon, Vec::new()); + parks.push(square(-0.1, -0.1), Vec::new()); + map.add_dataset(parks); + let mut sites = Dataset::new("Sites", GeometryType::Point, kind()); + let mut classes = Vec::new(); + for i in 0..12u8 { + let mut s = Symbol::default_for(GeometryType::Point, u32::from(i)); + if i == 0 { + s.size = 30.0; + } + classes.push((format!("c{i}"), s)); + sites.push(Some(Geometry::Point(Coord::new(0.01 * f64::from(i), 0.0))), vec![Value::Text(format!("c{i}"))]); + } + sites.push(Some(Geometry::Point(Coord::new(0.0, 0.05))), vec![Value::Text("elsewhere".into())]); + let id = map.add_dataset(sites); + if let Some(l) = map.layer_mut(id) { + l.renderer = unique(classes, Symbol::default_for(GeometryType::Point, 7), BTreeMap::new()); + } + let mut roads = Dataset::new("Roads", GeometryType::Polyline, Vec::new()); + roads.push(Some(Geometry::Line(vec![vec![Coord::new(-0.1, 0.0), Coord::new(0.1, 0.03)]])), Vec::new()); + let id = map.add_dataset(roads); + if let Some(l) = map.layer_mut(id) { + l.line_strokes = + vec![rustgis_map::symbology::LineStroke { dash: rustgis_map::symbology::Dash::new(&[4.0, 2.0]), ..Default::default() }]; + } + let mut zones = Dataset::new("Zones", GeometryType::Polygon, kind()); + let mut classes = Vec::new(); + for i in 0..5u8 { + classes.push((format!("z{i}"), Symbol::default_for(GeometryType::Polygon, u32::from(i)))); + zones.push(square(0.03 * f64::from(i), -0.05), vec![Value::Text(format!("z{i}"))]); + } + let long = "Zoned for mixed residential and light commercial use (draft)"; + let id = map.add_dataset(zones); + if let Some(l) = map.layer_mut(id) { + l.renderer = unique(classes, Symbol::default_for(GeometryType::Polygon, 5), [("z2".to_string(), long.to_string())].into()); + } + let mut counts = Dataset::new("Counts", GeometryType::Point, vec![Field::new("n", FieldType::Double)]); + for v in [Value::Float(10.0), Value::Float(50.0), Value::Null] { + counts.push(Some(Geometry::Point(Coord::new(-0.05, 0.05))), vec![v]); + } + let id = map.add_dataset(counts); + if let Some(l) = map.layer_mut(id) { + let base = Symbol::default_for(GeometryType::Point, 3); + let method = rustgis_map::ClassMethod::EqualInterval; + // Kept in one symbol if it can't be classed, which the pins then fail on. + if let Ok(r) = Renderer::graduated(&l.dataset, &[], "n", 2, method, rustgis_map::Ramp::Ember, base) { + l.renderer = r; + } + } + map +} + +/// Pages of one legend each with none of the fitting settings, in the combinations main draws, on +/// a 220 x 150 mm page over a hidden frame of [`legend_pin_map`], every class listed and titled +/// "Legend" unless said: 1 to 3, one, two and three columns in a box that holds them; 4 to 6, the +/// same in a short box (rows left out); 7 to 9, the same in a narrow box (columns closing up, long +/// labels running on); 10, text of 14 points in two columns, roomy; 11, text of 5 points in three +/// columns, short; 12, no title, what the frame draws, `` left out; 13, a layer +/// labelled, one excluded, in an ink of its own; 14, no-data rows, in two columns; 15, a box across +/// the page's right edge, its title's ink leaving the page; 16, a box shorter than its title; 17, +/// every layer excluded, nothing to list, in two columns. +#[cfg(all(test, not(target_arch = "wasm32")))] +pub(crate) fn legend_pin_pages() -> Vec<(Layout, Vec)> { + let (roomy, short, narrow) = ((10.0, 10.0, 200.0, 130.0), (10.0, 10.0, 200.0, 25.0), (10.0, 10.0, 30.0, 130.0)); + // No pages without it, which the pins then fail on. + let frame = serde_json::json!({"MapFrame": {"map": "Pins", "center": {"x": 0, "y": 0}, "scale": 2000000}}); + let Ok(frame) = serde_json::from_value::(frame) else { return Vec::new() }; + let page = |at: (f64, f64, f64, f64), columns: usize, f: &dyn Fn(&mut ElementKind)| { + let mut l = Layout::new("Pins", 220.0, 150.0); + let frame = l.add("Frame", (0.0, 0.0, 220.0, 150.0), frame.clone()); + // Only the legend is painted; its hidden frame still provides the map and scale. + if let Some(e) = l.elements.first_mut() { + e.visible = false; + } + let mut kind = ElementKind::Legend { + frame, + title: "Legend".into(), + all_classes: true, + hide_other: false, + show_no_data: false, + exclude: Vec::new(), + columns, + labels: BTreeMap::new(), + color: None, + text_size: rustgis_map::layout::LEGEND_TEXT_PT, + }; + f(&mut kind); + l.add("Legend", at, kind); + (l, vec![legend_pin_map()]) + }; + let mut pages = Vec::new(); + for at in [roomy, short, narrow] { + for columns in 1..=3 { + pages.push(page(at, columns, &|_| {})); + } + } + let sized = |pt: f64| { + move |k: &mut ElementKind| { + if let ElementKind::Legend { text_size, .. } = k { + *text_size = pt; + } + } + }; + pages.push(page(roomy, 2, &sized(14.0))); + pages.push(page(short, 3, &sized(5.0))); + pages.push(page(roomy, 1, &|k| { + if let ElementKind::Legend { title, all_classes, hide_other, .. } = k { + (*title, *all_classes, *hide_other) = (String::new(), false, true); + } + })); + pages.push(page(roomy, 1, &|k| { + if let ElementKind::Legend { labels, exclude, color, .. } = k { + *labels = [("Sites".to_string(), "Survey sites recorded during the 2019 field season".to_string())].into(); + *exclude = vec!["Roads".into()]; + *color = Some(Rgba::rgb(20, 60, 140)); + } + })); + pages.push(page(roomy, 2, &|k| { + if let ElementKind::Legend { show_no_data, .. } = k { + *show_no_data = true; + } + })); + pages.push(page((212.0, 10.0, 60.0, 40.0), 1, &|_| {})); + pages.push(page((10.0, 10.0, 60.0, 3.0), 1, &|_| {})); + pages.push(page(roomy, 2, &|k| { + if let ElementKind::Legend { exclude, .. } = k { + *exclude = ["Parks", "Sites", "Roads", "Zones", "Counts"].map(String::from).to_vec(); + } + })); + pages +} + #[expect(clippy::disallowed_methods, reason = "a thread the system refuses fails the test, as it should")] #[cfg(test)] mod tests { @@ -10175,6 +10337,55 @@ Elaboração: RustGIS", assert_eq!((fnv(&drawn), losses), (PINNED_TEXT_PIXELS, PINNED_TEXT_LOSSES), "{:#x} {:#x}", fnv(&drawn), losses); } + /// How [`legends_draw_as_before`]'s pages drew and measured before legends had a fit, layer + /// names to leave off or more than three columns; in the built-in face. + #[cfg(not(target_arch = "wasm32"))] + const PINNED_LEGEND_PIXELS: u64 = 0xe2d0_6046_d9cc_09b8; + #[cfg(not(target_arch = "wasm32"))] + const PINNED_LEGEND_MEASURES: u64 = 0xf386_abad_68f6_f240; + + /// A legend with none of the fitting settings draws, and is measured for its size in one to + /// three columns and for its title's ink, exactly as main did: every page at 96 dpi, and the + /// first three (one, two and three columns in a box that holds them) at 300 dpi too, which + /// holds the scaling of rows, swatches and gaps with the resolution. In a process of its own, + /// told to use the built-in face before any text. + #[cfg(not(target_arch = "wasm32"))] + #[test] + fn legends_draw_as_before() { + if std::env::var_os("RUSTGIS_LEGEND_PIN_CHILD").is_none() { + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", "layout::tests::legends_draw_as_before", "--nocapture"]) + .env("RUSTGIS_LEGEND_PIN_CHILD", "1") + .env("RUSTGIS_BUILTIN_FONTS", "1") + .output() + .unwrap(); + assert!(output.status.success(), "{}\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr)); + assert!(String::from_utf8_lossy(&output.stdout).contains("1 passed"), "the test didn't run in the child process"); + return; + } + let info = PageInfo::default(); + let (mut drawn, mut measured) = (Vec::new(), String::new()); + for (i, (l, mut maps)) in crate::layout::legend_pin_pages().into_iter().enumerate() { + for dpi in if i < 3 { &[96.0, 300.0][..] } else { &[96.0][..] } { + drawn.push(render(&l, &mut maps, *dpi, &info).unwrap()); + measured.push_str(&format!("{:?}\n", text_losses(&l, &maps, *dpi, &info))); + } + let Some(ElementKind::Legend { all_classes, hide_other, show_no_data, exclude, labels, text_size, .. }) = + l.elements.last().map(|e| &e.kind) + else { + panic!("a legend page") + }; + let sizes = + legend_sizes_with_no_data_mm(&mut maps[0], 1e6, *all_classes, *hide_other, (*show_no_data, *text_size), (exclude, labels)); + // The first three only: these are the column counts main measures. + measured.push_str(&format!("{:?}\n", sizes.map(|s| [s[0], s[1], s[2]]))); + } + // The pages exercise the title's check. + assert!(measured.contains("off_page: true"), "{measured}"); + let measures = fnv_bytes(measured.as_bytes()); + assert_eq!((fnv(&drawn), measures), (PINNED_LEGEND_PIXELS, PINNED_LEGEND_MEASURES), "{:#x} {:#x}", fnv(&drawn), measures); + } + /// How [`scale_bars_without_details_draw_as_before`]'s bars drew before scale bars had details, /// their labels in the built-in face. #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/render/src/svg.rs b/crates/render/src/svg.rs index 2bef015f66..cb7f520c27 100644 --- a/crates/render/src/svg.rs +++ b/crates/render/src/svg.rs @@ -856,4 +856,39 @@ mod tests { let (s, p) = (fnv(&svg), fnv(&pdf)); assert_eq!((s, p), (PINNED_TEXT_SVG, PINNED_TEXT_PDF), "{s:#x} {p:#x}"); } + + /// How [`legends_export_as_before`]'s pages were written as SVG and as a vector PDF before + /// legends had a fit, layer names to leave off or more than three columns; in the built-in face. + #[cfg(not(target_arch = "wasm32"))] + const PINNED_LEGEND_SVG: u64 = 0xadfa_b6b6_4b1b_50f1; + #[cfg(not(target_arch = "wasm32"))] + const PINNED_LEGEND_PDF: u64 = 0xdd47_f219_ace4_cbd7; + + /// The SVG and the vector PDF of a legend with none of the fitting settings are byte for byte + /// main's, every page of [`crate::layout::legend_pin_pages`]: in a process of its own, told to + /// use the built-in face before any text. + #[cfg(not(target_arch = "wasm32"))] + #[test] + fn legends_export_as_before() { + if std::env::var_os("RUSTGIS_LEGEND_EXPORT_PIN_CHILD").is_none() { + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", "svg::tests::legends_export_as_before", "--nocapture"]) + .env("RUSTGIS_LEGEND_EXPORT_PIN_CHILD", "1") + .env("RUSTGIS_BUILTIN_FONTS", "1") + .output() + .unwrap(); + assert!(output.status.success(), "{}\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr)); + assert!(String::from_utf8_lossy(&output.stdout).contains("1 passed"), "the test didn't run in the child process"); + return; + } + let info = PageInfo::default(); + let (mut svg, mut pdf) = (Vec::new(), Vec::new()); + for (l, mut maps) in crate::layout::legend_pin_pages() { + svg.extend(layout_svg(&l, &mut maps, 72.0, &info).unwrap().0.into_bytes()); + let (drawing, _) = crate::layout::render_drawing(&l, &mut maps, 150.0, &info).unwrap(); + pdf.extend(crate::pdf::write(&[crate::pdf::Page::drawing(drawing, l.width, l.height)], "Legends")); + } + let (s, p) = (fnv(&svg), fnv(&pdf)); + assert_eq!((s, p), (PINNED_LEGEND_SVG, PINNED_LEGEND_PDF), "{s:#x} {p:#x}"); + } } From 2d6643c2c16273332a170c4fa54fe5d8f69e9042 Mon Sep 17 00:00:00 2001 From: m-hollis-1 <207106921+m-hollis-1@users.noreply.github.com> Date: Thu, 26 Nov 2026 13:21:48 -0600 Subject: [PATCH 02/28] test(render): pin each legend page, notice and publication on its own Co-Authored-By: Claude Fable 5.2 --- crates/engine/src/tests.rs | 78 ++++++++++++++++----- crates/render/src/layout.rs | 134 ++++++++++++++++++++++++++++++------ crates/render/src/svg.rs | 63 ++++++++++++++--- 3 files changed, 228 insertions(+), 47 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 90a4306f60..1708c3434e 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12906,19 +12906,34 @@ fn fnv_bytes(b: &[u8]) -> u64 { } /// What [`legend_notices_and_publications_are_as_before`] heard and laid out before legends had a -/// fit or more than three columns; in the built-in face. +/// fit or more than three columns, in the built-in face: what each of its legends was told, in +/// turn. #[cfg(not(target_arch = "wasm32"))] -const PINNED_LEGEND_NOTICES: u64 = 0xd5f4_a138_dbbc_c84f; +const PINNED_LEGEND_NOTICES: [u64; 6] = [ + 0x214b_b413_045f_6d4e, // 1: two columns, too narrow and too short + 0x7daa_504e_46ff_6418, // 2: one column, too narrow + 0x98c3_7e4b_aff1_2feb, // 3: text of 20 points + 0x66ee_667f_12a6_c320, // 4: three columns that fit, then too short + 0x744f_5513_44ff_865e, // 5: no-data rows, what the frame draws + 0x7010_ddb2_f99e_6f4a, // 6: three columns, too narrow only +]; +/// The answer and the layout of each of its publications, in turn. #[cfg(not(target_arch = "wasm32"))] -const PINNED_PUBLICATIONS: u64 = 0x5588_2d64_179a_9eea; +const PINNED_PUBLICATIONS: [u64; 3] = [ + 0x975c_564c_cd22_6e09, // the default: two columns + 0xd042_13d6_dfca_489f, // a panel: one column + 0xb6ba_991c_c801_6290, // a thesis's half page: three columns +]; /// What main says about a legend's fit in its box, word for word, as added and when made 12 mm -/// tall, and how `layout.publication` lays out the sample, its answer and its layout (the legend, -/// its column count and box included) for a legend in one, two and three columns, before legends -/// had a fit or more than three columns; in the built-in face, in a process of its own. +/// tall, case by case, and how `layout.publication` lays out the sample, its answer and its layout +/// (the legend, its column count and box included), for a legend in two, one and three columns, +/// before legends had a fit or more than three columns; in the built-in face, in a process of its +/// own. #[cfg(not(target_arch = "wasm32"))] #[test] fn legend_notices_and_publications_are_as_before() { + use rustgis_map::layout::ElementKind; if std::env::var_os("RUSTGIS_LEGEND_NOTICE_PIN_CHILD").is_none() { let output = std::process::Command::new(std::env::current_exe().unwrap()) .args(["--exact", "tests::legend_notices_and_publications_are_as_before", "--nocapture"]) @@ -12930,10 +12945,24 @@ fn legend_notices_and_publications_are_as_before() { assert!(String::from_utf8_lossy(&output.stdout).contains("1 passed"), "the test didn't run in the child process"); return; } + // Each hash that isn't its pinned one, named, with both values and all of them to pin. + let mismatches = |what: &str, got: &[(String, u64)], pinned: &[u64]| { + let mut wrong: Vec = got + .iter() + .zip(pinned) + .filter(|((_, g), p)| g != *p) + .map(|((name, g), p)| format!("{what} {name}: got {g:#018x}, pinned {p:#018x}")) + .collect(); + if got.len() != pinned.len() || !wrong.is_empty() { + let all: Vec = got.iter().map(|(name, g)| format!("{g:#018x}, // {name}")).collect(); + wrong.push(format!("{what}s, {} of {} pinned, all:\n{}", got.len(), pinned.len(), all.join("\n"))); + } + wrong + }; let mut s = world(); s.run("layout.new", &json!({"name": "Notices", "page": "a4", "orientation": "landscape"})).unwrap(); - let mut said = String::new(); - for p in [ + let mut said = Vec::new(); + for (i, p) in [ // Too narrow and too short in two columns. json!({"kind": "legend", "columns": 2, "allClasses": true, "w": 30, "h": 20}), // One column, too narrow. @@ -12942,26 +12971,41 @@ fn legend_notices_and_publications_are_as_before() { // Fits as added: said only once it is made 12 mm tall. json!({"kind": "legend", "columns": 3, "allClasses": true, "w": 200, "h": 150}), json!({"kind": "legend", "showNoData": true, "w": 40, "h": 10}), - ] { + // Too narrow only, in three columns, as added. + json!({"kind": "legend", "columns": 3, "allClasses": true, "w": 20, "h": 150}), + ] + .into_iter() + .enumerate() + { let mark = s.notice_mark(); let id = s.run("layout.addElement", &p).unwrap()["element"].clone(); let added: Vec<_> = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); let mark = s.notice_mark(); s.run("layout.update", &json!({"element": id, "h": 12})).unwrap(); let updated: Vec<_> = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); - said.push_str(&format!("{p}: {added:?} {updated:?}\n")); + if i == 5 { + assert!(added.len() == 1 && added.iter().all(|n| n.contains("close up")), "{added:?}"); + } + said.push((format!("case {} {p}", i + 1), fnv_bytes(format!("{p}: {added:?} {updated:?}\n").as_bytes()))); } - assert!(said.contains("its last rows are left out") && said.contains("close up"), "{said}"); - let mut laid = String::new(); - // The sample's publications lay their legend in two columns (the default), one (a panel) and - // three (a thesis's half page). + let mut laid = Vec::new(); + let mut columns = Vec::new(); for p in [json!({}), json!({"style": "panel"}), json!({"profile": "thesis-half"})] { let mut s = world(); let r = s.run("layout.publication", &p).unwrap(); - laid.push_str(&format!("{r}\n{}\n", serde_json::to_string(s.project.layouts.last().unwrap()).unwrap())); + let layout = s.project.layouts.last().unwrap(); + columns.extend(layout.elements.iter().find_map(|e| match &e.kind { + ElementKind::Legend { columns, .. } => Some(*columns), + _ => None, + })); + laid.push((format!("publication {p}"), fnv_bytes(format!("{r}\n{}\n", serde_json::to_string(layout).unwrap()).as_bytes()))); } - let (n, p) = (fnv_bytes(said.as_bytes()), fnv_bytes(laid.as_bytes())); - assert_eq!((n, p), (PINNED_LEGEND_NOTICES, PINNED_PUBLICATIONS), "{n:#x} {p:#x}\n{said}\n{laid}"); + // The sample's publications lay their legend in two columns (the default), one (a panel) and + // three (a thesis's half page). + assert_eq!(columns, [2, 1, 3]); + let mut wrong = mismatches("notice", &said, &PINNED_LEGEND_NOTICES); + wrong.extend(mismatches("publication", &laid, &PINNED_PUBLICATIONS)); + assert!(wrong.is_empty(), "{}", wrong.join("\n")); } /// A publication's scale bar box is measured from every setting its bar has (#1379), as the diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 699b92591e..53b29bc5d1 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -5339,7 +5339,8 @@ fn legend_pin_map() -> Map { /// columns, short; 12, no title, what the frame draws, `` left out; 13, a layer /// labelled, one excluded, in an ink of its own; 14, no-data rows, in two columns; 15, a box across /// the page's right edge, its title's ink leaving the page; 16, a box shorter than its title; 17, -/// every layer excluded, nothing to list, in two columns. +/// every layer excluded, nothing to list, in two columns; 18, what the frame draws with no-data +/// rows asked for (which only a legend of every class adds), in two columns. #[cfg(all(test, not(target_arch = "wasm32")))] pub(crate) fn legend_pin_pages() -> Vec<(Layout, Vec)> { let (roomy, short, narrow) = ((10.0, 10.0, 200.0, 130.0), (10.0, 10.0, 200.0, 25.0), (10.0, 10.0, 30.0, 130.0)); @@ -5408,9 +5409,35 @@ pub(crate) fn legend_pin_pages() -> Vec<(Layout, Vec)> { *exclude = ["Parks", "Sites", "Roads", "Zones", "Counts"].map(String::from).to_vec(); } })); + pages.push(page(roomy, 2, &|k| { + if let ElementKind::Legend { all_classes, show_no_data, .. } = k { + (*all_classes, *show_no_data) = (false, true); + } + })); pages } +/// Each of `got`'s hashes that isn't its `pinned` one, named for its page (and resolution), with +/// both values, and the whole of `got` to pin when the change is meant; one more line when the +/// counts differ. `what` names the output compared. +#[cfg(all(test, not(target_arch = "wasm32")))] +pub(crate) fn pin_mismatches(what: &str, got: &[(String, u64)], pinned: &[u64]) -> Vec { + let mut wrong: Vec = got + .iter() + .zip(pinned) + .filter(|((_, g), p)| g != *p) + .map(|((name, g), p)| format!("{what} of {name}: got {g:#018x}, pinned {p:#018x}")) + .collect(); + if got.len() != pinned.len() { + wrong.push(format!("{what}: {} hashes, {} pinned", got.len(), pinned.len())); + } + if !wrong.is_empty() { + let all: Vec = got.iter().map(|(name, g)| format!("{g:#018x}, // {name}")).collect(); + wrong.push(format!("{what}, all:\n{}", all.join("\n"))); + } + wrong +} + #[expect(clippy::disallowed_methods, reason = "a thread the system refuses fails the test, as it should")] #[cfg(test)] mod tests { @@ -10337,18 +10364,64 @@ Elaboração: RustGIS", assert_eq!((fnv(&drawn), losses), (PINNED_TEXT_PIXELS, PINNED_TEXT_LOSSES), "{:#x} {:#x}", fnv(&drawn), losses); } - /// How [`legends_draw_as_before`]'s pages drew and measured before legends had a fit, layer - /// names to leave off or more than three columns; in the built-in face. + /// How [`legends_draw_as_before`]'s pages drew before legends had a fit, layer names to leave + /// off or more than three columns, in the built-in face: each page of + /// [`crate::layout::legend_pin_pages`] at 96 dpi, the first three at 300 dpi after it. #[cfg(not(target_arch = "wasm32"))] - const PINNED_LEGEND_PIXELS: u64 = 0xe2d0_6046_d9cc_09b8; + const PINNED_LEGEND_PIXELS: [u64; 21] = [ + 0xfdc3_d550_3af3_da82, // 1: one column, roomy, 96 dpi + 0xfa9a_c1b3_ef86_ded0, // 1: 300 dpi + 0x9def_85e9_f2bf_79ce, // 2: two columns, roomy, 96 dpi + 0xeb46_544e_ed74_f8e3, // 2: 300 dpi + 0x5875_a607_ce55_8e8b, // 3: three columns, roomy, 96 dpi + 0x1e6a_1390_09e4_a43a, // 3: 300 dpi + 0x860a_f6db_8d10_a01a, // 4: one column, short + 0x5dcb_a1db_07b2_9160, // 5: two columns, short + 0x0235_53e1_a2df_0855, // 6: three columns, short + 0xfdc3_d550_3af3_da82, // 7: one column, narrow (page 1's: one column has none to close up) + 0x0e5a_0092_f5eb_407b, // 8: two columns, narrow + 0xc34e_9a2b_2000_de11, // 9: three columns, narrow + 0x6011_fd0f_a03d_920e, // 10: 14 pt, two columns + 0xbb8d_03ca_f40c_1d9d, // 11: 5 pt, three columns, short + 0x6867_5d22_3f63_43e8, // 12: no title, what the frame draws, other left out + 0x4f28_090b_e840_a63d, // 13: labelled, excluded, ink + 0xdfab_ac0a_fef8_0764, // 14: no-data rows, two columns + 0xb7b0_2d21_13c9_ff7a, // 15: across the right edge + 0x122e_6c5c_24ac_2eb1, // 16: shorter than its title + 0x122e_6c5c_24ac_2eb1, // 17: nothing to list (page 16's: its title alone) + 0x895d_688f_af95_5420, // 18: what the frame draws, no-data asked + ]; + /// How each of those pages measured: what [`text_losses`] found at each resolution it was + /// drawn at, and its rows' sizes in one to three columns (alike on pages that differ only in + /// their box). #[cfg(not(target_arch = "wasm32"))] - const PINNED_LEGEND_MEASURES: u64 = 0xf386_abad_68f6_f240; + const PINNED_LEGEND_MEASURES: [u64; 18] = [ + 0x698b_5830_84be_65fe, // 1: one column, roomy + 0x698b_5830_84be_65fe, // 2: two columns, roomy + 0x698b_5830_84be_65fe, // 3: three columns, roomy + 0xbf3a_eef4_592a_7206, // 4: one column, short + 0xbf3a_eef4_592a_7206, // 5: two columns, short + 0xbf3a_eef4_592a_7206, // 6: three columns, short + 0xbf3a_eef4_592a_7206, // 7: one column, narrow + 0xbf3a_eef4_592a_7206, // 8: two columns, narrow + 0xbf3a_eef4_592a_7206, // 9: three columns, narrow + 0x4e3b_8653_1ac5_6e1d, // 10: 14 pt, two columns + 0x5e46_780d_cd4a_87c4, // 11: 5 pt, three columns, short + 0xab16_62c7_8d9c_398a, // 12: no title, what the frame draws, other left out + 0xbdc6_2076_84cc_97c7, // 13: labelled, excluded, ink + 0x0de9_b39c_7273_61da, // 14: no-data rows, two columns + 0x6de4_4bc0_7e82_51cc, // 15: across the right edge + 0xbf3a_eef4_592a_7206, // 16: shorter than its title + 0x7249_b531_f330_3a30, // 17: nothing to list + 0x18ef_3e69_73a3_50c9, // 18: what the frame draws, no-data asked + ]; /// A legend with none of the fitting settings draws, and is measured for its size in one to - /// three columns and for its title's ink, exactly as main did: every page at 96 dpi, and the - /// first three (one, two and three columns in a box that holds them) at 300 dpi too, which - /// holds the scaling of rows, swatches and gaps with the resolution. In a process of its own, - /// told to use the built-in face before any text. + /// three columns and for its title's ink, exactly as main did, page by page: every page at 96 + /// dpi, and the first three (one, two and three columns in a box that holds them) at 300 dpi + /// too, which holds the scaling of rows, swatches and gaps with the resolution. Its size is + /// measured at the scale its hidden frame draws the map at, as the commands measure it. In a + /// process of its own, told to use the built-in face before any text. #[cfg(not(target_arch = "wasm32"))] #[test] fn legends_draw_as_before() { @@ -10364,26 +10437,47 @@ Elaboração: RustGIS", return; } let info = PageInfo::default(); - let (mut drawn, mut measured) = (Vec::new(), String::new()); + let (mut drawn, mut measured) = (Vec::new(), Vec::new()); for (i, (l, mut maps)) in crate::layout::legend_pin_pages().into_iter().enumerate() { - for dpi in if i < 3 { &[96.0, 300.0][..] } else { &[96.0][..] } { - drawn.push(render(&l, &mut maps, *dpi, &info).unwrap()); - measured.push_str(&format!("{:?}\n", text_losses(&l, &maps, *dpi, &info))); + let page = i + 1; + let mut said = String::new(); + for dpi in if page <= 3 { &[96.0, 300.0][..] } else { &[96.0][..] } { + let pm = render(&l, &mut maps, *dpi, &info).unwrap(); + drawn.push((format!("page {page} at {dpi} dpi"), fnv(std::slice::from_ref(&pm)))); + let losses = format!("{:?}", text_losses(&l, &maps, *dpi, &info)); + // The two pages that test the title's ink: across the page's right edge it is + // said to leave the page; in a box shorter than itself, main says nothing. + if *dpi == 96.0 && page == 15 { + assert!(losses.contains("off_page: true") && !losses.contains("below_box: true"), "page 15: {losses}"); + } + if *dpi == 96.0 && page == 16 { + assert_eq!(losses, "[]", "page 16"); + } + said.push_str(&losses); + said.push('\n'); } + let Some(ElementKind::MapFrame { map, center, scale, .. }) = l.elements.first().map(|e| &e.kind) else { panic!("a frame") }; + let scale = frame_render_scale(&maps[map_index(&maps, map).unwrap()], *center, *scale); let Some(ElementKind::Legend { all_classes, hide_other, show_no_data, exclude, labels, text_size, .. }) = l.elements.last().map(|e| &e.kind) else { panic!("a legend page") }; - let sizes = - legend_sizes_with_no_data_mm(&mut maps[0], 1e6, *all_classes, *hide_other, (*show_no_data, *text_size), (exclude, labels)); + let sizes = legend_sizes_with_no_data_mm( + &mut maps[0], + scale, + *all_classes, + *hide_other, + (*show_no_data, *text_size), + (exclude, labels), + ); // The first three only: these are the column counts main measures. - measured.push_str(&format!("{:?}\n", sizes.map(|s| [s[0], s[1], s[2]]))); + said.push_str(&format!("{:?}\n", sizes.map(|s| [s[0], s[1], s[2]]))); + measured.push((format!("page {page}"), fnv_bytes(said.as_bytes()))); } - // The pages exercise the title's check. - assert!(measured.contains("off_page: true"), "{measured}"); - let measures = fnv_bytes(measured.as_bytes()); - assert_eq!((fnv(&drawn), measures), (PINNED_LEGEND_PIXELS, PINNED_LEGEND_MEASURES), "{:#x} {:#x}", fnv(&drawn), measures); + let mut wrong = crate::layout::pin_mismatches("drawing", &drawn, &PINNED_LEGEND_PIXELS); + wrong.extend(crate::layout::pin_mismatches("measures", &measured, &PINNED_LEGEND_MEASURES)); + assert!(wrong.is_empty(), "{}", wrong.join("\n")); } /// How [`scale_bars_without_details_draw_as_before`]'s bars drew before scale bars had details, diff --git a/crates/render/src/svg.rs b/crates/render/src/svg.rs index cb7f520c27..1e737a287e 100644 --- a/crates/render/src/svg.rs +++ b/crates/render/src/svg.rs @@ -858,15 +858,54 @@ mod tests { } /// How [`legends_export_as_before`]'s pages were written as SVG and as a vector PDF before - /// legends had a fit, layer names to leave off or more than three columns; in the built-in face. + /// legends had a fit, layer names to leave off or more than three columns, in the built-in + /// face: each page of [`crate::layout::legend_pin_pages`] in turn. #[cfg(not(target_arch = "wasm32"))] - const PINNED_LEGEND_SVG: u64 = 0xadfa_b6b6_4b1b_50f1; + const PINNED_LEGEND_SVG: [u64; 18] = [ + 0xdde9_9bbd_fcfa_7b03, // 1: one column, roomy + 0x434f_548a_b50a_d07f, // 2: two columns, roomy + 0x71c1_fa20_bd53_8683, // 3: three columns, roomy + 0x81df_80de_1501_6f46, // 4: one column, short + 0xc8f1_9adc_aefe_782f, // 5: two columns, short + 0x7f24_8684_f29d_4892, // 6: three columns, short + 0xdde9_9bbd_fcfa_7b03, // 7: one column, narrow + 0xaa01_df65_0173_015e, // 8: two columns, narrow + 0x23a2_a454_7d20_f432, // 9: three columns, narrow + 0xdbab_b441_685c_fbc4, // 10: 14 pt, two columns + 0x621c_672e_2968_bf38, // 11: 5 pt, three columns, short + 0xd2c2_978b_14ce_f64c, // 12: no title, what the frame draws, other left out + 0x8546_8a86_082b_7af2, // 13: labelled, excluded, ink + 0x878e_7b18_1718_8c95, // 14: no-data rows, two columns + 0xaae8_b8f8_936e_ecff, // 15: across the right edge + 0x4546_c89f_1cf7_5dff, // 16: shorter than its title + 0x4546_c89f_1cf7_5dff, // 17: nothing to list + 0xa10a_680a_ac4d_2b58, // 18: what the frame draws, no-data asked + ]; #[cfg(not(target_arch = "wasm32"))] - const PINNED_LEGEND_PDF: u64 = 0xdd47_f219_ace4_cbd7; + const PINNED_LEGEND_PDF: [u64; 18] = [ + 0xe316_5ff2_9099_46df, // 1: one column, roomy + 0xdc6c_aa9d_bfa7_2264, // 2: two columns, roomy + 0x523d_fde1_8e25_b26b, // 3: three columns, roomy + 0x3c1d_85dd_54b4_cde8, // 4: one column, short + 0xa5ea_4672_820f_7bb1, // 5: two columns, short + 0x3ce3_aef6_103c_ea2c, // 6: three columns, short + 0xe316_5ff2_9099_46df, // 7: one column, narrow + 0x0853_87ac_de13_68de, // 8: two columns, narrow + 0xbc8b_12e8_b710_8539, // 9: three columns, narrow + 0x728a_470d_c6a9_dccf, // 10: 14 pt, two columns + 0xb7be_f398_0c8a_9815, // 11: 5 pt, three columns, short + 0x78ab_2e33_4226_39a9, // 12: no title, what the frame draws, other left out + 0x32f7_77da_1f52_9178, // 13: labelled, excluded, ink + 0x1c4b_2dcc_00bc_3477, // 14: no-data rows, two columns + 0x97fe_9568_01e8_cac8, // 15: across the right edge + 0x7e4f_2651_6981_e5bf, // 16: shorter than its title + 0x7e4f_2651_6981_e5bf, // 17: nothing to list + 0x26d6_182c_6b62_bbe2, // 18: what the frame draws, no-data asked + ]; /// The SVG and the vector PDF of a legend with none of the fitting settings are byte for byte - /// main's, every page of [`crate::layout::legend_pin_pages`]: in a process of its own, told to - /// use the built-in face before any text. + /// main's, page by page: in a process of its own, told to use the built-in face before any + /// text. #[cfg(not(target_arch = "wasm32"))] #[test] fn legends_export_as_before() { @@ -883,12 +922,16 @@ mod tests { } let info = PageInfo::default(); let (mut svg, mut pdf) = (Vec::new(), Vec::new()); - for (l, mut maps) in crate::layout::legend_pin_pages() { - svg.extend(layout_svg(&l, &mut maps, 72.0, &info).unwrap().0.into_bytes()); + for (i, (l, mut maps)) in crate::layout::legend_pin_pages().into_iter().enumerate() { + let page = format!("page {}", i + 1); + let written = layout_svg(&l, &mut maps, 72.0, &info).unwrap().0.into_bytes(); + svg.push((page.clone(), fnv(&written))); let (drawing, _) = crate::layout::render_drawing(&l, &mut maps, 150.0, &info).unwrap(); - pdf.extend(crate::pdf::write(&[crate::pdf::Page::drawing(drawing, l.width, l.height)], "Legends")); + let bytes = crate::pdf::write(&[crate::pdf::Page::drawing(drawing, l.width, l.height)], "Legends"); + pdf.push((page, fnv(&bytes))); } - let (s, p) = (fnv(&svg), fnv(&pdf)); - assert_eq!((s, p), (PINNED_LEGEND_SVG, PINNED_LEGEND_PDF), "{s:#x} {p:#x}"); + let mut wrong = crate::layout::pin_mismatches("SVG", &svg, &PINNED_LEGEND_SVG); + wrong.extend(crate::layout::pin_mismatches("PDF", &pdf, &PINNED_LEGEND_PDF)); + assert!(wrong.is_empty(), "{}", wrong.join("\n")); } } From 53404b88771775408b28abb457f311c5b740ec86 Mon Sep 17 00:00:00 2001 From: m-hollis-1 <207106921+m-hollis-1@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:48:18 -0600 Subject: [PATCH 03/28] feat(layout): a legend's fit, its layer names and up to six columns in the layout model Saved only when set, so a legend saved before saves byte for byte; a hand-edited fit or layer-names value of the wrong kind or not a name loads as the default and is counted. layout.publication still lays its legend in one to three columns. Co-Authored-By: Claude Fable 5.2 --- crates/engine/src/cmd/layout.rs | 40 +++- crates/engine/src/tests.rs | 21 ++- crates/map/src/layout.rs | 300 +++++++++++++++++++++++++++++- crates/render/src/layout.rs | 27 ++- crates/render/src/stream_tests.rs | 2 + crates/render/src/svg.rs | 4 + 6 files changed, 372 insertions(+), 22 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index e45a742f5c..875a0e30a9 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -118,10 +118,10 @@ pub fn commands() -> Vec { r#"{"layout"?, "shape"?: "rectangle"|"circle"|"ellipse"|"polygon"|"lasso", "points"?: [[u, v], …] (polygon/lasso, 0..1 across the frame), "map"?: name, "x"?, "y"?, "w"?, "h"?: mm}"#, ), C::new("layout.addElement", "Add Element", "Publish › Map Surrounds", add_element).inputs(element_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).params( - r##"{"layout"?, "kind": "northArrow"|"scaleBar"|"legend"|"colorbar"|"text"|"dynamicText"|"picture"|"table"|"chart"|"rectangle" (a neatline framing the page unless any of x, y, w, h is given)|"ellipse"|"circle"|"line"|"arrow"|"extentIndicator"|"grid", "frame"?: element id (default: the first map frame), "of"?: frame id (extentIndicator, which also takes "color" and "width" in points, default red and 2), "text"?, "size"?, "color"?: "#RRGGBB"|"#RRGGBBAA" (text, dynamicText, line, arrow, rectangle, ellipse, circle: its outline; extentIndicator; grid; scaleBar; legend, colorbar, table, chart: the ink of its text and lines, default #222222, a chart's bars and a colorbar's colours keeping theirs, and a table drawn without its white cells; refused for other kinds), "bold"?: bool (text), "italic"?: bool, "align"?: "left"|"center"|"right", "letterSpacing"?: points, -5 to 50 (text, dynamicText), "rotation"?: degrees clockwise about the box's centre, 90 reading top to bottom and -90 bottom to top, kept within -180 to 180 (text, dynamicText; refused for other kinds), "wrap"?: bool (text, dynamicText: broken into lines at spaces to fit the box's width when drawn, after its dynamic text is filled in, a word wider than the box broken across lines; default false, lines breaking only at the text's own line breaks; refused for other kinds), "valign"?: "top"|"middle"|"bottom" (text, dynamicText: where its block of lines sits down its box; default top; a block taller than its box is drawn from the top, its last lines left out, which a warning says; refused for other kinds), "lineSpacing"?: 0.5 to 3 (text, dynamicText: the distance between its lines, a multiple of the usual; default 1; refused outside that range, and for other kinds), "case"?: "none"|"upper"|"lower" (text, dynamicText: drawn in upper or lower case once its dynamic text is filled in, its text kept as typed; default none; refused for other kinds), "font"?: "sans"|"serif"|an installed font family's name, as labels.fonts lists them (text, dynamicText; a family not installed here is drawn in its fallback, and a serif where none is installed in the sans, with a warning; refused for other kinds), "fallback"?: "sans"|"serif" (a named font's, where it isn't installed; default its own class, else sans), "title"?: legend title (default "Legend"); chart: its own title ("" for none; default: its field, or the statistic of its field by the group), "allClasses"?: bool (legend: every class, not only those the frame draws), "hideOther"?: bool (legend: leave out ), "showNoData"?: bool (legend: include Graduated Colors’ missing-value symbol; default false), "exclude"?: [layer names] (legend: layers it leaves out though the map draws them), "columns"?: 1..3 (legend: the columns its rows are laid in; default 1), "textSize"?: points, 4 to 100 (legend: its layers' names and classes' labels, its title, rows, swatches and gaps following in proportion and a point symbol keeping the size the map draws it at; default 9; scaleBar: its labels, the room over the bar and between them following, the bar keeping its size; default 8; refused outside that range, and for other kinds unless null, as showNoData is), "orientation"?: "horizontal"|"vertical" (colorbar; chart: bars running across, the default, or columns standing up, each label centred under its column), "ticks"?: 2..21 (colorbar: labelled values, ends included), "tickSide"?: "below"|"above"|"right"|"left" (colorbar), "reverse"?: bool (colorbar: high values first), "fill"?: "#RRGGBBAA" (rectangle, ellipse, circle, northArrow; scaleBar: the alternating bar's light divisions, default white; refused for other kinds), "width"?: outline width in points (rectangle, ellipse, circle; 0 for none) or line width in points (line, grid), "radius"?: mm, 0 to 50 (rectangle: rounded corners), "dash"?: [points, …] (line, arrow, and a rectangle's, ellipse's or circle's outline: dash, gap, … in turn, as layer.lineStrokes takes it, at most 8, each 0 to 500; an arrow's heads stay solid; [] or null for solid; refused, null too, for other kinds), "dir"?: "horizontal"|"vertical"|"falling"|"rising" (line), "head"?: "none"|"end"|"start"|"both" (line; default "end" for an arrow), "angle"?: degrees anticlockwise from pointing right, centred on the page unless x or y is given (line, arrow; it sets the box and the direction, so w, h and dir are not used with it), "length"?: mm (line, arrow), "image"?: base64, "path"?: picture file, "layer"?: (table, chart; colorbar: a raster layer, default the top visible raster with a colour scale, not drawn by classes, which a legend lists), "field"?: (chart: a numeric field, default the layer's first; any field when it groups and counts, default then the field it groups by), "label"?: a field (chart: each bar's label when not grouped), "group"?: a field (chart: a bar per value of this field, its statistic of field over that value's features; blank values make one "(blank)" bar; default none, a bar per feature), "statistic"?: "sum" (the default)|"count" (features, numbers or not)|"mean"|"min"|"max" (chart, grouped), "order"?: "descending" (the default: largest first)|"ascending"|"category" (by label, A to Z)|"layer" (as the features come) (chart), "bars"?: 1..100 (chart: the most bars drawn, default 20), "other"?: bool (chart: the bars past "bars" gathered in a last Other bar, its statistic over their features, their sum when not grouped, last whatever the order; default false: left out, which a warning says, as it says features with no number left out), "stack"?: a field (chart, grouped by another field, summing or counting: each bar split by this field's values, a stretch per value in the key over the bars, the values its bars show by their total, largest first (A to Z when ordered by category), past 8 values 7 and a grey Other, which a warning counts; in the palette diagrams take, or with classes in the colour each value's features share on the map, a value with several keeping its palette colour, which a warning counts; values written are the bar's total; default none), "values"?: bool (chart: each bar's value written past its end, its thousands apart with commas; default false), "decimals"?: "auto" (the default: a chart's values up to 2, the zeros they end in dropped; a scale bar's labels each the decimals it needs, as before)|0..6 (chart: its values' decimals)|0..3 (scaleBar: its labels' decimals, fixed, with the thousands set apart), "barColor"?: "#RRGGBB"|"#RRGGBBAA" (chart: its bars' colour, default #3B82C4), "classes"?: bool (chart: each bar in the colour its features have on the map, by the layer's symbology classes: a bar per feature its feature's, a grouped bar the colour its features share; a bar whose features have several, which a warning counts, and an Other bar keep barColor; default false), "labelAlign"?: "left" (the default)|"right" (chart: bars running across have their labels at the left of their column, or at its right against the bars), "mirror"?: bool (chart: drawn as its mirror image, its text reading as ever: bars running across from the right, their labels at the right, or columns hanging from the top, their labels over them; beside a chart drawn the usual way the two face each other; default false), "max"?: a number above 0|"auto" (chart: the value at the far end of its bars' room, so charts given the same one share a scale; a bar past it runs to that end, which a warning counts; default "auto", its bars' own), "hideLabels"?: bool (chart: its labels left out, their room given to the bars; default false), "barOutline"?: {"color"?: "#RRGGBB"|"#RRGGBBAA" (default #222222), "width"?: points, 0 to 5 (default 0.5; 0 for none)} (chart: a line round each bar, or each stretch of a stacked one; default none) (label, group, statistic, order, bars, other, stack, values, decimals, barColor, classes, labelAlign, mirror, max, hideLabels and barOutline refused for other kinds unless null, as showNoData is, a scaleBar's decimals aside), "rows"?, "step"?: degrees, or a measured grid's units (metres) (0 picks one), "type"?: "graticule" (latitudes and longitudes, default) | "measured" (eastings and northings in a projected system), "crs"?: a measured grid's coordinate system: EPSG:25832, WKT or a PROJ string ("" or none: the map's when projected, else the UTM zone at the frame's centre), "short"?: bool (a measured grid's labels as their kilometres' last two digits, 43 for 543000), "mgrs"?: bool (a measured grid labelled as MGRS: each 100 km square named with its grid zone designation, 32T MT, and the lines by their kilometres' last two digits; its crs a WGS 84 UTM zone by EPSG code, EPSG:32601–32660 or 32701–32760, or none: the map's when it is one, else the zone at the frame's centre), "labels"?: bool (grid) | {"": "