From 744d7ca8e222f91c9af32851316d6caf230c316a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 12:33:17 -0500 Subject: [PATCH 1/4] fix(layout): list only what the definition query keeps in tables and charts (#3478) --- crates/engine/src/tests.rs | 3 + .../src/tests/layout_definition_query.rs | 178 ++++++++++++++++++ crates/map/src/layout/elements.rs | 106 +++++++---- crates/map/src/layout/tests.rs | 78 +++++--- crates/map/src/lib.rs | 2 + crates/render/src/layout.rs | 11 +- crates/render/src/layout/table.rs | 15 +- crates/render/src/layout/tests.rs | 17 +- docs/user-guide/layouts.md | 14 +- 9 files changed, 346 insertions(+), 78 deletions(-) create mode 100644 crates/engine/src/tests/layout_definition_query.rs diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1dacd58ac3..5c2e11ab66 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -193,6 +193,9 @@ mod layer_ids; #[path = "tests/layout_table.rs"] mod layout_table; +#[path = "tests/layout_definition_query.rs"] +mod layout_definition_query; + #[path = "tests/layout_extents.rs"] mod layout_extents; diff --git a/crates/engine/src/tests/layout_definition_query.rs b/crates/engine/src/tests/layout_definition_query.rs new file mode 100644 index 0000000000..82c66e7644 --- /dev/null +++ b/crates/engine/src/tests/layout_definition_query.rs @@ -0,0 +1,178 @@ +//! A layout table and chart list only what their layer's definition query keeps (#3478). + +use super::*; +use rustgis_data::{Dataset, Field, FieldType, Geometry, GeometryType, Value as Data}; + +/// `region`, `n` and whether the query `shown = 1` keeps the row. +const SHOPS: [(&str, i64, bool); 7] = + [("E", 40, true), ("N", 90, false), ("S", 10, true), ("E", 70, false), ("N", 30, true), ("W", 80, false), ("S", 20, true)]; + +/// A blank layout "Shops page" over a map with the points layer "Shops" holding `rows`, and the +/// layer "Pages" of two features to run a series over. +fn session(rows: &[(&str, i64, bool)]) -> Session { + let mut s = Session::new(sample::world_project()); + let point = || Some(Geometry::Point(rustgis_data::Coord::new(0.0, 0.0))); + let mut ds = Dataset::new( + "Shops", + GeometryType::Point, + vec![Field::new("region", FieldType::Text), Field::new("n", FieldType::Integer), Field::new("shown", FieldType::Integer)], + ); + for (region, n, shown) in rows { + ds.push(point(), vec![Data::Text((*region).into()), Data::Int(*n), Data::Int(i64::from(*shown))]); + } + s.map_mut().add_dataset(ds); + let mut pages = Dataset::new("Pages", GeometryType::Point, vec![Field::new("p", FieldType::Integer)]); + for p in [1, 2] { + pages.push(point(), vec![Data::Int(p)]); + } + s.map_mut().add_dataset(pages); + s.run("layout.new", &json!({"name": "Shops page"})).unwrap(); + s.run("layout.addFrame", &json!({"x": 5, "y": 5, "w": 80, "h": 50})).unwrap(); + s +} + +/// The rows the query keeps, as a layer of their own. +fn kept() -> Vec<(&'static str, i64, bool)> { + SHOPS.into_iter().filter(|r| r.2).collect() +} + +fn query(s: &mut Session, text: &str) { + s.run("layer.definitionQuery", &json!({"layer": "Shops", "where": text})).unwrap(); +} + +/// Adds an element of Shops, large enough for every row, with `extra` keys; its id. +fn add(s: &mut Session, kind: &str, extra: &Value) -> u64 { + let mut p = json!({"kind": kind, "layer": "Shops", "x": 100, "y": 10, "w": 90, "h": 90}); + if kind == "chart" { + p["field"] = json!("n"); + } + if let (Some(p), Some(e)) = (p.as_object_mut(), extra.as_object()) { + p.extend(e.clone()); + } + s.run("layout.addElement", &p).unwrap()["element"].as_u64().unwrap() +} + +fn page(s: &mut Session) -> Vec { + crate::cmd::layout::layout_png(s, 0, 96.0, None).unwrap() +} + +/// The page with an element of `extra` keys over all of Shops under `text`. +fn queried(kind: &str, extra: &Value, text: &str) -> Vec { + let mut s = session(&SHOPS); + query(&mut s, text); + add(&mut s, kind, extra); + page(&mut s) +} + +/// The same element over a layer holding `rows` alone, without a query. +fn holding(kind: &str, extra: &Value, rows: &[(&str, i64, bool)]) -> Vec { + let mut s = session(rows); + add(&mut s, kind, extra); + page(&mut s) +} + +#[test] +fn a_table_and_a_chart_draw_only_what_the_query_keeps() { + for (kind, extra) in [ + ("table", json!({})), + ("table", json!({"sort": "n"})), + ("table", json!({"sort": "n", "descending": true, "rows": 2})), + ("chart", json!({"label": "region"})), + ("chart", json!({"label": "region", "bars": 2, "other": true})), + ("chart", json!({"group": "region", "statistic": "sum"})), + ("chart", json!({"group": "region", "statistic": "count"})), + ("chart", json!({"group": "region", "statistic": "mean", "values": true})), + ("chart", json!({"group": "region", "statistic": "sum", "stack": "shown"})), + ] { + let want = holding(kind, &extra, &kept()); + assert_ne!(want, holding(kind, &extra, &SHOPS), "{kind} {extra}: the hidden rows show in a drawing"); + assert_eq!(queried(kind, &extra, "shown = 1"), want, "{kind} {extra}"); + // A query keeping nothing leaves what an empty layer draws. + assert_eq!(queried(kind, &extra, "n < 0"), holding(kind, &extra, &[]), "{kind} {extra}"); + } +} + +#[test] +fn a_query_that_is_blank_or_does_not_read_keeps_every_row() { + for kind in ["table", "chart"] { + let want = holding(kind, &json!({}), &SHOPS); + for text in ["", " "] { + assert_eq!(queried(kind, &json!({}), text), want, "{kind} '{text}'"); + } + let mut s = session(&SHOPS); + s.map_mut().layers.iter_mut().find(|l| l.name == "Shops").unwrap().definition_query = Some("n = = 1".into()); + add(&mut s, kind, &json!({})); + assert_eq!(page(&mut s), want, "{kind}"); + } +} + +#[test] +fn a_table_of_the_selected_rows_leaves_out_the_hidden_ones() { + let extra = json!({"selectedOnly": true}); + let selected = |rows: &[(&str, i64, bool)], text: Option<&str>, selection: Vec| { + let mut s = session(rows); + if let Some(text) = text { + query(&mut s, text); + } + s.map_mut().layers.iter_mut().find(|l| l.name == "Shops").unwrap().selection = selection; + add(&mut s, "table", &extra); + page(&mut s) + }; + // Rows 1 and 3 are hidden; 0 and 4 are the first and third of those kept. + assert_eq!(selected(&SHOPS, Some("shown = 1"), vec![0, 1, 3, 4]), selected(&kept(), None, vec![0, 2])); + assert_eq!(selected(&SHOPS, Some("shown = 1"), vec![1, 3]), selected(&kept(), None, vec![])); +} + +#[test] +fn a_series_page_lists_what_the_query_keeps_on_it() { + for kind in ["table", "chart"] { + let mut s = session(&SHOPS); + // The first page keeps the rows up to 10. + query(&mut s, "n <= @page_number * 10"); + add(&mut s, kind, &json!({})); + s.run("layout.series", &json!({"layer": "Pages"})).unwrap(); + let mut want = session(&[("S", 10, true)]); + add(&mut want, kind, &json!({})); + want.run("layout.series", &json!({"layer": "Pages"})).unwrap(); + assert_eq!(page(&mut s), page(&mut want), "{kind}"); + } +} + +#[test] +fn undo_gives_the_hidden_rows_back() { + for kind in ["table", "chart"] { + let mut s = session(&SHOPS); + add(&mut s, kind, &json!({})); + let all = page(&mut s); + query(&mut s, "shown = 1"); + assert_eq!(page(&mut s), holding(kind, &json!({}), &kept()), "{kind}"); + s.run("edit.undo", &Value::Null).unwrap(); + assert_eq!(page(&mut s), all, "{kind}"); + } +} + +/// What exporting the page says of its tables and charts. +fn exported(s: &mut Session) -> Vec { + let dir = std::env::temp_dir().join(format!("rustgis-3478-{}-{:?}", std::process::id(), std::thread::current().id())); + std::fs::create_dir_all(&dir).unwrap(); + let mark = s.notice_mark(); + s.run("layout.export", &json!({"path": dir.join("page.pdf"), "dpi": 36})).unwrap(); + std::fs::remove_dir_all(&dir).unwrap(); + s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("Table") || t.contains("Chart")).collect() +} + +#[test] +fn what_is_said_to_be_left_out_counts_the_kept_rows_alone() { + let mut s = session(&SHOPS); + query(&mut s, "shown = 1"); + // Four rows kept of the six asked for: all of them fit, and nothing is cut. + add(&mut s, "table", &json!({"rows": 6})); + let bars = add(&mut s, "chart", &json!({"bars": 3})); + let said = exported(&mut s); + assert_eq!(said.len(), 1, "{said:?}"); + assert!(said[0].contains(&format!("({bars}): the chart draws 3 of 4 bars")), "{said:?}"); + // A box for one row of the four. + let small = add(&mut s, "table", &json!({"h": 11})); + let said = exported(&mut s); + assert!(said.iter().any(|t| t.contains(&format!("({small}): its box shows 1 of 4 rows"))), "{said:?}"); +} diff --git a/crates/map/src/layout/elements.rs b/crates/map/src/layout/elements.rs index 58f2723d10..68a155c31a 100644 --- a/crates/map/src/layout/elements.rs +++ b/crates/map/src/layout/elements.rs @@ -478,24 +478,38 @@ pub struct TableRows<'a> { pub selected_only: bool, } -/// The features of a layer a table has to list from, whatever rows it asks for: its selected rows, -/// worked out once for the count and the order, or all of them. +/// Whether a definition query's answer `kept` ([`crate::Layer::query_rows_with`]) keeps `row`; none +/// keeps every row. +fn is_kept(kept: Option<&[bool]>, row: usize) -> bool { + kept.is_none_or(|k| k.get(row) == Some(&true)) +} + +/// The features of a layer a table has to list from, whatever rows it asks for: those its +/// definition query keeps, or the selected ones among them, worked out once for the count and the +/// order. pub struct TableListing<'a> { layer: &'a crate::Layer, look: TableRows<'a>, - /// The selected rows, each once, in the layer's order; none when every row is listed from. + /// The definition query's answer, a byte a row; none when it keeps every row. + kept: Option>, + /// The selected rows it keeps, each once, in the layer's order; none when not only those are + /// listed. selected: Option>, } -/// What a table showing `look` lists from in `layer`. -pub fn table_listing<'a>(layer: &'a crate::Layer, look: TableRows<'a>) -> TableListing<'a> { +/// What a table showing `look` lists from in `layer`, its definition query read in `env`, the +/// map frame's scale and the series page (#3478). Reading the query over the layer's rows is one +/// step, without a look at Cancel, as the map frame reads it. +pub fn table_listing<'a>(layer: &'a crate::Layer, look: TableRows<'a>, env: &rustgis_data::query::Env) -> TableListing<'a> { + let kept = layer.query_rows_with(&layer.dataset, env); let selected = look.selected_only.then(|| { - let mut rows: Vec = layer.selection.iter().copied().filter(|r| *r < layer.dataset.features.len()).collect(); + let listed = |r: &usize| *r < layer.dataset.features.len() && is_kept(kept.as_deref(), *r); + let mut rows: Vec = layer.selection.iter().copied().filter(listed).collect(); rows.sort_unstable(); rows.dedup(); rows }); - TableListing { layer, look, selected } + TableListing { layer, look, kept, selected } } /// How many rows a table or a chart reads between looks at Cancel. @@ -588,24 +602,30 @@ impl Eq for Sorted<'_> {} impl TableListing<'_> { /// How many features there are to list. pub fn count(&self) -> usize { - self.selected.as_ref().map_or(self.layer.dataset.features.len(), Vec::len) + match (&self.selected, &self.kept) { + (Some(rows), _) => rows.len(), + (None, Some(kept)) => kept.iter().filter(|k| **k).count(), + (None, None) => self.layer.dataset.features.len(), + } } - /// The first `limit` rows the table lists: kind by kind, numbers by value, dates by instant, - /// text ignoring case and then by case, equal values in the layer's order. One pass over every - /// row of the layer (or every selected one) per call. Sorted, only the `limit` best rows seen - /// so far are held (a heap), not the whole layer's order: a table shows a few hundred rows of - /// what may be millions. A sorted pass looks at Cancel every few thousand rows and stops - /// there, with the rows kept so far: the export drawing them refuses its page as cancelled. + /// The first `limit` rows the table lists: kind by kind, numbers by value, dates by instant, text + /// ignoring case and then by case, equal values in the layer's order. One pass over every row it + /// lists from per call. Sorted, only the `limit` best rows seen so far are held (a heap), not the + /// whole layer's order: a table shows a few hundred rows of what may be millions. A sorted pass + /// looks at Cancel every few thousand rows it lists from and stops there, with the rows kept so + /// far: the export drawing them refuses its page as cancelled. pub fn first(self, limit: usize) -> Vec { let ds = &self.layer.dataset; let descending = self.look.descending; // Spelled as stored, as a column's field is. let field = self.look.sort.and_then(|name| ds.fields.iter().position(|f| f.name == name)); + let kept = self.kept.as_deref(); + let unselected = (0..ds.features.len()).filter(|row| is_kept(kept, *row)); let Some(field) = field else { return match self.selected { Some(rows) => rows.into_iter().take(limit).collect(), - None => (0..ds.features.len().min(limit)).collect(), + None => unselected.take(limit).collect(), }; }; use std::ops::ControlFlow; @@ -627,7 +647,7 @@ impl TableListing<'_> { // Cancelled or walked to the end, what is kept by then is returned. let _ = match self.selected { Some(rows) => rows.into_iter().enumerate().try_for_each(&mut offer), - None => (0..ds.features.len()).enumerate().try_for_each(&mut offer), + None => unselected.enumerate().try_for_each(&mut offer), }; best.into_sorted_vec().into_iter().map(|s| s.row).collect() } @@ -1003,37 +1023,42 @@ impl ElementKind { /// It looks at Cancel every few thousand features, and a cancelled read is no data. Ordering /// the bars once they are read is one step, without a look. /// - /// It reads no colours ([`ChartData::colors`] stays empty): [`ElementKind::chart_data_of`] reads - /// them from the layer for a chart coloured by classes. + /// It reads every row of `ds` and no colours ([`ChartData::colors`] stays empty): a layer's + /// chart is [`ElementKind::chart_data_of`], which keeps to the definition query and reads the + /// colours of a chart coloured by classes. pub fn chart_data(&self, ds: &rustgis_data::Dataset) -> Option { - self.chart_data_with(ds, None) + self.chart_data_with(ds, None, None) } - /// [`ElementKind::chart_data`] of `layer`'s features, a chart coloured by classes reading each - /// feature's colour as the map frame draws it: in `env`, the frame's scale and the series - /// page ([`crate::Layer::styler_with`]), by the feature's own geometry, the layer's where it - /// has none ([`crate::symbology::Symbol::shown_colour`]). A feature its symbol draws nothing - /// of, in a hidden class, has none. The layer's transparency isn't read: a bar is drawn whole. + /// [`ElementKind::chart_data`] of the features of `layer` its definition query keeps in `env` + /// (#3478), the frame's scale and the series page, as the map frame draws them; the query's answer + /// is held while they are read, a byte a feature, and reading it is one step, without a look at + /// Cancel. A chart coloured by classes reads each feature's colour as the frame draws it + /// ([`crate::Layer::styler_with`]), by the feature's own geometry, the layer's where it has none + /// ([`crate::symbology::Symbol::shown_colour`]). A feature its symbol draws nothing of, in a hidden + /// class, has none. The layer's transparency isn't read: a bar is drawn whole. pub fn chart_data_of(&self, layer: &crate::Layer, env: &rustgis_data::query::Env) -> Option { + let ds = &layer.dataset; + let kept = layer.query_rows_with(ds, env); + let kept = kept.as_deref(); if !self.chart_uses_classes() { - return self.chart_data(&layer.dataset); + return self.chart_data_with(ds, kept, None); } let styler = layer.styler_with(env.clone()); - let ds = &layer.dataset; let colour = |row: usize| { let g = ds.features.geometry(row).map_or(ds.geometry_type, rustgis_data::Geometry::kind); styler.symbol(row).shown_colour(g) }; - self.chart_data_with(ds, Some(&colour)) + self.chart_data_with(ds, kept, Some(&colour)) } - /// [`ElementKind::chart_data`], each bar coloured by `colour` (a feature row's colour, none for - /// a feature drawn with nothing) when given: a bar per feature its row's, a grouped bar the - /// colour all the features its statistic reads share (a count's every feature, another's those - /// with a number), those drawn with nothing aside. A bar without one keeps the chart's. - /// Grouped, it holds a colour (5 bytes) per value besides, and reads no more colours of a value - /// once its features have two; each colour read is the feature's symbol, as drawing the map - /// reads it. + /// [`ElementKind::chart_data`] of the rows `kept` marks (all of them without it), each bar coloured + /// by `colour` (a feature row's colour, none for a feature drawn with nothing) when given: a bar + /// per feature its row's, a grouped bar the colour all the features its statistic reads share (a + /// count's every feature, another's those with a number), those drawn with nothing aside. A bar + /// without one keeps the chart's. Grouped, it holds a colour (5 bytes) per value besides, and reads + /// no more colours of a value once its features have two; each colour read is the feature's symbol, + /// as drawing the map reads it. /// /// Stacked ([`ElementKind::chart_stack`]), the colours go to the values of the stack field /// instead: each one takes the colour all its features on the bars shown share, else its @@ -1041,7 +1066,12 @@ impl ElementKind { /// colour and two indexes (32 bytes, and the B-tree's own room) for each pair of a group value /// and a stack value that some feature has, at most one per feature, and the stack field's /// names once, as the group field's. - pub(super) fn chart_data_with(&self, ds: &rustgis_data::Dataset, colour: Option<&dyn Fn(usize) -> Option>) -> Option { + pub(super) fn chart_data_with( + &self, + ds: &rustgis_data::Dataset, + kept: Option<&[bool]>, + colour: Option<&dyn Fn(usize) -> Option>, + ) -> Option { let ElementKind::Chart { field, label, group, statistic, order, bars, other, .. } = self else { return None }; let fi = ds.field_index(field)?; let gi = match group { @@ -1077,6 +1107,9 @@ impl ElementKind { if stopped_at(row) { return None; } + if !is_kept(kept, row) { + continue; + } let at = index.slot(ds.value(row, gi)); if at == groups.len() { groups.push(Tally::default()); @@ -1138,6 +1171,9 @@ impl ElementKind { if stopped_at(row) { return None; } + if !is_kept(kept, row) { + continue; + } match number(row) { Some(n) => drawn.push((n, row)), None => no_number += 1, diff --git a/crates/map/src/layout/tests.rs b/crates/map/src/layout/tests.rs index 22ae2dae6d..378ab27ce6 100644 --- a/crates/map/src/layout/tests.rs +++ b/crates/map/src/layout/tests.rs @@ -1,5 +1,6 @@ use super::*; use crate::symbology::MAX_DASH_STEP; +use rustgis_data::query::Env; /// Several figures of one layer, worked out in one pass over its rows, are the figures worked out /// one by one, errors included (#2853). @@ -208,14 +209,14 @@ fn chart_bars_take_their_features_colours() { _ => Some(Rgba::rgb(2, 0, 0)), }; let one = chart(serde_json::json!({"field": "people", "classes": true})); - let d = one.chart_data_with(&ds, Some(&by_name)).unwrap(); + let d = one.chart_data_with(&ds, None, Some(&by_name)).unwrap(); // Largest first: a (10), d (7), b (4), c (2), f (1), g (-3). let rows = [0u8, 3, 1, 2, 5, 6]; assert_eq!(d.colors, rows.iter().map(|r| Some(Rgba::rgb(*r, 0, 0))).collect::>()); assert_eq!(d.mixed, 0); // Grouped by region: N is a and c, which have a colour each by name. let grouped = chart(serde_json::json!({"field": "people", "group": "region", "classes": true})); - let d = grouped.chart_data_with(&ds, Some(&by_name)).unwrap(); + let d = grouped.chart_data_with(&ds, None, Some(&by_name)).unwrap(); assert_eq!(bars(&d), vec![(12.0, "N"), (7.0, "E"), (4.0, "S"), (1.0, CHART_BLANK), (-3.0, "W")]); // S is b alone: e has no number, so its sum doesn't read it. assert_eq!( @@ -225,26 +226,26 @@ fn chart_bars_take_their_features_colours() { assert_eq!(d.mixed, 1); // A count reads every feature: S is b and e then. let counted = chart(serde_json::json!({"field": "people", "group": "region", "statistic": "count", "classes": true})); - let d = counted.chart_data_with(&ds, Some(&by_name)).unwrap(); + let d = counted.chart_data_with(&ds, None, Some(&by_name)).unwrap(); assert_eq!(d.mixed, 2); // By region, every bar has one colour; the Other bar keeps the chart's. let cut = chart(serde_json::json!({"field": "people", "group": "region", "bars": 3, "other": true, "classes": true})); - let d = cut.chart_data_with(&ds, Some(&by_region)).unwrap(); + let d = cut.chart_data_with(&ds, None, Some(&by_region)).unwrap(); assert_eq!(bars(&d).last().map(|b| b.1), Some(CHART_OTHER)); assert_eq!(d.colors, vec![Some(Rgba::rgb(1, 0, 0)), Some(Rgba::rgb(2, 0, 0)), None]); assert_eq!((d.mixed, d.unshown), (0, 0), "the Other bar is neither"); // Features drawn with nothing (a hidden class) give their bar none, not a clear one: N's // features are hidden, so N keeps the chart's colour without being mixed, and is counted. let hidden_n = |row: usize| by_region(row).filter(|c| *c != Rgba::rgb(1, 0, 0)); - let d = grouped.chart_data_with(&ds, Some(&hidden_n)).unwrap(); + let d = grouped.chart_data_with(&ds, None, Some(&hidden_n)).unwrap(); assert_eq!(d.colors.first(), Some(&None)); assert_eq!((d.mixed, d.unshown), (0, 1)); - let d = one.chart_data_with(&ds, Some(&hidden_n)).unwrap(); + let d = one.chart_data_with(&ds, None, Some(&hidden_n)).unwrap(); assert_eq!(d.colors.first(), Some(&None), "a, in N"); assert_eq!(d.unshown, 2, "a and c, in N"); // Only some hidden, the bar takes the colour of those that show: N is a, hidden, and c. let hidden_a = |row: usize| by_name(row).filter(|_| row != 0); - let d = grouped.chart_data_with(&ds, Some(&hidden_a)).unwrap(); + let d = grouped.chart_data_with(&ds, None, Some(&hidden_a)).unwrap(); assert_eq!(d.colors.first(), Some(&Some(Rgba::rgb(2, 0, 0)))); assert_eq!((d.mixed, d.unshown), (0, 0)); // The colour a symbol shows: a line's stroke, an area's fill or its outline where the @@ -443,17 +444,17 @@ fn stacked_bars_colour_their_key_by_classes() { rustgis_data::Value::Text(_) => Some(blue), _ => Some(green), }; - let d = kind.chart_data_with(&ds, Some(&by_kind)).unwrap(); + let d = kind.chart_data_with(&ds, None, Some(&by_kind)).unwrap(); assert_eq!(d.key.iter().map(|k| k.1).collect::>(), vec![red, blue, green]); assert_eq!((d.key_kept, d.mixed, d.unshown), (0, 0, 0)); assert!(d.colors.is_empty()); // A colour per feature: x and y have several, the blank one feature's own. let by_row = |row: usize| Some(Rgba::rgb(row as u8, 0, 0)); - let d = kind.chart_data_with(&ds, Some(&by_row)).unwrap(); + let d = kind.chart_data_with(&ds, None, Some(&by_row)).unwrap(); assert_eq!(d.key.iter().map(|k| k.1).collect::>(), vec![palette[0], palette[1], Rgba::rgb(5, 0, 0)]); assert_eq!(d.key_kept, 2); // Drawn with nothing, every value keeps its palette colour. - let d = kind.chart_data_with(&ds, Some(&|_| None)).unwrap(); + let d = kind.chart_data_with(&ds, None, Some(&|_| None)).unwrap(); assert_eq!(d.key.iter().map(|k| k.1).collect::>(), palette[..3].to_vec()); assert_eq!(d.key_kept, 3); // A value's colour is read over the bars shown: x red on A's bar, blue on B's left out, @@ -469,7 +470,7 @@ fn stacked_bars_colour_their_key_by_classes() { let by_region = |row: usize| Some(if row == 0 { red } else { blue }); let one = |other: bool| { chart(serde_json::json!({"field": "people", "group": "region", "stack": "kind", "classes": true, "bars": 1, "other": other})) - .chart_data_with(&ds, Some(&by_region)) + .chart_data_with(&ds, None, Some(&by_region)) .unwrap() }; let d = one(false); @@ -2282,7 +2283,7 @@ fn a_colorbars_label_size_and_decimals_out_of_range_are_counted() { fn a_table_lists_rows_sorted_and_selected() { let mut layer = crate::Layer::new(1, places()); let order = |layer: &crate::Layer, sort: Option<&str>, descending, selected_only, limit| { - table_listing(layer, TableRows { sort, descending, selected_only }).first(limit) + table_listing(layer, TableRows { sort, descending, selected_only }, &Env::default()).first(limit) }; assert_eq!(order(&layer, None, false, false, 3), [0, 1, 2]); assert_eq!(order(&layer, None, true, false, 20), [0, 1, 2, 3, 4, 5, 6], "no field to turn round"); @@ -2299,19 +2300,51 @@ fn a_table_lists_rows_sorted_and_selected() { assert_eq!(order(&layer, Some("gone"), true, false, 3), [0, 1, 2]); assert_eq!(order(&layer, Some("PEOPLE"), false, false, 3), [0, 1, 2]); let selected = TableRows { selected_only: true, ..TableRows::default() }; - assert!(order(&layer, None, false, true, 20).is_empty() && table_listing(&layer, selected).count() == 0); + assert!(order(&layer, None, false, true, 20).is_empty() && table_listing(&layer, selected, &Env::default()).count() == 0); // Each once, in the layer's order, and none past its last row. layer.selection = vec![6, 0, 3, 0, 99]; - assert_eq!(table_listing(&layer, selected).count(), 3); + assert_eq!(table_listing(&layer, selected, &Env::default()).count(), 3); assert_eq!(order(&layer, None, false, true, 20), [0, 3, 6]); assert_eq!(order(&layer, None, false, true, 2), [0, 3]); assert_eq!(order(&layer, Some("people"), false, true, 20), [6, 3, 0]); assert_eq!(order(&layer, Some("people"), true, true, 2), [0, 3]); - assert_eq!(table_listing(&layer, TableRows::default()).count(), 7); + assert_eq!(table_listing(&layer, TableRows::default(), &Env::default()).count(), 7); layer.dataset.features.clear(); assert!(order(&layer, Some("people"), false, false, 500).is_empty()); } +/// A table's rows and a chart's bars are those the definition query keeps in the page it is read +/// on (#3478); a query that doesn't read keeps every row. +#[test] +fn a_table_and_a_chart_read_the_definition_query_on_the_page() { + let mut layer = crate::Layer::new(1, places()); + layer.selection = vec![0, 1, 2]; + let page = |number| Env { + page: Some(std::sync::Arc::new(rustgis_data::query::SeriesPage { feature_id: 1, name: String::new(), number })), + ..Env::default() + }; + let rows = |layer: &crate::Layer, env: &Env, selected_only, sort| { + let listing = table_listing(layer, TableRows { sort, descending: false, selected_only }, env); + (listing.count(), listing.first(20)) + }; + let chart: ElementKind = serde_json::from_value( + serde_json::json!({"Chart": {"frame": 1, "layer": "t", "field": "people", "label": "name", "order": "layer"}}), + ) + .unwrap(); + let names = + |layer: &crate::Layer, env: &Env| chart.chart_data_of(layer, env).unwrap().bars.into_iter().map(|b| b.1).collect::>(); + layer.definition_query = Some("people > 3 * @page_number".into()); + assert_eq!(rows(&layer, &page(1), false, None), (3, vec![0, 1, 3])); + assert_eq!(rows(&layer, &page(2), false, None), (2, vec![0, 3])); + assert_eq!(rows(&layer, &page(1), false, Some("people")), (3, vec![1, 3, 0])); + assert_eq!(rows(&layer, &page(2), true, None), (1, vec![0])); + assert_eq!(names(&layer, &page(1)), ["a", "b", "d"]); + assert_eq!(names(&layer, &page(2)), ["a", "d"]); + layer.definition_query = Some("people = = 1".into()); + assert_eq!(rows(&layer, &page(1), false, None).0, 7); + assert_eq!(names(&layer, &page(1)).len(), 6, "every row with a number"); +} + /// Text sorts ignoring case, dates by instant, and a number that isn't one with the nulls. #[test] fn a_tables_sort_reads_values_as_the_attribute_table_does() { @@ -2322,7 +2355,7 @@ fn a_tables_sort_reads_values_as_the_attribute_table_does() { ds.push(None, vec![v]); } let look = TableRows { sort: Some("v"), ..TableRows::default() }; - table_listing(&crate::Layer::new(1, ds), look).first(10) + table_listing(&crate::Layer::new(1, ds), look, &Env::default()).first(10) }; let text = |t: &str| Value::Text(t.into()); assert_eq!(sorted(FieldType::Text, vec![text("beta"), text("Alpha"), text("gamma")]), [1, 0, 2]); @@ -2385,7 +2418,8 @@ fn a_tables_sort_of_mixed_values_does_not_depend_on_the_rows_order() { } for limit in 1..=ordered.len() { let look = TableRows { sort: Some("v"), descending, selected_only: false }; - let listed: Vec = table_listing(&layer, look).first(limit).into_iter().map(|row| values[row].clone()).collect(); + let listed: Vec = + table_listing(&layer, look, &Env::default()).first(limit).into_iter().map(|row| values[row].clone()).collect(); assert_eq!(listed, want[..limit], "turn {turn} back {back} descending {descending}"); } } @@ -2409,7 +2443,7 @@ fn a_tables_first_rows_of_many_are_the_whole_sorts_first() { (if descending { -n } else { n }, row) }); let look = TableRows { sort: Some("n"), descending, selected_only: false }; - assert_eq!(table_listing(&layer, look).first(500), whole[..500]); + assert_eq!(table_listing(&layer, look, &Env::default()).first(500), whole[..500]); } } @@ -2454,11 +2488,11 @@ fn a_tables_sort_looks_at_cancel_between_rows() { layer.selection = (0..10_000).collect(); for selected_only in [false, true] { let look = TableRows { sort: Some("n"), descending: true, selected_only }; - let (rows, looked) = cancelled_from(usize::MAX, || table_listing(&layer, look).first(3)); + let (rows, looked) = cancelled_from(usize::MAX, || table_listing(&layer, look, &Env::default()).first(3)); assert_eq!((rows, looked), (vec![9999, 9998, 9997], 3), "selected {selected_only}"); - let (rows, looked) = cancelled_from(1, || table_listing(&layer, look).first(3)); + let (rows, looked) = cancelled_from(1, || table_listing(&layer, look, &Env::default()).first(3)); assert_eq!((rows, looked), (vec![], 1), "selected {selected_only}"); - let (rows, looked) = cancelled_from(2, || table_listing(&layer, look).first(3)); + let (rows, looked) = cancelled_from(2, || table_listing(&layer, look, &Env::default()).first(3)); assert_eq!((rows, looked), (vec![4095, 4094, 4093], 2), "selected {selected_only}"); } } @@ -2497,7 +2531,7 @@ fn a_tables_sort_of_text_keeps_the_comparators_order() { }); for limit in 1..=texts.len() { let look = TableRows { sort: Some("v"), descending, selected_only: false }; - assert_eq!(table_listing(&layer, look).first(limit), want[..limit], "descending {descending} limit {limit}"); + assert_eq!(table_listing(&layer, look, &Env::default()).first(limit), want[..limit], "descending {descending} limit {limit}"); } } } diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index 04073d485b..d7652af7dd 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -5378,6 +5378,8 @@ mod tests { layer.selection.push(0); layer.definition_query = Some("@row_number = 1".into()); assert_eq!(layer.visible_rows(), [false], "old window rows must not be renumbered before the read"); + let table = |layer: &Layer| layout::table_listing(layer, Default::default(), &Default::default()).first(5); + assert!(table(&layer).is_empty(), "a layout table lists what the map draws (#3478)"); layer.sync_source(&view, true); assert_eq!(layer.query_rows(&whole).unwrap(), [true, false]); assert_eq!(layer.dataset.features[0].id, other.id); diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 0060e4d73c..61af7dc607 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -746,11 +746,16 @@ fn draw_page( None => draw_picture_box(&mut pm, r, source.as_deref(), ppp), }, ElementKind::Table { frame: f, layer, rows, color, fields, text_size, header, sort, descending, selected_only } => { - match frame(*f).and_then(|fr| maps.get(fr.1)).and_then(|m| m.layer_by_name(layer)) { - Some(shown) => { + // Its rows are read at the frame's scale and on this page, as the frame draws them. + let shown = frame(*f).and_then(|&(_, mi, cam, _, _)| { + let m = maps.get(mi)?; + Some((m.layer_by_name(layer)?, frame_style_env(m, &cam, env))) + }); + match shown { + Some((shown, on_frame)) => { let listed = TableRows { sort: sort.as_deref(), descending: *descending, selected_only: *selected_only }; let look = TableLook { rows: *rows, fields, text_size: *text_size, header: *header, listed }; - table(&mut pm, r, shown, look, *color, ppp) + table(&mut pm, r, (shown, &on_frame), look, *color, ppp) } None => placeholder(&mut pm, r, "Table", ppp), } diff --git a/crates/render/src/layout/table.rs b/crates/render/src/layout/table.rs index 66a4a9b290..1dc207bd39 100644 --- a/crates/render/src/layout/table.rs +++ b/crates/render/src/layout/table.rs @@ -1,6 +1,7 @@ //! The attribute table element. use super::*; +use rustgis_data::query::Env; use rustgis_map::layout::{TABLE_TEXT_PT, TableRows, table_listing}; /// How a table is laid out: the rows and fields it shows, its text and whether it is headed. @@ -69,8 +70,8 @@ impl TableCut { /// The tables of `layout` drawn at `dpi` whose boxes don't hold the rows and columns they are /// asked to show (#3416), or whose sort field is gone (#3409). A hidden table, one with none of -/// its box on the page and one drawn as a placeholder (no frame, map or layer) show nothing to -/// count. +/// its box on the page and one drawn as a placeholder (no frame, map or layer, or a series page +/// that can't be read) show nothing to count. pub fn tables_cut(layout: &Layout, maps: &[Map], dpi: f64) -> Vec { let k = page_geometry(layout, dpi).2; let ppp = (k / PT_PER_MM) as f32; @@ -78,14 +79,14 @@ pub fn tables_cut(layout: &Layout, maps: &[Map], dpi: f64) -> Vec { let ElementKind::Table { frame, layer, rows, fields, text_size, header, sort, descending, selected_only, .. } = &e.kind else { return None; }; - let ElementKind::MapFrame { map, .. } = &layout.element(*frame)?.kind else { return None }; - let shown = maps.get(map_index(maps, map)?)?.layer_by_name(layer)?; + let (map, env) = frame_page_env(layout, maps, *frame).ok()??; + let shown = map.layer_by_name(layer)?; let ds = &shown.dataset; // At least a pixel each way, as the page draws it. let r = Rect::from_xywh((e.x * k) as f32, (e.y * k) as f32, ((e.w * k) as f32).max(1.0), ((e.h * k) as f32).max(1.0))?; let listed = TableRows { sort: sort.as_deref(), descending: *descending, selected_only: *selected_only }; let look = TableLook { rows: *rows, fields, text_size: *text_size, header: *header, listed }; - let listable = table_listing(shown, listed).count(); + let listable = table_listing(shown, listed, &env).count(); let fit = table_fit(r, look, ds.fields.len(), listable, ppp); let asked = asked_columns(look, ds.fields.len()); let shown_rows = (fit.rows, (*rows).min(listable)); @@ -166,10 +167,10 @@ fn table_cut_notice(found: &[TableCut]) -> Option { /// with an `ink` (#2257) in it on no paper of its own, its header and stripes a tint of the ink, so /// it reads on whatever is behind it (a dark page, or the element's background). A column whose /// field the layer hasn't (removed or renamed since) keeps its name, its cells a dash. -pub(super) fn table(pm: &mut Canvas, r: Rect, layer: &rustgis_map::Layer, look: TableLook, ink: Option, ppp: f64) { +pub(super) fn table(pm: &mut Canvas, r: Rect, (layer, env): (&rustgis_map::Layer, &Env), look: TableLook, ink: Option, ppp: f64) { let ppp = ppp as f32; let ds = &layer.dataset; - let listing = table_listing(layer, look.listed); + let listing = table_listing(layer, look.listed, env); let TableFit { pt, px, row_h, col_w, cols, rows: n } = table_fit(r, look, ds.fields.len(), listing.count(), ppp); // Each column shown: its field's place in the layer, and its heading. let columns: Vec<(Option, &str)> = if look.fields.is_empty() { diff --git a/crates/render/src/layout/tests.rs b/crates/render/src/layout/tests.rs index 772dfa2601..ebbeed5b2e 100644 --- a/crates/render/src/layout/tests.rs +++ b/crates/render/src/layout/tests.rs @@ -779,8 +779,8 @@ fn an_ink_colours_legends_colorbars_tables_and_charts() { // row's empty right end, (175, 8) in the header's. let look = TableLook { rows: 5, fields: &[], text_size: 8.0, header: true, listed: Default::default() }; let layer = rustgis_map::Layer::new(1, ds.clone()); - let plain = draw(&|c| table(c, r, &layer, look, None, 1.0)); - let inked = draw(&|c| table(c, r, &layer, look, Some(red), 1.0)); + let plain = draw(&|c| table(c, r, (&layer, &Default::default()), look, None, 1.0)); + let inked = draw(&|c| table(c, r, (&layer, &Default::default()), look, Some(red), 1.0)); assert!(!reddish(&plain) && reddish(&inked)); let at = |c: &Canvas, x, y| c.pixmap().pixel(x, y).unwrap(); assert_eq!((at(&plain, 175, 25).red(), at(&plain, 175, 25).alpha()), (255, 255), "white cells without an ink"); @@ -803,7 +803,7 @@ fn a_table_draws_its_fields_at_its_size_headed_or_not() { let fields: Vec = fields.iter().map(|f| (*f).to_string()).collect(); let mut c = Canvas::new(300, 120).unwrap(); let look = TableLook { rows: 20, fields: &fields, text_size, header, listed: Default::default() }; - table(&mut c, r, &rustgis_map::Layer::new(1, ds.clone()), look, None, 1.0); + table(&mut c, r, (&rustgis_map::Layer::new(1, ds.clone()), &Default::default()), look, None, 1.0); c.pixmap().data().to_vec() }; // The white paper's right and bottom ends, from the pixels painted. @@ -861,7 +861,14 @@ fn a_table_draws_its_rows_sorted_and_selected() { let r = Rect::from_xywh(0.0, 0.0, 120.0, 120.0).unwrap(); let draw = |layer: &rustgis_map::Layer, listed: TableRows| { let mut c = Canvas::new(120, 120).unwrap(); - table(&mut c, r, layer, TableLook { rows: 20, fields: &[], text_size: 8.0, header: true, listed }, None, 1.0); + table( + &mut c, + r, + (layer, &Default::default()), + TableLook { rows: 20, fields: &[], text_size: 8.0, header: true, listed }, + None, + 1.0, + ); c.pixmap().data().to_vec() }; let mut layer = places(&[30, 10, 40, 20]); @@ -9482,7 +9489,7 @@ fn a_tables_fit_is_what_it_draws() { let fit = table_fit(r, look, ds.fields.len(), ds.features.len(), ppp); assert_eq!((fit.cols, fit.rows), (2, if header { 6 } else { 7 }), "{ppp} {header}"); let mut c = Canvas::new(w, h).unwrap(); - table(&mut c, r, &rustgis_map::Layer::new(1, ds.clone()), look, None, f64::from(ppp)); + table(&mut c, r, (&rustgis_map::Layer::new(1, ds.clone()), &Default::default()), look, None, f64::from(ppp)); // The white paper's right and bottom ends: two columns of 90, and its rows of 17.024. let painted = c.pixmap().pixels().iter().enumerate().filter(|(_, p)| p.alpha() > 0); let (right, bottom) = painted.fold((0, 0), |(x, y), (i, _)| (x.max(i as u32 % w + 1), y.max(i as u32 / w + 1))); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 02318123cc..c954800c1c 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -926,9 +926,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu give it a **Background** for a box. From a command: `layout.update={"element":5,"color":"#FFFFFF"}`, and `"color":null` for the default; `layout.addElement` takes it too. -- **Table frame**: a layer's attribute table. Its properties set the **Rows** (1 to 500), the - **Text size** (4 to 100 points, 8 unless set; rows and columns follow it) and the **Header**, the - row of field names. It shows the layer's fields in their order, as many as its box holds. The +- **Table frame**: a layer's attribute table, of the features its definition query keeps on the page + (display filters and the time window don't narrow it). Its properties set the **Rows** (1 to 500), + the **Text size** (4 to 100 points, 8 unless set; rows and columns follow it) and the **Header**, + the row of field names. It shows the layer's fields in their order, as many as its box holds. The **Columns** section below picks which and their order: tick or untick each field, and move a ticked one with ▲ and ▼, each one undo step. Ticked fields are listed first, as drawn, and a field ticked goes after them. **Select All** and **Select None** tick or untick every field @@ -951,9 +952,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu to the table's box or to what it lists says so, as an export and a report do. When its box doesn't hold the rows and columns it is asked to show, adding or changing the table says how many it shows, and so does an export or a report. -- **Chart frame**: a bar chart of a layer of the frame's map. Its properties pick the **Layer** - and the numeric **Field**, and by default draw a bar per feature, the largest first, each - labelled by the **Label** field. **Group by** a field draws a bar per value of that field +- **Chart frame**: a bar chart of a layer of the frame's map, of the features its definition query + keeps on the page (display filters and the time window don't narrow it). Its properties pick the + **Layer** and the numeric **Field**, and by default draw a bar per feature, the largest first, + each labelled by the **Label** field. **Group by** a field draws a bar per value of that field instead, its **Statistic** of the field over that value's features: sum, count (features, numbers or not, so a count can chart a text field), mean, minimum or maximum. Values are grouped as they are stored, capitals and spaces included: "North" and "north " are two bars. From 6d23ac6fe28f04bcf136f00b446eecdd5b89e52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 13:06:51 -0500 Subject: [PATCH 2/4] fix(layout): count one table's cut on a change, and leave one chart reader (#3478) --- crates/engine/src/cmd/layout/elements.rs | 5 +- crates/map/src/layout/chart.rs | 6 +-- crates/map/src/layout/elements.rs | 55 +++++++++++----------- crates/render/src/layout.rs | 2 +- crates/render/src/layout/chart.rs | 2 +- crates/render/src/layout/table.rs | 60 +++++++++++++++--------- crates/render/src/layout/tests.rs | 39 +++++++++++++-- 7 files changed, 106 insertions(+), 63 deletions(-) diff --git a/crates/engine/src/cmd/layout/elements.rs b/crates/engine/src/cmd/layout/elements.rs index d46b0affa5..4b2ed7a8b4 100644 --- a/crates/engine/src/cmd/layout/elements.rs +++ b/crates/engine/src/cmd/layout/elements.rs @@ -320,9 +320,8 @@ pub(in crate::cmd::layout) fn say_table_cut(s: &mut Session, li: usize, id: u32) let Some(l) = s.project.layouts.get(li) else { return }; // The counts don't depend on the resolution: the box, its columns and its rows scale with it. // Nothing is drawn here, so a layer read in place counts the rows it holds now. - let mut cut = rustgis_render::layout::tables_cut(l, &s.project.maps, 300.0); - cut.retain(|t| t.id == id); - for note in rustgis_render::layout::table_notices(&cut) { + let cut = rustgis_render::layout::table_cut(l, id, &s.project.maps, 300.0); + for note in rustgis_render::layout::table_notices(cut.as_slice()) { s.warn(note); } } diff --git a/crates/map/src/layout/chart.rs b/crates/map/src/layout/chart.rs index 31df7bdd92..e81b605413 100644 --- a/crates/map/src/layout/chart.rs +++ b/crates/map/src/layout/chart.rs @@ -235,7 +235,7 @@ impl Shade { } /// The values of a field a chart groups or stacks its bars by, each numbered as it first comes -/// ([`ElementKind::chart_data`]). Each name is held once, in `index`; a text is looked up as it +/// ([`ElementKind::chart_data_of`]). Each name is held once, in `index`; a text is looked up as it /// is, and only a new value's name is copied. A number or a yes/no is looked up by its value in /// `by_value` first, so it is written out once per value, not per feature: a value first seen goes /// through `index` by its name, so values written alike (3 and 3.0) stay one. No value, or only @@ -326,7 +326,7 @@ pub(super) fn add_cell( s.merge(shade); } -/// A stacked chart's key and stretches ([`ElementKind::chart_data`]) from the total of each pair of +/// A stacked chart's key and stretches ([`ElementKind::chart_data_of`]) from the total of each pair of /// a group value and a stack value (`cells`), the bar each group is drawn in (`bar_of`, an Other /// bar's groups all in the last of `bars`) and the stack values' names; `coloured`, each pair's /// colour gives a value the one its features share over the bars shown. The key holds the values @@ -405,7 +405,7 @@ pub(super) fn stack_bars( (key, stretches, kept, gathered, whole) } -/// A chart's group value looked up by itself rather than by its name ([`ElementKind::chart_data`]): +/// A chart's group value looked up by itself rather than by its name ([`ElementKind::chart_data_of`]): /// a whole number, a number's bits, or a yes/no. The same key is always written alike, so a bar /// found by it is the bar of that name. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/map/src/layout/elements.rs b/crates/map/src/layout/elements.rs index 68a155c31a..b4c67d1566 100644 --- a/crates/map/src/layout/elements.rs +++ b/crates/map/src/layout/elements.rs @@ -332,7 +332,7 @@ pub enum ElementKind { selected_only: bool, }, /// A bar chart of a numeric field of a layer in a frame's map: one bar per feature, or one - /// per value of a `group` field ([`ElementKind::chart_data`], #2487). + /// per value of a `group` field ([`ElementKind::chart_data_of`], #2487). Chart { frame: u32, layer: String, @@ -1005,12 +1005,18 @@ impl ElementKind { if group.is_some() || *statistic != StatKind::default() || *order != ChartOrder::default() || *bars != CHART_BARS || *other) } - /// The bars a chart draws from `ds`, its layer's features (#2487); `None` for another kind, or - /// when its field or group field isn't in `ds`. Ungrouped, a bar per feature with a number in - /// its field; grouped, a bar per value of the group field ([`CHART_BLANK`] for none), its - /// statistic of the field over that value's features. Ordered, then cut to its limit, the - /// bars past it left out or gathered in a last [`CHART_OTHER`] bar, the statistic over their - /// features (their sum, ungrouped), whatever the order. + /// [`ElementKind::chart_data_of`]'s bars of every row of `ds`, without colours, for tests. + #[cfg(test)] + pub(super) fn chart_data(&self, ds: &rustgis_data::Dataset) -> Option { + self.chart_data_with(ds, None, None) + } + + /// The bars a chart draws of `layer`'s features (#2487); `None` for another kind, or when its field + /// or group field isn't in `layer`. Ungrouped, a bar per feature with a number in its field; + /// grouped, a bar per value of the group field ([`CHART_BLANK`] for none), its statistic of the + /// field over that value's features. Ordered, then cut to its limit, the bars past it left out or + /// gathered in a last [`CHART_OTHER`] bar, the statistic over their features (their sum, + /// ungrouped), whatever the order. /// /// It holds a value and an index per feature with a number (16 bytes) ungrouped. Grouped, it /// holds a 48-byte tally and an index per value, with the value's name once: at most the @@ -1023,20 +1029,13 @@ impl ElementKind { /// It looks at Cancel every few thousand features, and a cancelled read is no data. Ordering /// the bars once they are read is one step, without a look. /// - /// It reads every row of `ds` and no colours ([`ChartData::colors`] stays empty): a layer's - /// chart is [`ElementKind::chart_data_of`], which keeps to the definition query and reads the - /// colours of a chart coloured by classes. - pub fn chart_data(&self, ds: &rustgis_data::Dataset) -> Option { - self.chart_data_with(ds, None, None) - } - - /// [`ElementKind::chart_data`] of the features of `layer` its definition query keeps in `env` - /// (#3478), the frame's scale and the series page, as the map frame draws them; the query's answer - /// is held while they are read, a byte a feature, and reading it is one step, without a look at - /// Cancel. A chart coloured by classes reads each feature's colour as the frame draws it - /// ([`crate::Layer::styler_with`]), by the feature's own geometry, the layer's where it has none - /// ([`crate::symbology::Symbol::shown_colour`]). A feature its symbol draws nothing of, in a hidden - /// class, has none. The layer's transparency isn't read: a bar is drawn whole. + /// The features are those its definition query keeps in `env` (#3478), the frame's scale and the + /// series page, as the map frame draws them; the query's answer is held while they are read, a + /// byte a feature, and reading it is one step, without a look at Cancel. A chart coloured by + /// classes reads each feature's colour as the frame draws it ([`crate::Layer::styler_with`]), by + /// the feature's own geometry, the layer's where it has none + /// ([`crate::symbology::Symbol::shown_colour`]). A feature its symbol draws nothing of, in a + /// hidden class, has none. The layer's transparency isn't read: a bar is drawn whole. pub fn chart_data_of(&self, layer: &crate::Layer, env: &rustgis_data::query::Env) -> Option { let ds = &layer.dataset; let kept = layer.query_rows_with(ds, env); @@ -1052,13 +1051,13 @@ impl ElementKind { self.chart_data_with(ds, kept, Some(&colour)) } - /// [`ElementKind::chart_data`] of the rows `kept` marks (all of them without it), each bar coloured - /// by `colour` (a feature row's colour, none for a feature drawn with nothing) when given: a bar - /// per feature its row's, a grouped bar the colour all the features its statistic reads share (a - /// count's every feature, another's those with a number), those drawn with nothing aside. A bar - /// without one keeps the chart's. Grouped, it holds a colour (5 bytes) per value besides, and reads - /// no more colours of a value once its features have two; each colour read is the feature's symbol, - /// as drawing the map reads it. + /// [`ElementKind::chart_data_of`] of the rows `kept` marks of `ds` (all of them without it), each + /// bar coloured by `colour` (a feature row's colour, none for a feature drawn with nothing) when + /// given: a bar per feature its row's, a grouped bar the colour all the features its statistic + /// reads share (a count's every feature, another's those with a number), those drawn with nothing + /// aside. A bar without one keeps the chart's. Grouped, it holds a colour (5 bytes) per value + /// besides, and reads no more colours of a value once its features have two; each colour read is + /// the feature's symbol, as drawing the map reads it. /// /// Stacked ([`ElementKind::chart_stack`]), the colours go to the values of the stack field /// instead: each one takes the colour all its features on the bars shown share, else its diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 61af7dc607..c7177a609e 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -51,7 +51,7 @@ pub use scale_bar::*; pub use section::*; use swatch::*; use table::*; -pub use table::{TableCut, table_notices, tables_cut}; +pub use table::{TableCut, table_cut, table_notices, tables_cut}; pub use textbox::*; /// Page values for dynamic text. diff --git a/crates/render/src/layout/chart.rs b/crates/render/src/layout/chart.rs index 504786068b..4238bb85a8 100644 --- a/crates/render/src/layout/chart.rs +++ b/crates/render/src/layout/chart.rs @@ -50,7 +50,7 @@ pub(super) fn drawn_chart(id: u32, data: &rustgis_map::layout::ChartData) { }); } -/// A bar chart of `data`'s bars ([`ElementKind::chart_data`]) drawn as `look` says, its title, +/// A bar chart of `data`'s bars ([`ElementKind::chart_data_of`]) drawn as `look` says, its title, /// labels and values in `dark`, its values with a decimal comma when `comma`. With a negative /// value, bars run either way from a zero line (#2487). Stacked, each bar is drawn as its /// stretches in the colours of the key under the title, those above zero from it on and those diff --git a/crates/render/src/layout/table.rs b/crates/render/src/layout/table.rs index 1dc207bd39..3c8c574419 100644 --- a/crates/render/src/layout/table.rs +++ b/crates/render/src/layout/table.rs @@ -71,32 +71,46 @@ impl TableCut { /// The tables of `layout` drawn at `dpi` whose boxes don't hold the rows and columns they are /// asked to show (#3416), or whose sort field is gone (#3409). A hidden table, one with none of /// its box on the page and one drawn as a placeholder (no frame, map or layer, or a series page -/// that can't be read) show nothing to count. +/// that can't be read) show nothing to count. Each table's layer has its definition query read +/// over it, once a call, besides the read that draws it: what an export or a report pays to say +/// them (#3478). pub fn tables_cut(layout: &Layout, maps: &[Map], dpi: f64) -> Vec { + layout.elements.iter().filter_map(|e| cut_of(layout, e, maps, dpi)).collect() +} + +/// [`tables_cut`] of the element `id` alone, reading no other table's layer: what a change to one +/// table says. +pub fn table_cut(layout: &Layout, id: u32, maps: &[Map], dpi: f64) -> Option { + cut_of(layout, layout.element(id)?, maps, dpi) +} + +/// What [`tables_cut`] says of the element `e` of `layout`; none when it isn't a table or has +/// nothing to say. +fn cut_of(layout: &Layout, e: &rustgis_map::layout::Element, maps: &[Map], dpi: f64) -> Option { + if !e.visible || !on_page(layout, e) { + return None; + } + let ElementKind::Table { frame, layer, rows, fields, text_size, header, sort, descending, selected_only, .. } = &e.kind else { + return None; + }; let k = page_geometry(layout, dpi).2; let ppp = (k / PT_PER_MM) as f32; - let cut = layout.elements.iter().filter(|e| e.visible && on_page(layout, e)).filter_map(|e| { - let ElementKind::Table { frame, layer, rows, fields, text_size, header, sort, descending, selected_only, .. } = &e.kind else { - return None; - }; - let (map, env) = frame_page_env(layout, maps, *frame).ok()??; - let shown = map.layer_by_name(layer)?; - let ds = &shown.dataset; - // At least a pixel each way, as the page draws it. - let r = Rect::from_xywh((e.x * k) as f32, (e.y * k) as f32, ((e.w * k) as f32).max(1.0), ((e.h * k) as f32).max(1.0))?; - let listed = TableRows { sort: sort.as_deref(), descending: *descending, selected_only: *selected_only }; - let look = TableLook { rows: *rows, fields, text_size: *text_size, header: *header, listed }; - let listable = table_listing(shown, listed, &env).count(); - let fit = table_fit(r, look, ds.fields.len(), listable, ppp); - let asked = asked_columns(look, ds.fields.len()); - let shown_rows = (fit.rows, (*rows).min(listable)); - let shown_cols = (fit.cols.min(asked), asked); - // Spelled as stored, as the rows are ordered. - let lost_sort = sort.as_ref().filter(|name| ds.fields.iter().all(|f| f.name != **name)).cloned(); - let table = TableCut { id: e.id, name: e.name.clone(), layout: None, rows: shown_rows, cols: shown_cols, lost_sort }; - (table.is_cut() || table.lost_sort.is_some()).then_some(table) - }); - cut.collect() + let (map, env) = frame_page_env(layout, maps, *frame).ok()??; + let shown = map.layer_by_name(layer)?; + let ds = &shown.dataset; + // At least a pixel each way, as the page draws it. + let r = Rect::from_xywh((e.x * k) as f32, (e.y * k) as f32, ((e.w * k) as f32).max(1.0), ((e.h * k) as f32).max(1.0))?; + let listed = TableRows { sort: sort.as_deref(), descending: *descending, selected_only: *selected_only }; + let look = TableLook { rows: *rows, fields, text_size: *text_size, header: *header, listed }; + let listable = table_listing(shown, listed, &env).count(); + let fit = table_fit(r, look, ds.fields.len(), listable, ppp); + let asked = asked_columns(look, ds.fields.len()); + let shown_rows = (fit.rows, (*rows).min(listable)); + let shown_cols = (fit.cols.min(asked), asked); + // Spelled as stored, as the rows are ordered. + let lost_sort = sort.as_ref().filter(|name| ds.fields.iter().all(|f| f.name != **name)).cloned(); + let table = TableCut { id: e.id, name: e.name.clone(), layout: None, rows: shown_rows, cols: shown_cols, lost_sort }; + (table.is_cut() || table.lost_sort.is_some()).then_some(table) } /// A table as a notice names it: by name and id, and in a report by its layout. diff --git a/crates/render/src/layout/tests.rs b/crates/render/src/layout/tests.rs index ebbeed5b2e..fa5dd0a6e7 100644 --- a/crates/render/src/layout/tests.rs +++ b/crates/render/src/layout/tests.rs @@ -43,6 +43,11 @@ fn measure_at(rows: &[LegendRow], columns: usize, at: (f64, f32)) -> (f32, f32) measured(rows, at, |m| measure(m, columns)) } +/// The bars `kind` draws of a layer holding `ds`. +fn bars_of(kind: &ElementKind, ds: &rustgis_data::Dataset) -> Option { + kind.chart_data_of(&rustgis_map::Layer::new(1, ds.clone()), &Default::default()) +} + /// A chart element of layer "t" on frame 1, with `extra` keys (its field among them). fn chart_kind(extra: serde_json::Value) -> ElementKind { let mut chart = serde_json::json!({"frame": 1, "layer": "t"}); @@ -120,7 +125,7 @@ fn a_chart_saved_before_draws_to_the_same_pixels() { }; let before = draw(&|c| chart_before(c, r, ds, "n", label, INK, ppp)); let kind = chart_kind(serde_json::json!({"field": "n", "label": label})); - let now = draw(&|c| match kind.chart_data(ds) { + let now = draw(&|c| match bars_of(&kind, ds) { Some(data) => chart(c, r, &data, &ChartLook::default(), INK, ppp, false), None => placeholder(c, r, "Chart", ppp), }); @@ -136,7 +141,7 @@ fn a_chart_with_a_negative_value_draws_from_a_zero_line() { for n in [3.0, -1.0] { ds.push(Some(Geometry::Point(Coord::new(0.0, 0.0))), vec![Value::Float(n)]); } - let data = chart_kind(serde_json::json!({"field": "n"})).chart_data(&ds).unwrap(); + let data = bars_of(&chart_kind(serde_json::json!({"field": "n"})), &ds).unwrap(); let mut c = Canvas::new(200, 120).unwrap(); let r = Rect::from_xywh(0.0, 0.0, 200.0, 120.0).unwrap(); chart(&mut c, r, &data, &ChartLook::default(), INK, 1.0, false); @@ -162,7 +167,7 @@ fn chart_drawn(vals: &[(f64, &str)], extra: serde_json::Value) -> Canvas { k.extend(e.clone()); } let kind = chart_kind(keys); - let data = kind.chart_data(&ds).unwrap(); + let data = bars_of(&kind, &ds).unwrap(); let mut c = Canvas::new(200, 120).unwrap(); let r = Rect::from_xywh(0.0, 0.0, 200.0, 120.0).unwrap(); chart(&mut c, r, &data, &kind.chart_look().unwrap(), INK, 1.0, false); @@ -772,7 +777,7 @@ fn an_ink_colours_legends_colorbars_tables_and_charts() { assert_eq!(reddish(&legend), expected, "legend {ink:?}"); assert_eq!(reddish(&draw(&|c| colorbar(c, r, &grey, &bar(ink), 1.0))), expected, "colorbar {ink:?}"); // Its bars keep their blue. - let data = chart_kind(serde_json::json!({"field": "n", "label": "name"})).chart_data(&ds).unwrap(); + let data = bars_of(&chart_kind(serde_json::json!({"field": "n", "label": "name"})), &ds).unwrap(); assert_eq!(reddish(&draw(&|c| chart(c, r, &data, &ChartLook::default(), ink, 1.0, false))), expected, "chart {ink:?}"); } // Two columns 90 px wide, a header and two rows 17 px high: (175, 25) is in the first @@ -845,6 +850,32 @@ fn a_table_draws_its_fields_at_its_size_headed_or_not() { assert_eq!(ends(&draw(&short, &["n"], 8.0, false)).1, 35, "two rows"); } +/// A change to one table counts it alone, as the whole page's count says it (#3478). +#[test] +fn one_tables_cut_is_its_own_of_the_pages() { + use rustgis_data::{Dataset, Field, FieldType, Geometry, Value}; + let mut ds = Dataset::new("t", GeometryType::Point, vec![Field::new("n", FieldType::Integer)]); + for n in 0..40 { + ds.push(Some(Geometry::Point(Coord::new(0.0, 0.0))), vec![Value::Int(n)]); + } + let mut map = Map::new("m"); + map.add_dataset(ds); + let mut layout = Layout::new("Page", 120.0, 90.0); + let frame = serde_json::json!({"MapFrame": {"map": "m", "center": {"x": 0, "y": 0}, "scale": 2000000}}); + let frame = layout.add("Frame", (0.0, 0.0, 50.0, 50.0), serde_json::from_value(frame).unwrap()); + let table = |rows| serde_json::from_value(serde_json::json!({"Table": {"frame": frame, "layer": "t", "rows": rows}})).unwrap(); + let cut = layout.add("Cut", (60.0, 0.0, 40.0, 11.0), table(30)); + let also = layout.add("Also", (60.0, 30.0, 40.0, 11.0), table(20)); + let fits = layout.add("Fits", (60.0, 60.0, 40.0, 30.0), table(1)); + let maps = [map]; + let all = tables_cut(&layout, &maps, 96.0); + assert_eq!(all.iter().map(|t| t.id).collect::>(), [cut, also]); + assert_eq!(table_cut(&layout, also, &maps, 96.0).as_ref(), all.get(1)); + for none in [fits, frame, 999] { + assert_eq!(table_cut(&layout, none, &maps, 96.0), None, "{none}"); + } +} + /// A table sorted, or of the selected features alone, draws those rows in that order, striped by /// their place in the table (#3409). #[test] From 869a33805e45e87d05c656dfcaf00aa4806efdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 13:16:43 -0500 Subject: [PATCH 3/4] docs(layout): say what reading a definition query costs and keeps (#3478) --- crates/engine/src/cmd/layout/elements.rs | 4 +++- crates/map/src/layout/elements.rs | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/layout/elements.rs b/crates/engine/src/cmd/layout/elements.rs index 4b2ed7a8b4..678803ff93 100644 --- a/crates/engine/src/cmd/layout/elements.rs +++ b/crates/engine/src/cmd/layout/elements.rs @@ -315,7 +315,9 @@ pub(in crate::cmd::layout) fn held_rows(p: &Value) -> Option { /// Says the rows and columns the box of the table `id` of layout `li` leaves out (#3416), and a /// sort field its layer no longer has (#3409), measured as [`super::text::text_fit_loss`] measures -/// a text; nothing of another element. +/// a text; nothing of another element. With a definition query on the table's layer, the count +/// reads it over every feature, once, on the command's thread and without a look at Cancel, as +/// drawing the table does on every draw of the page. pub(in crate::cmd::layout) fn say_table_cut(s: &mut Session, li: usize, id: u32) { let Some(l) = s.project.layouts.get(li) else { return }; // The counts don't depend on the resolution: the box, its columns and its rows scale with it. diff --git a/crates/map/src/layout/elements.rs b/crates/map/src/layout/elements.rs index b4c67d1566..2651bb532f 100644 --- a/crates/map/src/layout/elements.rs +++ b/crates/map/src/layout/elements.rs @@ -499,7 +499,8 @@ pub struct TableListing<'a> { /// What a table showing `look` lists from in `layer`, its definition query read in `env`, the /// map frame's scale and the series page (#3478). Reading the query over the layer's rows is one -/// step, without a look at Cancel, as the map frame reads it. +/// step, without a look at Cancel, as the map frame reads it. A query that doesn't read keeps every +/// row, as the map draws it; `layer.definitionQuery` refuses to set one. pub fn table_listing<'a>(layer: &'a crate::Layer, look: TableRows<'a>, env: &rustgis_data::query::Env) -> TableListing<'a> { let kept = layer.query_rows_with(&layer.dataset, env); let selected = look.selected_only.then(|| { @@ -1030,12 +1031,13 @@ impl ElementKind { /// the bars once they are read is one step, without a look. /// /// The features are those its definition query keeps in `env` (#3478), the frame's scale and the - /// series page, as the map frame draws them; the query's answer is held while they are read, a - /// byte a feature, and reading it is one step, without a look at Cancel. A chart coloured by - /// classes reads each feature's colour as the frame draws it ([`crate::Layer::styler_with`]), by - /// the feature's own geometry, the layer's where it has none - /// ([`crate::symbology::Symbol::shown_colour`]). A feature its symbol draws nothing of, in a - /// hidden class, has none. The layer's transparency isn't read: a bar is drawn whole. + /// series page, as the map frame draws them (all of them under a query that doesn't read, which + /// `layer.definitionQuery` refuses to set); the query's answer is held while they are read, a byte + /// a feature, and reading it is one step, without a look at Cancel. A chart coloured by classes + /// reads each feature's colour as the frame draws it ([`crate::Layer::styler_with`]), by the + /// feature's own geometry, the layer's where it has none + /// ([`crate::symbology::Symbol::shown_colour`]). A feature its symbol draws nothing of, in a hidden + /// class, has none. The layer's transparency isn't read: a bar is drawn whole. pub fn chart_data_of(&self, layer: &crate::Layer, env: &rustgis_data::query::Env) -> Option { let ds = &layer.dataset; let kept = layer.query_rows_with(ds, env); From c4063cb50b3e6c2f5cd17ff6d6d374efd3bc59a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 13:42:28 -0500 Subject: [PATCH 4/4] docs(layout): say when the definition query is read and what a table counts (#3478) --- crates/engine/src/cmd/layout/chart.rs | 16 ++++++++-------- crates/map/src/layout/elements.rs | 10 ++++++---- crates/render/src/layout/table.rs | 17 +++++++++-------- docs/user-guide/layouts.md | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/crates/engine/src/cmd/layout/chart.rs b/crates/engine/src/cmd/layout/chart.rs index dc40013040..6b9bc0a580 100644 --- a/crates/engine/src/cmd/layout/chart.rs +++ b/crates/engine/src/cmd/layout/chart.rs @@ -438,14 +438,14 @@ pub(in crate::cmd::layout) fn chart_update( Ok(Some((o, Some(to.name.clone()), said))) } -/// Says [`chart_notices`] of the chart `id` of layout `li`: what it leaves out of what it is told -/// to draw (an existing loss made said) and whether its box is too small for it. It reads each -/// feature of the chart's layer once, on the command's thread, as drawing the chart does on every -/// draw of the page: run when a chart is added, told what to draw or coloured by classes; resized -/// or restyled, it reads them too, for [`say_chart_crowded`] to say the last alone: whether the -/// box is too small depends on the bars, and the Layout view reads them on this thread as well -/// when it draws the edited page. An export -/// says [`chart_notices`] of what its pages drew. +/// Says [`chart_notices`] of the chart `id` of layout `li`: what it leaves out of what it is told to +/// draw (an existing loss made said) and whether its box is too small for it. It reads the chart's +/// layer, its definition query over every feature and then the features it keeps, on the command's +/// thread, as drawing the chart does on every draw of the page: run when a chart is added, told what to +/// draw or coloured by classes; resized or restyled, it reads them too, for [`say_chart_crowded`] to +/// say the last alone: whether the box is too small depends on the bars, and the Layout view reads them +/// on this thread as well when it draws the edited page. An export says [`chart_notices`] of what its +/// pages drew. pub(in crate::cmd::layout) fn say_chart_losses(s: &mut Session, li: usize, id: u32) { say_chart(s, li, id, false); } diff --git a/crates/map/src/layout/elements.rs b/crates/map/src/layout/elements.rs index 2651bb532f..1f7913f1e0 100644 --- a/crates/map/src/layout/elements.rs +++ b/crates/map/src/layout/elements.rs @@ -490,7 +490,7 @@ fn is_kept(kept: Option<&[bool]>, row: usize) -> bool { pub struct TableListing<'a> { layer: &'a crate::Layer, look: TableRows<'a>, - /// The definition query's answer, a byte a row; none when it keeps every row. + /// The definition query's answer, a byte a row; none when no query filters the rows. kept: Option>, /// The selected rows it keeps, each once, in the layer's order; none when not only those are /// listed. @@ -498,9 +498,11 @@ pub struct TableListing<'a> { } /// What a table showing `look` lists from in `layer`, its definition query read in `env`, the -/// map frame's scale and the series page (#3478). Reading the query over the layer's rows is one -/// step, without a look at Cancel, as the map frame reads it. A query that doesn't read keeps every -/// row, as the map draws it; `layer.definitionQuery` refuses to set one. +/// map frame's scale and the series page (#3478). Each call reads the query over every row of the +/// layer, in one step without a look at Cancel, as drawing the map frame reads a layer it draws: +/// every draw of the table and every count of its cut pays it, and nothing is kept between them. A +/// query that doesn't read keeps every row, as the map draws it; `layer.definitionQuery` refuses to +/// set one. pub fn table_listing<'a>(layer: &'a crate::Layer, look: TableRows<'a>, env: &rustgis_data::query::Env) -> TableListing<'a> { let kept = layer.query_rows_with(&layer.dataset, env); let selected = look.selected_only.then(|| { diff --git a/crates/render/src/layout/table.rs b/crates/render/src/layout/table.rs index 3c8c574419..05670afc3b 100644 --- a/crates/render/src/layout/table.rs +++ b/crates/render/src/layout/table.rs @@ -70,10 +70,10 @@ impl TableCut { /// The tables of `layout` drawn at `dpi` whose boxes don't hold the rows and columns they are /// asked to show (#3416), or whose sort field is gone (#3409). A hidden table, one with none of -/// its box on the page and one drawn as a placeholder (no frame, map or layer, or a series page -/// that can't be read) show nothing to count. Each table's layer has its definition query read -/// over it, once a call, besides the read that draws it: what an export or a report pays to say -/// them (#3478). +/// its box on the page and one drawn as a placeholder (no frame, map or layer) show nothing to +/// count, and no table is counted while the series index can't be read, as the page isn't drawn +/// then. Each table's layer has its definition query read over it, once a call, besides the read +/// that draws it: what an export or a report pays to say them (#3478). pub fn tables_cut(layout: &Layout, maps: &[Map], dpi: f64) -> Vec { layout.elements.iter().filter_map(|e| cut_of(layout, e, maps, dpi)).collect() } @@ -177,10 +177,11 @@ fn table_cut_notice(found: &[TableCut]) -> Option { } } -/// The rows of a table, with as many columns as fit: on white cells in dark grey, or -/// with an `ink` (#2257) in it on no paper of its own, its header and stripes a tint of the ink, so -/// it reads on whatever is behind it (a dark page, or the element's background). A column whose -/// field the layer hasn't (removed or renamed since) keeps its name, its cells a dash. +/// The rows of a table, those its layer's definition query keeps in `env`, with as many columns as fit: +/// on white cells in dark grey, or with an `ink` (#2257) in it on no paper of its own, its header and +/// stripes a tint of the ink, so it reads on whatever is behind it (a dark page, or the element's +/// background). A column whose field the layer hasn't (removed or renamed since) keeps its name, its +/// cells a dash. pub(super) fn table(pm: &mut Canvas, r: Rect, (layer, env): (&rustgis_map::Layer, &Env), look: TableLook, ink: Option, ppp: f64) { let ppp = ppp as f32; let ds = &layer.dataset; diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index c954800c1c..d943b2ab51 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -945,7 +945,7 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu numbers by value, dates by instant, text ignoring case (then by case), equal values in the layer's order; in a field holding several kinds of value, yes or no come first, then numbers, dates and text. **Descending** turns it round. **Selected only** lists the layer's selected - features, and no rows while none is selected. From a command: + features that the query keeps, and no rows while none is selected. From a command: `layout.update={"element":6,"sort":"POP","descending":true,"selectedOnly":false}`, `"sort":null` returning to the layer's order; another layer without a sort of its own drops it. A sort field removed or renamed afterwards is kept by name and its rows come in the layer's order; a change