Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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 @@ -26,7 +26,7 @@ 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), `"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),
text or add columns to fit its box), `"subtitle"` (one line under its title), `"patchWidth"` (4 to 100) and `"patchHeight"` (3 to 100) (points; the size of a line, polygon or raster class row's patch, default 16 and 9), `"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), `"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);
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? 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.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? patchWidth? patchHeight? 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? 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?
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? patchWidth? patchHeight? 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
8 changes: 6 additions & 2 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +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_one_row_param, legend_sizes_param,
legend_subtitle_param,
legend_columns_param, legend_counts_param, legend_fit_param, legend_names_param, legend_one_row_param, legend_patch_height_param,
legend_patch_width_param, legend_sizes_param, legend_subtitle_param,
};
mod picture;
pub(crate) use picture::gives_picture;
Expand Down Expand Up @@ -228,6 +228,7 @@ pub fn commands() -> Vec<C> {
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), "##,
r##""patchWidth"?: 4..100, "patchHeight"?: 3..100 (legend: the points a line, polygon or raster class row's patch is wide and tall at the default text size, 16 and 9 unless set; they grow with textSize; a point symbol keeps the size the map draws it at, and a legend of points only keeps the patch width's room before its labels; refused for other kinds), "##,
r##""sizes"?: "rows" (default) | "nested" (legend: a point layer's rows of marker sizes drawn as one block, the markers one inside another on a common base, each led to its value; refused for other kinds), "##,
r##""showCounts"?: bool (legend: each class row, and a one-symbol layer's row, ends in the number of features the layer's filters keep; default false; none for rasters, web layers, size and diagram rows, layers read in place other than from a local Shapefile, GeoPackage, FlatGeobuf or GeoParquet (each of those is read whole to count), or Unique Values by an expression over too many features and classes; refused for other kinds), "##,
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), "##,
Expand Down Expand Up @@ -351,6 +352,7 @@ pub fn commands() -> Vec<C> {
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), "##,
r##""patchWidth"?: 4..100, "patchHeight"?: 3..100 (legend, as in layout.addElement; null leaves each as it is), "##,
r##""sizes"?: "rows"|"nested" (legend, as in layout.addElement; null leaves it as it is), "##,
r##""showCounts"?: bool (legend, as in layout.addElement; null leaves it as it is), "##,
r##""orientation"? (colorbar, chart), "##,
Expand Down Expand Up @@ -671,6 +673,8 @@ pub(crate) fn new_layout(s: &mut Session, p: &Value) -> CmdResult {
show_counts: Default::default(),
subtitle: Default::default(),
sizes: Default::default(),
patch_width: rustgis_map::layout::LEGEND_PATCH_WIDTH_PT,
patch_height: rustgis_map::layout::LEGEND_PATCH_HEIGHT_PT,
},
);
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
14 changes: 13 additions & 1 deletion crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
if kind != "legend" && gives(p, "sizes") {
return Err(ONLY_LEGEND_SIZES.into());
}
if kind != "legend" && gives(p, "patchWidth") {
return Err(ONLY_LEGEND_PATCH_WIDTH.into());
}
if kind != "legend" && gives(p, "patchHeight") {
return Err(ONLY_LEGEND_PATCH_HEIGHT.into());
}
if legend_names_param(p)?.is_some() && kind != "legend" {
return Err(ONLY_LEGEND_NAMES.into());
}
Expand Down Expand Up @@ -531,6 +537,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();
let patch_width = legend_patch_width_param(p)?.unwrap_or(rustgis_map::layout::LEGEND_PATCH_WIDTH_PT);
let patch_height = legend_patch_height_param(p)?.unwrap_or(rustgis_map::layout::LEGEND_PATCH_HEIGHT_PT);
let one_row = legend_one_row_param(p)?.unwrap_or(false);
columns_set_elsewhere(one_row, (&column_breaks, true), (columns, true), (fit, true))?;
(
Expand All @@ -556,6 +564,8 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
show_counts,
subtitle,
sizes,
patch_width,
patch_height,
},
)
}
Expand Down Expand Up @@ -1198,6 +1208,8 @@ const ADD_LEGEND_KEYS: &[&str] = &[
"showLayerNames",
"showCounts",
"sizes",
"patchWidth",
"patchHeight",
"color",
];

Expand Down Expand Up @@ -1722,7 +1734,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", "font": "sans", "fallback": null, "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", "font": "sans", "fallback": null}),
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, "sizes": "nested", "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, "sizes": "nested", "patchWidth": 20, "patchHeight": 12, "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
33 changes: 33 additions & 0 deletions crates/engine/src/cmd/layout/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ pub(in crate::cmd::layout) fn tells_legend_fit(kind: &ElementKind, p: &Value) ->
["columns", "showNoData", "labels", "classLabels", "fit", "showLayerNames", "showCounts", "subtitle", "sizes", "oneRow"]
.iter()
.any(|k| given(k))
|| given("patchWidth")
|| given("patchHeight")
|| p.get("textSize").is_some()
|| (watched && refitted)
|| given("columnBreaks")
Expand Down Expand Up @@ -164,6 +166,8 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
show_counts,
subtitle,
sizes,
patch_width,
patch_height,
..
} = &e.kind
else {
Expand All @@ -181,6 +185,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 patch = (*patch_width, *patch_height);
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)));
Expand All @@ -203,6 +208,7 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
class_labels: &class_labels,
show_counts,
sizes,
patch,
};
// 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 {
Expand Down Expand Up @@ -337,6 +343,33 @@ pub(crate) fn legend_subtitle_param(p: &Value) -> Result<Option<String>, String>
.transpose()
}

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

/// The `"patchWidth"` a legend is given (#3559), in points at the default text size, 4 to 100
/// (`null` is not given): the one reader the commands and the `layout-legend-patch-size`
/// capability check share.
pub(crate) fn legend_patch_width_param(p: &Value) -> Result<Option<f64>, String> {
patch_param(p, "patchWidth", &rustgis_map::layout::LEGEND_PATCH_WIDTH_RANGE)
}

/// The `"patchHeight"` a legend is given, 3 to 100: see [`legend_patch_width_param`].
pub(crate) fn legend_patch_height_param(p: &Value) -> Result<Option<f64>, String> {
patch_param(p, "patchHeight", &rustgis_map::layout::LEGEND_PATCH_HEIGHT_RANGE)
}

fn patch_param(p: &Value, key: &str, range: &std::ops::RangeInclusive<f64>) -> Result<Option<f64>, String> {
match p.get(key) {
None | Some(Value::Null) => Ok(None),
Some(v) => v
.as_f64()
.filter(|v| range.contains(v))
.map(Some)
.ok_or_else(|| format!("{key} is a number of points, {} to {}", range.start(), range.end())),
}
}

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

Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
show_counts: Default::default(),
subtitle: Default::default(),
sizes: Default::default(),
patch_width: rustgis_map::layout::LEGEND_PATCH_WIDTH_PT,
patch_height: rustgis_map::layout::LEGEND_PATCH_HEIGHT_PT,
},
);
}
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 @@ -175,6 +175,7 @@ impl PublicationLegend {
class_labels: &rustgis_map::layout::ClassLabels::NONE,
show_counts: false,
sizes: Default::default(),
patch: (rustgis_map::layout::LEGEND_PATCH_WIDTH_PT, rustgis_map::layout::LEGEND_PATCH_HEIGHT_PT),
};
[legend_size_asked_mm(map, scale, &asked, columns)?; PUBLICATION_LEGEND_COLUMNS]
}
Expand Down
15 changes: 15 additions & 0 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
return Err(ONLY_LEGEND_SIZES.into());
}
let new_sizes = legend_sizes_param(p)?;
if gives(p, "patchWidth") && !is_legend {
return Err(ONLY_LEGEND_PATCH_WIDTH.into());
}
if gives(p, "patchHeight") && !is_legend {
return Err(ONLY_LEGEND_PATCH_HEIGHT.into());
}
let new_patch = (legend_patch_width_param(p)?, legend_patch_height_param(p)?);
if p.get("textSize").is_some_and(|v| !v.is_null()) && !sized && !is_table && !is_colorbar {
return Err(ONLY_LAYOUT_TEXT_SIZE.into());
}
Expand Down Expand Up @@ -743,11 +750,19 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
show_counts,
subtitle,
sizes,
patch_width,
patch_height,
..
} => {
if let Some(new) = new_sizes {
*sizes = new;
}
if let Some(width) = new_patch.0 {
*patch_width = width;
}
if let Some(height) = new_patch.1 {
*patch_height = height;
}
if let Some(text) = new_subtitle {
*subtitle = text;
}
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub const CAPABILITIES: &[&str] = &[
"layout-legend-class-labels",
"layout-legend-counts",
"layout-legend-subtitle",
"layout-legend-patch-size",
"layout-legend-nested-sizes",
"layout-extent-indicators",
"layout-extent-numbers",
Expand Down
Loading
Loading