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
4 changes: 3 additions & 1 deletion crates/assistant/skills/print-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ description: Make a printable page layout — map frame, title, legend, north ar
(`"auto"`, the default, or 0–3 fixed with the thousands set apart, as a chart's), `"textSize"` (4–100 pt, its
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) and `"showLayerNames": false`. A `"text"` or `"dynamicText"` can take
text or add columns to fit its box), `"showLayerNames": false` 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"`
(`"none"`, `"upper"`, `"lower"`; applied when drawn, the text kept as typed). `"grid"` adds a graticule to the frame
(`"style": "ticks"` for neatline ticks, `"format": "dms"`, `"edges"`).
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? 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? columns? textSize? classLabels? 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? columns? textSize? showLayerNames? 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? labels? classLabels? columns? textSize? showLayerNames? 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
21 changes: 19 additions & 2 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7326,7 +7326,7 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str>
}
let shared = new.is_some_and(|n| named(s, n) > 1);
let map = s.map().name.clone();
let mut unlabelled = 0usize;
let (mut unlabelled, mut unclassed) = (0usize, 0usize);
for layout in &mut s.project.layouts {
let frames: Vec<u32> = layout
.elements
Expand All @@ -7335,7 +7335,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, .. } = &mut e.kind
if let rustgis_map::layout::ElementKind::Legend { frame, exclude, 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 All @@ -7350,6 +7350,17 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str>
(Some(_), Some(_), true) => unlabelled += 1,
_ => {}
}
// Its classes' labels (#3187) go the same way.
let keys: Vec<String> = class_labels.by_layer.keys().filter(|n| n.eq_ignore_ascii_case(old)).cloned().collect();
let classes = keys.iter().filter_map(|k| class_labels.by_layer.remove(k)).last();
match (new, classes, shared) {
(Some(n), Some(c), false) => {
class_labels.by_layer.retain(|x, _| !x.eq_ignore_ascii_case(n));
class_labels.by_layer.insert(n.to_string(), c);
}
(Some(_), Some(_), true) => unclassed += 1,
_ => {}
}
match new {
// Another layer the legend lists bears the new name: carrying the exclusion
// over would take that one out too, so the renamed layer is listed with it.
Expand All @@ -7373,6 +7384,12 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str>
}
}
}
if let Some(n) = new.filter(|_| unclassed > 0) {
s.notify(
format!("'{old}', renamed '{n}', lost its class labels in {unclassed} legend(s): another layer is called '{n}', and a legend labels layers by name"),
false,
);
}
// The text given for the layer goes while the layer stays: said. (A removed layer's goes
// with its row.)
if let Some(n) = new.filter(|_| unlabelled > 0) {
Expand Down
11 changes: 7 additions & 4 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::sync::LazyLock;

use rustgis_geom::{Coord, Extent};
use rustgis_map::layout::{
Arrange, ArrowStyle, Background, CHART_BAR, CHART_BARS, CHART_OUTLINE, ChartOrder, ChartOutline, CoordFormat, ElementKind, FontFamily,
FrameShape, GRID_LABEL_PT, Grid, GridEdges, GridKind, GridStyle, Guides, LAYOUT_TEXT_SIZE, LINE_SPACING, LayerNames, Layout, LegendFit,
LineDir, LineHead, MAX_CHART_BARS, MAX_CHART_DECIMALS, MAX_CHART_OUTLINE_WIDTH, MAX_COLORBAR_TICKS, MAX_GRID_WIDTH, MAX_GUIDES,
MAX_LEGEND_COLUMNS, MAX_LEGEND_LABEL_CHARS, MAX_LEGEND_LABELS, MAX_LINE_SPACING, MAX_SCALE_BEFORE_ZERO, MAX_SCALE_DECIMALS,
Arrange, ArrowStyle, Background, CHART_BAR, CHART_BARS, CHART_OUTLINE, ChartOrder, ChartOutline, ClassLabels, CoordFormat, ElementKind,
FontFamily, FrameShape, GRID_LABEL_PT, Grid, GridEdges, GridKind, GridStyle, Guides, LAYOUT_TEXT_SIZE, LINE_SPACING, LayerNames,
Layout, LegendFit, LineDir, LineHead, MAX_CHART_BARS, MAX_CHART_DECIMALS, MAX_CHART_OUTLINE_WIDTH, MAX_COLORBAR_TICKS, MAX_GRID_WIDTH,
MAX_GUIDES, MAX_LEGEND_COLUMNS, MAX_LEGEND_LABEL_CHARS, MAX_LEGEND_LABELS, MAX_LINE_SPACING, MAX_SCALE_BEFORE_ZERO, MAX_SCALE_DECIMALS,
MAX_SCALE_DIVISIONS, MAX_SCALE_SUBDIVISIONS, MAX_SECTIONS, MAX_TICK_MM, MAX_UNIT_LABEL_CHARS, MIN_ELEMENT_MM, MIN_LINE_SPACING,
MapSeries, Orientation, PAGES, SCALE_BAR_TEXT_PT, ScaleBarFit, ScaleBarStyle, ScaleLabelPosition, ScaleUnits, Section, SectionLine,
TextAlign, TextCase, TextVAlign, TickSide, UnitLabelPosition, fit_scale, line_angle, line_at_angle, line_length,
Expand Down Expand Up @@ -207,6 +207,7 @@ pub fn commands() -> Vec<C> {
r##""exclude"?: [layer names] (legend: layers it leaves out though the map draws them), "##,
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), "##,
r##""showLayerNames"?: bool (legend: the name over each layer's classes and over a web layer's legend picture; default true; a layer drawn in one symbol keeps its name; refused for other kinds), "##,
r##""orientation"?: "horizontal"|"vertical" (colorbar; chart: bars running across, the default, or columns standing up, each label centred under its column), "##,
r##""ticks"?: 2..21 (colorbar: labelled values, ends included), "##,
Expand Down Expand Up @@ -305,6 +306,7 @@ pub fn commands() -> Vec<C> {
r##""showNoData"?: bool (legend; default false), "##,
r##""exclude"?: [layer names] (legend; [] lists every layer again), "##,
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), "##,
r##""textSize"?: points, 4 to 100 (legend, scaleBar, as in layout.addElement, null giving each its default again; refused outside that range, and for other elements unless null), "##,
r##""showLayerNames"?: bool (legend, as in layout.addElement; null leaves it as it is), "##,
Expand Down Expand Up @@ -602,6 +604,7 @@ pub(crate) fn new_layout(s: &mut Session, p: &Value) -> CmdResult {
text_size: rustgis_map::layout::LEGEND_TEXT_PT,
fit: rustgis_map::layout::LegendFit::Manual,
show_layer_names: rustgis_map::layout::LayerNames::Shown,
class_labels: Default::default(),
},
);
l.add("North Arrow", (side + sw / 2.0 - 8.0, m + 16.0 + fh * 0.62, 16.0, 24.0), ElementKind::north_arrow(frame));
Expand Down
9 changes: 9 additions & 0 deletions crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
Some(_) if kind != "legend" && kind != "grid" => return Err(ONLY_LEGEND_LABELS.into()),
_ => {}
}
if kind != "legend" && gives(p, "classLabels") {
return Err(ONLY_LEGEND_CLASS_LABELS.into());
}
// A family is a text's: refused elsewhere, as a legend's left-out layers are, so a script
// doesn't take it as applied.
if !matches!(kind, "text" | "dynamicText") && gives_font(p) {
Expand Down Expand Up @@ -379,6 +382,10 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
Some(given) => with_labels(&BTreeMap::new(), given)?,
None => BTreeMap::new(),
};
let class_labels = match legend_class_labels(s, l, frame, p)? {
Some(given) => with_class_labels(&ClassLabels::default(), given)?,
None => ClassLabels::default(),
};
let text_size =
text_size_param(p, "textSize", rustgis_map::layout::LEGEND_TEXT_PT)?.unwrap_or(rustgis_map::layout::LEGEND_TEXT_PT);
let fit = legend_fit_param(p)?.unwrap_or_default();
Expand All @@ -399,6 +406,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
text_size,
fit,
show_layer_names,
class_labels,
},
)
}
Expand Down Expand Up @@ -958,6 +966,7 @@ const ADD_LEGEND_KEYS: &[&str] = &[
"exclude",
"columns",
"labels",
"classLabels",
"textSize",
"fit",
"showLayerNames",
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 @@ -91,7 +91,11 @@ pub(in crate::cmd::layout) fn element_inputs(input: &crate::cmd::InputContext<'_
}
let layout = s.project.layouts.get(index(input, p)?).ok_or("no layout")?;
let frame = frame_of(layout, p)?;
if kind == "legend" && legend_exclude(input, layout, frame, p)?.is_none() && legend_labels(input, layout, frame, p)?.is_none() {
if kind == "legend"
&& legend_exclude(input, layout, frame, p)?.is_none()
&& legend_labels(input, layout, frame, p)?.is_none()
&& legend_class_labels(input, layout, frame, p)?.is_none()
{
let mut inputs = object_inputs(input, p)?;
inputs.state["frame"] = json!(frame);
return Ok(inputs);
Expand All @@ -106,7 +110,8 @@ pub(in crate::cmd::layout) fn element_inputs(input: &crate::cmd::InputContext<'_
inputs.extend(crate::cmd::Inputs::named(map, [name.as_str()])?);
}
} else {
legend_inputs(&mut inputs, map, legend_exclude(input, layout, frame, p)?, legend_labels(input, layout, frame, p)?);
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)?);
}
inputs.maps.push(map.instance_id());
inputs.state = json!({"layout":index(input,p)?,"frame":frame,"selectors":inputs.state});
Expand Down Expand Up @@ -219,8 +224,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)?);
if names.is_some() || labels.is_some() {
legend_inputs(&mut inputs, frame_map(input, l, *frame)?, names, labels);
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);
}
}
_ => {}
Expand All @@ -229,17 +235,18 @@ pub(in crate::cmd::layout) fn update_inputs(input: &crate::cmd::InputContext<'_>
Ok(inputs)
}

/// The layers a legend's `exclude` and `labels` name, as inputs. Tile layers' names are stored
/// The layers a legend's `exclude`, `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>>,
labels: Option<Vec<(String, Option<String>)>>,
classes: Option<GivenClassLabels>,
) {
let named = names.iter().flatten().chain(labels.iter().flatten().map(|(n, _)| n));
let named = names.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});
inputs.state = json!({"exclude": names, "labels": labels, "classLabels": classes});
}

/// Reference-only operations bind the actual chosen layout, without reading its stored maps.
Expand Down Expand Up @@ -271,7 +278,9 @@ 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, .. } => json!({"frame":frame,"exclude":exclude,"labels":labels}),
ElementKind::Legend { frame, exclude, labels, class_labels, .. } => {
json!({"frame":frame,"exclude":exclude,"labels":labels,"classLabels":class_labels})
}
ElementKind::Colorbar { frame, layer, .. } => json!({"frame":frame,"layer":layer}),
ElementKind::NorthArrow { frame, .. } | ElementKind::ScaleBar { frame, .. } => json!({"frame":frame}),
_ => return None,
Expand Down
Loading
Loading