Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/assistant/skills/print-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ description: Make a printable page layout — map frame, title, legend, north ar
labels' size) and `"fit"` (`"adjustDivisionValue"`, `"adjustDivision"`, `"adjustWidth"`). A `"legend"` can take
`"columns"` (1–6), `"fit"` (`"manual"`, `"adjustSize"`, `"adjustColumns"`, `"adjustColumnsAndSize"`: shrink its
text or add columns to fit its box), `"showCounts": true` (each class row ends in its number of features; none for a layer read from a database, over the web or a view at a time from other files),
`"showLayerNames": false` and `"classLabels"` (`{"<layer>": {"<class label>": "<text>"}}`: its own text for a
`"showLayerNames": false`, `"layerOrder": ["<layer>"]` (those layers first, the map unchanged) and `"classLabels"` (`{"<layer>": {"<class label>": "<text>"}}`: its own text for a
class, the layer keeping its label).
A `"text"` or `"dynamicText"` can take
`"valign"` (`"top"`, `"middle"`, `"bottom"`), `"lineSpacing"` (0.5–3, default 1) and `"case"`
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ layer.transparency layer? value
layer.visibility layer? visible?
layer.zoomTo layer?
layout.activate name layout
layout.addElement layout? kind frame? of? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? valign? lineSpacing? case? font? fallback? title? allClasses? hideOther? showNoData? exclude? columns? textSize? classLabels? showCounts? showLayerNames? orientation? ticks? tickSide? reverse? fill? width? radius? dash? dir? head? angle? length? image? path? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? hideLabels? barOutline? rows? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? name? direction? at? outline? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? x? y? w? h? background?
layout.addElement layout? kind frame? of? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? valign? lineSpacing? case? font? fallback? title? allClasses? hideOther? showNoData? exclude? layerOrder? columns? textSize? classLabels? showCounts? showLayerNames? orientation? ticks? tickSide? reverse? fill? width? radius? dash? dir? head? angle? length? image? path? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? hideLabels? barOutline? rows? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? name? direction? at? outline? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? x? y? w? h? background?
layout.addFrame layout? shape? points? map? x? y? w? h?
layout.arrange layout? element to
layout.arrangement favourite? save? arrangement? remove?
Expand All @@ -304,7 +304,7 @@ layout.save layout? path
layout.series layout? layer nameField? frame? margin? off?
layout.seriesPage layout? page
layout.seriesRefresh layout?
layout.update layout? element x? y? w? h? name? visible? locked? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? valign? lineSpacing? case? font? fallback? title? allClasses? hideOther? showNoData? exclude? labels? classLabels? columns? textSize? showLayerNames? showCounts? orientation? ticks? tickSide? reverse? style? fill? outline? radius? width? dash? dir? head? angle? length? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? map? scale? center? bearing? pitch? grid? extentIndicator? border? section? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? barOutline? hideLabels? rows? background?
layout.update layout? element x? y? w? h? name? visible? locked? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? valign? lineSpacing? case? font? fallback? title? allClasses? hideOther? showNoData? exclude? layerOrder? labels? classLabels? columns? textSize? showLayerNames? showCounts? orientation? ticks? tickSide? reverse? style? fill? outline? radius? width? dash? dir? head? angle? length? units? divisions? subdivisions? divisionsBeforeZero? labelPosition? unitLabel? unitLabelPosition? fit? map? scale? center? bearing? pitch? grid? extentIndicator? border? section? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? barOutline? hideLabels? rows? background?
locator.find locator? text limit? zoom?
map.activate name
map.addTiles url kind? name? bounds? attribution? minZoom? maxZoom? tileSize? singleImage? tms? subdomains? layers? styleLayers? opacity? blend? resampling? overlay? top? replace? id? view? start? end? unit? interval? dates? legend? connection?
Expand Down
31 changes: 17 additions & 14 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7309,7 +7309,15 @@ fn add_sample(s: &mut Session, p: &Value) -> CmdResult {
Ok(json!({"layer": id}))
}

/// Legends that leave out or label layer `old` of the active map, in the frames that show it,
/// Gives `old` its new name `new` in a legend's list of layer names, each once, should the new
/// name have been listed already.
fn rename_listed(names: &mut Vec<String>, old: &str, new: &str) {
names.iter_mut().filter(|x| x.eq_ignore_ascii_case(old)).for_each(|x| *x = new.to_string());
let mut seen = std::collections::HashSet::new();
names.retain(|x| seen.insert(x.to_ascii_lowercase()));
}

/// Legends that leave out, order or label layer `old` of the active map, in the frames that show it,
/// follow it: to its new name, or (`None`, the layer deleted) by dropping it, so a later layer of
/// that name isn't left out or labelled unasked. Called once the layer is renamed or gone: while
/// another layer still bears `old` (names may repeat), the legends keep it for that one. Renamed
Expand All @@ -7335,7 +7343,7 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str>
.map(|e| e.id)
.collect();
for e in &mut layout.elements {
if let rustgis_map::layout::ElementKind::Legend { frame, exclude, labels, class_labels, .. } = &mut e.kind
if let rustgis_map::layout::ElementKind::Legend { frame, exclude, layer_order, labels, class_labels, .. } = &mut e.kind
&& frames.contains(frame)
{
// Its label (#1654), taken off the old name; onto the new one unless another layer
Expand Down Expand Up @@ -7367,20 +7375,15 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str>
Some(n) if shared && !exclude.iter().any(|x| x.eq_ignore_ascii_case(n)) => {
exclude.retain(|x| !x.eq_ignore_ascii_case(old));
}
Some(n) => {
exclude.iter_mut().filter(|x| x.eq_ignore_ascii_case(old)).for_each(|x| *x = n.to_string());
// Once each, should the new name have been left out already.
let mut seen: Vec<String> = Vec::new();
exclude.retain(|x| {
let first = !seen.iter().any(|y| y.eq_ignore_ascii_case(x));
if first {
seen.push(x.clone());
}
first
});
}
Some(n) => rename_listed(exclude, old, n),
None => exclude.retain(|x| !x.eq_ignore_ascii_case(old)),
}
// Its place in the legend's order (#3279) goes with it; onto a name already
// there, the layers sharing it go together at the first of the two.
match new {
Some(n) => rename_listed(layer_order, old, n),
None => layer_order.retain(|x| !x.eq_ignore_ascii_case(old)),
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub fn commands() -> Vec<C> {
r##""hideOther"?: bool (legend: leave out <all other values>), "##,
r##""showNoData"?: bool (legend: include Graduated Colors’ missing-value symbol; default false), "##,
r##""exclude"?: [layer names] (legend: layers it leaves out though the map draws them), "##,
r##""layerOrder"?: [layer names] (legend: these layers first, in this order, the others after them as the map draws them; the map is not changed), "##,
r##""columns"?: 1..6 (legend: the columns its rows are laid in; default 1; with a fit that adds columns, the fewest it starts from), "##,
r##""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), "##,
r##""classLabels"?: {"<layer>": {"<class label>": "<text>"}} (legend: its own text for a class, by the label the layer shows for it, up to 200 characters; the layer keeps its label; a layer or class it can't find is refused), "##,
Expand Down Expand Up @@ -306,6 +307,7 @@ pub fn commands() -> Vec<C> {
r##""hideOther"?: bool (legend), "##,
r##""showNoData"?: bool (legend; default false), "##,
r##""exclude"?: [layer names] (legend; [] lists every layer again), "##,
r##""layerOrder"?: [layer names] (legend, as in layout.addElement; [] returns to the map's order), "##,
r##""labels"?: {"<layer>": "<label>"|null} (legend: what it shows instead of a layer's name, up to 200 characters, a longer one is refused; each entry replaces that layer's label, null or "" shows its name again, {} every layer's; a layer the map hasn't is refused), "##,
r##""classLabels"?: {"<layer>": {"<class label>": "<text>"|null}|null} (legend, as in layout.addElement; each entry replaces that class's text, null or "" shows the layer's label again, a layer's null or {} all of its classes', {} every layer's), "##,
r##""columns"?: 1..6 (legend), "##,
Expand Down Expand Up @@ -600,6 +602,7 @@ pub(crate) fn new_layout(s: &mut Session, p: &Value) -> CmdResult {
hide_other: false,
show_no_data: false,
exclude: Vec::new(),
layer_order: Vec::new(),
columns: 1,
labels: Default::default(),
color: None,
Expand Down
8 changes: 7 additions & 1 deletion crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
if kind != "legend" && p.get("exclude").is_some_and(|v| !v.is_null()) {
return Err("only legends leave layers out".into());
}
if kind != "legend" && gives(p, "layerOrder") {
return Err(ONLY_LEGEND_ORDER.into());
}
if kind != "legend" && p.get("columns").is_some_and(|v| !v.is_null()) {
return Err(ONLY_LEGEND_COLUMNS.into());
}
Expand Down Expand Up @@ -392,6 +395,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
let hide_other = b(p, "hideOther").unwrap_or(false);
let show_no_data = b(p, "showNoData").unwrap_or(false);
let exclude = legend_exclude(s, l, frame, p)?.unwrap_or_default();
let layer_order = legend_layer_order(s, l, frame, p)?.unwrap_or_default();
let columns = legend_columns_param(p)?.unwrap_or(1);
let labels = match legend_labels(s, l, frame, p)? {
Some(given) => with_labels(&BTreeMap::new(), given)?,
Expand All @@ -416,6 +420,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
hide_other,
show_no_data,
exclude,
layer_order,
columns,
labels,
color: ink,
Expand Down Expand Up @@ -985,6 +990,7 @@ const ADD_LEGEND_KEYS: &[&str] = &[
"hideOther",
"showNoData",
"exclude",
"layerOrder",
"columns",
"labels",
"classLabels",
Expand Down Expand Up @@ -1476,7 +1482,7 @@ mod tests {
let calls = [
json!({"kind": "northArrow", "layout": 0, "frame": frame, "x": 10, "y": 10, "w": 15, "h": 20, "style": "compass", "fill": "#112233", "outline": "#445566", "background": {"fill": "#FFFFFF"}}),
json!({"kind": "scaleBar", "frame": frame, "x": 10, "y": 10, "w": 60, "h": 12, "style": "stepped", "units": "miles", "divisions": 3, "subdivisions": 2, "divisionsBeforeZero": 1, "labelPosition": "below", "unitLabel": "mi", "unitLabelPosition": "afterBar", "fit": "adjustWidth", "decimals": 1, "textSize": 9, "color": "#112233", "fill": "#FFFFFF"}),
json!({"kind": "legend", "frame": frame, "title": "T", "allClasses": true, "hideOther": true, "showNoData": true, "exclude": [], "columns": 2, "labels": {}, "textSize": 8, "fit": "adjustSize", "showLayerNames": false, "showCounts": true, "color": "#112233"}),
json!({"kind": "legend", "frame": frame, "title": "T", "allClasses": true, "hideOther": true, "showNoData": true, "exclude": [], "layerOrder": [], "columns": 2, "labels": {}, "textSize": 8, "fit": "adjustSize", "showLayerNames": false, "showCounts": true, "color": "#112233"}),
json!({"kind": "colorbar", "frame": frame, "title": "T", "orientation": "vertical", "ticks": 3, "tickSide": "left", "reverse": true, "color": "#112233"}),
json!({"kind": "text", "text": "A", "size": 14, "color": "#112233", "bold": true, "italic": true, "align": "center", "letterSpacing": 1, "font": "Some Family", "fallback": "serif", "rotation": 90, "wrap": true, "valign": "middle", "lineSpacing": 1.5, "case": "upper", "name": "ignored"}),
json!({"kind": "dynamicText", "text": "{map}", "size": 10}),
Expand Down
25 changes: 17 additions & 8 deletions crates/engine/src/cmd/layout/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub(in crate::cmd::layout) fn element_inputs(input: &crate::cmd::InputContext<'_
let frame = frame_of(layout, p)?;
if kind == "legend"
&& legend_exclude(input, layout, frame, p)?.is_none()
&& legend_layer_order(input, layout, frame, p)?.is_none()
&& legend_labels(input, layout, frame, p)?.is_none()
&& legend_class_labels(input, layout, frame, p)?.is_none()
{
Expand All @@ -111,7 +112,8 @@ pub(in crate::cmd::layout) fn element_inputs(input: &crate::cmd::InputContext<'_
}
} else {
let (names, labels) = (legend_exclude(input, layout, frame, p)?, legend_labels(input, layout, frame, p)?);
legend_inputs(&mut inputs, map, names, labels, legend_class_labels(input, layout, frame, p)?);
let order = legend_layer_order(input, layout, frame, p)?;
legend_inputs(&mut inputs, map, names, order, labels, legend_class_labels(input, layout, frame, p)?);
}
inputs.maps.push(map.instance_id());
inputs.state = json!({"layout":index(input,p)?,"frame":frame,"selectors":inputs.state});
Expand Down Expand Up @@ -225,8 +227,9 @@ pub(in crate::cmd::layout) fn update_inputs(input: &crate::cmd::InputContext<'_>
Some(ElementKind::Legend { frame, .. }) => {
let (names, labels) = (legend_exclude(input, l, *frame, p)?, legend_labels(input, l, *frame, p)?);
let classes = legend_class_labels(input, l, *frame, p)?;
if names.is_some() || labels.is_some() || classes.is_some() {
legend_inputs(&mut inputs, frame_map(input, l, *frame)?, names, labels, classes);
let order = legend_layer_order(input, l, *frame, p)?;
if names.is_some() || order.is_some() || labels.is_some() || classes.is_some() {
legend_inputs(&mut inputs, frame_map(input, l, *frame)?, names, order, labels, classes);
}
}
_ => {}
Expand All @@ -235,18 +238,24 @@ pub(in crate::cmd::layout) fn update_inputs(input: &crate::cmd::InputContext<'_>
Ok(inputs)
}

/// The layers a legend's `exclude`, `labels` and `classLabels` name, as inputs. Tile layers' names are stored
/// The layers a legend's `exclude`, `layerOrder`, `labels` and `classLabels` name, as inputs. Tile layers' names are stored
/// selector text, not invented layer/table identities.
pub(in crate::cmd::layout) fn legend_inputs(
inputs: &mut crate::cmd::Inputs,
map: &Map,
names: Option<Vec<String>>,
order: Option<Vec<String>>,
labels: Option<Vec<(String, Option<String>)>>,
classes: Option<GivenClassLabels>,
) {
let named = names.iter().flatten().chain(labels.iter().flatten().map(|(n, _)| n)).chain(classes.iter().flatten().map(|(n, _)| n));
let named = names
.iter()
.flatten()
.chain(order.iter().flatten())
.chain(labels.iter().flatten().map(|(n, _)| n))
.chain(classes.iter().flatten().map(|(n, _)| n));
inputs.layers.extend(named.filter_map(|n| map.layer_by_name(n)).map(|l| (map.instance_id(), l.id)));
inputs.state = json!({"exclude": names, "labels": labels, "classLabels": classes});
inputs.state = json!({"exclude": names, "layerOrder": order, "labels": labels, "classLabels": classes});
}

/// Reference-only operations bind the actual chosen layout, without reading its stored maps.
Expand Down Expand Up @@ -278,8 +287,8 @@ pub(in crate::cmd::layout) fn element_selectors(kind: &ElementKind) -> Option<Va
ElementKind::Chart { frame, layer, field, label, group, stack, .. } => {
json!({"frame":frame,"layer":layer,"field":field,"label":label,"group":group,"stack":stack})
}
ElementKind::Legend { frame, exclude, labels, class_labels, .. } => {
json!({"frame":frame,"exclude":exclude,"labels":labels,"classLabels":class_labels})
ElementKind::Legend { frame, exclude, layer_order, labels, class_labels, .. } => {
json!({"frame":frame,"exclude":exclude,"layerOrder":layer_order,"labels":labels,"classLabels":class_labels})
}
ElementKind::Colorbar { frame, layer, .. } => json!({"frame":frame,"layer":layer}),
ElementKind::NorthArrow { frame, .. } | ElementKind::ScaleBar { frame, .. } => json!({"frame":frame}),
Expand Down
Loading
Loading