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), `"subtitle"` (one line under its title), `"sizes": "nested"` (a point layer's marker sizes one inside another on a common base), `"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`, `"layerOrder": ["<layer>"]` (those layers first, the map unchanged), `"columnBreaks": ["<layer>"]` (each starts a column; no `"columns"` above 1 beside them) and `"classLabels"` (`{"<layer>": {"<class label>": "<text>"}}`: its own text for a
`"showLayerNames": false`, `"layerOrder": ["<layer>"]` (those layers first, the map unchanged), `"columnBreaks": ["<layer>"]` (each starts a column; no `"columns"` above 1 beside them), `"oneRow": true` (every entry side by side in one row, however many; no `"columns"` above 1 or `"columnBreaks"` beside it) and `"classLabels"` (`{"<layer>": {"<class label>": "<text>"}}`: its own text for a
class, the layer keeping its label).
A `"picture"` takes a `"path"` (a PNG or JPEG file; it remembers the file) or an `"image"` (base64);
`layout.update` with `"path"` reads it again. A `"text"` or `"dynamicText"` can take
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 @@ -284,7 +284,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? subtitle? allClasses? hideOther? showNoData? exclude? layerOrder? columnBreaks? columns? textSize? classLabels? sizes? 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? fields? header? sort? descending? selectedOnly? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? name? direction? at? section? band? side? gap? thickness? unit? lineColor? lineWidth? min? guides? 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? subtitle? allClasses? hideOther? showNoData? exclude? layerOrder? columnBreaks? oneRow? columns? textSize? classLabels? sizes? 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? fields? header? sort? descending? selectedOnly? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? name? direction? at? section? band? side? gap? thickness? unit? lineColor? lineWidth? min? guides? 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 @@ -306,7 +306,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? subtitle? allClasses? hideOther? showNoData? exclude? layerOrder? columnBreaks? labels? classLabels? columns? textSize? showLayerNames? sizes? 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? extentNumbers? border? section? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? band? side? gap? thickness? unit? lineColor? lineWidth? min? guides? barOutline? hideLabels? rows? fields? header? sort? descending? selectedOnly? image? path? 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? subtitle? allClasses? hideOther? showNoData? exclude? layerOrder? columnBreaks? labels? classLabels? oneRow? columns? textSize? showLayerNames? sizes? 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? extentNumbers? border? section? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? mirror? max? band? side? gap? thickness? unit? lineColor? lineWidth? min? guides? barOutline? hideLabels? rows? fields? header? sort? descending? selectedOnly? image? path? 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? anonymous?
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ mod tests {
"1 diagram(s) that could not be read or named no field removed",
"1 diagram category(ies) with a blank field name",
"1 diagram category(ies) repeating an earlier field kept",
"1 layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference, a repeated extent indicator or a background on a map frame repaired while opening the project (in \"Poster\")",
"1 layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference, a repeated extent indicator, a background on a map frame or columns beside a legend's one row repaired while opening the project (in \"Poster\")",
] {
assert!(said.iter().any(|t| t.contains(text)), "{text}: {said:?}");
}
Expand Down
6 changes: 5 additions & 1 deletion crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ mod legend;
pub(in crate::cmd) use legend::say_unfitted_legends_in;
use legend::*;
pub(crate) use legend::{
legend_columns_param, legend_counts_param, legend_fit_param, legend_names_param, legend_sizes_param, legend_subtitle_param,
legend_columns_param, legend_counts_param, legend_fit_param, legend_names_param, legend_one_row_param, legend_sizes_param,
legend_subtitle_param,
};
mod picture;
pub(crate) use picture::gives_picture;
Expand Down Expand Up @@ -220,6 +221,7 @@ pub fn commands() -> Vec<C> {
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##""columnBreaks"?: [layer names] (legend: each of these layers starts a column, 5 at most, so "columns" above 1 and the fits that add columns are refused beside them), "##,
r##""oneRow"?: bool (legend: every entry side by side in one row, however many, the layers' names on a line over their classes; "columns" above 1, "columnBreaks" and the fits that add columns are refused beside it; default false), "##,
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; table: its text, its rows and columns following; default 8; colorbar: its labels, the bar making room for them; 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 @@ -342,6 +344,7 @@ pub fn commands() -> Vec<C> {
r##""columnBreaks"?: [layer names] (legend, as in layout.addElement; [] takes them off), "##,
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##""oneRow"?: bool (legend, as in layout.addElement), "##,
r##""columns"?: 1..6 (legend), "##,
r##""textSize"?: points, 4 to 100 (legend, scaleBar, table, colorbar, 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 @@ -654,6 +657,7 @@ pub(crate) fn new_layout(s: &mut Session, p: &Value) -> CmdResult {
exclude: Vec::new(),
layer_order: Vec::new(),
column_breaks: Vec::new(),
one_row: false,
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 @@ -382,6 +382,9 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
if kind != "legend" && gives(p, "columnBreaks") {
return Err(ONLY_LEGEND_BREAKS.into());
}
if kind != "legend" && gives(p, "oneRow") {
return Err(ONLY_LEGEND_ONE_ROW.into());
}
if kind != "legend" && p.get("columns").is_some_and(|v| !v.is_null()) {
return Err(ONLY_LEGEND_COLUMNS.into());
}
Expand Down Expand Up @@ -528,7 +531,8 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
let show_counts = legend_counts_param(p)?.map_or(FeatureCounts::Hidden, FeatureCounts::from_shown);
let subtitle = legend_subtitle_param(p)?.unwrap_or_default();
let sizes = legend_sizes_param(p)?.unwrap_or_default();
columns_set_by_breaks((&column_breaks, true), (columns, true), (fit, true))?;
let one_row = legend_one_row_param(p)?.unwrap_or(false);
columns_set_elsewhere(one_row, (&column_breaks, true), (columns, true), (fit, true))?;
(
"Legend",
place(p, l, (pw - 70.0, 45.0, 60.0, 80.0))?,
Expand All @@ -541,6 +545,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
exclude,
layer_order,
column_breaks,
one_row,
columns,
labels,
color: ink,
Expand Down Expand Up @@ -1184,6 +1189,7 @@ const ADD_LEGEND_KEYS: &[&str] = &[
"exclude",
"layerOrder",
"columnBreaks",
"oneRow",
"columns",
"labels",
"classLabels",
Expand Down
51 changes: 40 additions & 11 deletions crates/engine/src/cmd/layout/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,18 @@ pub(in crate::cmd::layout) fn say_raster_keys(s: &mut Session, li: usize, id: u3
/// and, in columns, at a text size of its own or under a fit, which can stop fitting, when its box
/// or what it lists changes. A move changes neither.
pub(in crate::cmd::layout) fn tells_legend_fit(kind: &ElementKind, p: &Value) -> bool {
let ElementKind::Legend { columns, column_breaks, text_size, fit, .. } = kind else { return false };
let ElementKind::Legend { columns, column_breaks, one_row, text_size, fit, .. } = kind else { return false };
let given = |k: &str| p.get(k).is_some_and(|v| !v.is_null());
let watched =
*columns > 1 || !column_breaks.is_empty() || *text_size != rustgis_map::layout::LEGEND_TEXT_PT || fit.kept() != LegendFit::Manual;
let watched = *columns > 1
|| *one_row
|| !column_breaks.is_empty()
|| *text_size != rustgis_map::layout::LEGEND_TEXT_PT
|| fit.kept() != LegendFit::Manual;
let refitted =
["w", "h", "title", "allClasses", "hideOther", "exclude", "layerOrder", "labels", "classLabels"].iter().any(|k| given(k));
["columns", "showNoData", "labels", "classLabels", "fit", "showLayerNames", "showCounts", "subtitle", "sizes"].iter().any(|k| given(k))
["columns", "showNoData", "labels", "classLabels", "fit", "showLayerNames", "showCounts", "subtitle", "sizes", "oneRow"]
.iter()
.any(|k| given(k))
|| p.get("textSize").is_some()
|| (watched && refitted)
|| given("columnBreaks")
Expand All @@ -149,6 +154,7 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
exclude,
layer_order,
column_breaks,
one_row,
columns,
labels,
text_size,
Expand All @@ -175,6 +181,7 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
let layer_order = layer_order.clone();
let column_breaks = column_breaks.clone();
let sizes = *sizes;
let one_row = *one_row;
let found = shown
.and_then(|(name, center, scale)| Some((s.project.maps.iter_mut().find(|m| m.name.eq_ignore_ascii_case(&name))?, center, scale)));
let Some((map, center, scale)) = found else {
Expand All @@ -191,13 +198,14 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
exclude: &exclude,
layer_order: &layer_order,
column_breaks: &column_breaks,
one_row,
labels: &labels,
class_labels: &class_labels,
show_counts,
sizes,
};
// Broken into columns, how many it draws is the drawing's to say.
let measured = if fit == LegendFit::Manual && column_breaks.is_empty() {
// Broken into columns or in one row, how many it draws is the drawing's to say.
let measured = if fit == LegendFit::Manual && column_breaks.is_empty() && !one_row {
let n = rustgis_map::layout::legend_columns_in_range(columns);
crate::render::layout::legend_size_asked_mm(map, at, &asked, n).map(|size| (n, overflows(size, room)))
} else {
Expand Down Expand Up @@ -305,6 +313,19 @@ pub(crate) fn legend_names_param(p: &Value) -> Result<Option<bool>, String> {
}
}

/// The refusal for `oneRow` on an element other than a legend.
pub(in crate::cmd::layout) const ONLY_LEGEND_ONE_ROW: &str = "only legends take oneRow";

/// The `"oneRow"` a legend is given, `true` or `false` only (`null` is not given): the one reader
/// the commands and the `layout-legend-one-row` capability check share.
pub(crate) fn legend_one_row_param(p: &Value) -> Result<Option<bool>, String> {
match p.get("oneRow") {
None | Some(Value::Null) => Ok(None),
Some(Value::Bool(one)) => Ok(Some(*one)),
Some(_) => Err("oneRow is true or false".into()),
}
}

/// The refusal for `subtitle` on an element other than a legend.
pub(in crate::cmd::layout) const ONLY_LEGEND_SUBTITLE: &str = "only legends take subtitle";

Expand Down Expand Up @@ -428,16 +449,24 @@ pub(in crate::cmd::layout) fn legend_column_breaks(
Ok(Some(names))
}

/// Refuses columns of its own, or a fit that adds them, beside the layers a legend starts its
/// columns at: those set its columns. `breaks`, `columns` and `fit` are what the legend would end
/// with, each with whether this command gave it; what a legend already held is refused only when
/// the command gives it breaks.
pub(in crate::cmd::layout) fn columns_set_by_breaks(
/// Refuses columns of its own, or a fit that adds them, beside what sets a legend's columns: the
/// layers it starts them at (#3445), or its one row (#3487), which takes no such layers either.
/// `one_row`, `breaks`, `columns` and `fit` are what the legend would end with; all but the first
/// each with whether this command gave it, since what a legend already held beside breaks is refused
/// only when the command gives it breaks. A legend in one row holds none of them.
pub(in crate::cmd::layout) fn columns_set_elsewhere(
one_row: bool,
(breaks, breaks_given): (&[String], bool),
(columns, columns_given): (usize, bool),
(fit, fit_given): (LegendFit, bool),
) -> Result<(), String> {
let adds = matches!(fit.kept(), LegendFit::AdjustColumns | LegendFit::AdjustColumnsAndSize);
if one_row && (columns > 1 || adds || !breaks.is_empty()) {
return Err(
r#"oneRow sets the legend's columns: give "columns": 1, "columnBreaks": [] and a fit that adds none, or "oneRow": false"#
.into(),
);
}
if !breaks.is_empty() && (columns > 1 && (breaks_given || columns_given) || adds && (breaks_given || fit_given)) {
return Err(
r#"columnBreaks sets the legend's columns: give "columns": 1 and a fit that adds none, or take the breaks off with []"#.into(),
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
exclude: legend.left_out(&context),
layer_order: Vec::new(),
column_breaks: Vec::new(),
one_row: false,
columns: legend_cols,
labels: Default::default(),
color: None,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/layout/publication/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl PublicationLegend {
exclude: &exclude,
layer_order: &[],
column_breaks: &[],
one_row: false,
labels: &labels,
class_labels: &rustgis_map::layout::ClassLabels::NONE,
show_counts: false,
Expand Down
Loading
Loading