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 @@ -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), `"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), `"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) and `"classLabels"` (`{"<layer>": {"<class label>": "<text>"}}`: its own text for a
class, the layer keeping its label).
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 @@ -283,7 +283,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? 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? 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? 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? 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 @@ -305,7 +305,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? 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? band? side? gap? thickness? unit? lineColor? lineWidth? min? guides? 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? subtitle? allClasses? hideOther? showNoData? exclude? layerOrder? 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? 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? 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
18 changes: 12 additions & 6 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ use rustgis_geom::{Coord, Extent};
use rustgis_map::layout::{
Arrange, ArrowStyle, Background, CHART_BAR, CHART_BARS, CHART_OUTLINE, ChartOrder, ChartOutline, ClassLabels, CoordFormat, ElementKind,
FeatureCounts, 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,
LayerNames, Layout, LegendFit, LegendSizes, 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,
};
use rustgis_map::report::StatKind;
use rustgis_map::symbology::{Dash, MAX_DASH_STEP, MAX_DASH_STEPS};
Expand Down Expand Up @@ -41,7 +42,9 @@ pub(crate) use inputs::*;
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_subtitle_param};
pub(crate) use legend::{
legend_columns_param, legend_counts_param, legend_fit_param, legend_names_param, legend_sizes_param, legend_subtitle_param,
};
mod page;
use page::*;
mod profile;
Expand Down Expand Up @@ -212,6 +215,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; 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##""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), "##,
r##""orientation"?: "horizontal"|"vertical" (colorbar; chart: bars running across, the default, or columns standing up, each label centred under its column), "##,
Expand Down Expand Up @@ -327,6 +331,7 @@ pub fn commands() -> Vec<C> {
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), "##,
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), "##,
r##""ticks"?, "##,
Expand Down Expand Up @@ -634,6 +639,7 @@ pub(crate) fn new_layout(s: &mut Session, p: &Value) -> CmdResult {
class_labels: Default::default(),
show_counts: Default::default(),
subtitle: Default::default(),
sizes: 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
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 @@ -296,6 +296,9 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
if kind != "legend" && gives(p, "subtitle") {
return Err(ONLY_LEGEND_SUBTITLE.into());
}
if kind != "legend" && gives(p, "sizes") {
return Err(ONLY_LEGEND_SIZES.into());
}
if legend_names_param(p)?.is_some() && kind != "legend" {
return Err(ONLY_LEGEND_NAMES.into());
}
Expand Down Expand Up @@ -425,6 +428,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
let show_layer_names = legend_names_param(p)?.map_or(LayerNames::Shown, LayerNames::from_shown);
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();
(
"Legend",
place(p, l, (pw - 70.0, 45.0, 60.0, 80.0))?,
Expand All @@ -445,6 +449,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
class_labels,
show_counts,
subtitle,
sizes,
},
)
}
Expand Down Expand Up @@ -1015,6 +1020,7 @@ const ADD_LEGEND_KEYS: &[&str] = &[
"fit",
"showLayerNames",
"showCounts",
"sizes",
"color",
];

Expand Down Expand Up @@ -1499,7 +1505,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": [], "layerOrder": [], "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, "sizes": "nested", "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
14 changes: 13 additions & 1 deletion crates/engine/src/cmd/layout/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub(in crate::cmd::layout) fn tells_legend_fit(kind: &ElementKind, p: &Value) ->
let watched = *columns > 1 || *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"].iter().any(|k| given(k))
["columns", "showNoData", "labels", "classLabels", "fit", "showLayerNames", "showCounts", "subtitle", "sizes"].iter().any(|k| given(k))
|| p.get("textSize").is_some()
|| (watched && refitted)
}
Expand Down Expand Up @@ -152,6 +152,7 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
class_labels,
show_counts,
subtitle,
sizes,
..
} = &e.kind
else {
Expand All @@ -167,6 +168,7 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
let (fit, layer_names, class_labels) = (fit.kept(), show_layer_names.shown(), class_labels.clone());
let show_counts = show_counts.shown();
let layer_order = layer_order.clone();
let sizes = *sizes;
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 @@ -185,6 +187,7 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32
labels: &labels,
class_labels: &class_labels,
show_counts,
sizes,
};
let measured = if fit == LegendFit::Manual {
let n = rustgis_map::layout::legend_columns_in_range(columns);
Expand Down Expand Up @@ -303,6 +306,15 @@ pub(crate) fn legend_subtitle_param(p: &Value) -> Result<Option<String>, String>
.transpose()
}

/// 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";

/// The `"sizes"` a legend is given (#3347), a name (`null` is not given): the one reader the
/// commands and the `layout-legend-nested-sizes` capability check share.
pub(crate) fn legend_sizes_param(p: &Value) -> Result<Option<LegendSizes>, String> {
given_choice(p, "sizes", LegendSizes::from_name, "rows or nested")
}

/// The `"showCounts"` a legend is given, `true` or `false` only (`null` is not given): the one
/// reader the commands and the `layout-legend-counts` capability check share.
pub(crate) fn legend_counts_param(p: &Value) -> Result<Option<bool>, String> {
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 @@ -2080,6 +2080,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
class_labels: Default::default(),
show_counts: Default::default(),
subtitle: Default::default(),
sizes: Default::default(),
},
);
}
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 @@ -172,6 +172,7 @@ impl PublicationLegend {
labels: &labels,
class_labels: &rustgis_map::layout::ClassLabels::NONE,
show_counts: false,
sizes: Default::default(),
};
[legend_size_asked_mm(map, scale, &asked, columns)?; PUBLICATION_LEGEND_COLUMNS]
}
Expand Down
8 changes: 8 additions & 0 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
return Err(ONLY_LEGEND_SUBTITLE.into());
}
let new_subtitle = legend_subtitle_param(p)?;
if gives(p, "sizes") && !is_legend {
return Err(ONLY_LEGEND_SIZES.into());
}
let new_sizes = legend_sizes_param(p)?;
if p.get("textSize").is_some_and(|v| !v.is_null()) && !sized {
return Err(ONLY_LAYOUT_TEXT_SIZE.into());
}
Expand Down Expand Up @@ -616,8 +620,12 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
class_labels,
show_counts,
subtitle,
sizes,
..
} => {
if let Some(new) = new_sizes {
*sizes = new;
}
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 @@ -124,6 +124,7 @@ pub const CAPABILITIES: &[&str] = &[
"layout-legend-class-labels",
"layout-legend-counts",
"layout-legend-subtitle",
"layout-legend-nested-sizes",
"layout-legend-order",
"layout-scale-bar-details",
"label-guide",
Expand Down
Loading
Loading