Skip to content
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? 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.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? fields? header? 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? 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? 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? 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? fields? header? 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?
Expand Down
12 changes: 8 additions & 4 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use rustgis_map::layout::{
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,
ScaleLabelPosition, ScaleUnits, Section, SectionLine, TABLE_TEXT_PT, 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 @@ -218,7 +218,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##""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##""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; 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), "##,
Expand Down Expand Up @@ -256,6 +256,8 @@ pub fn commands() -> Vec<C> {
r##""hideLabels"?: bool (chart: its labels left out, their room given to the bars; default false), "##,
r##""barOutline"?: {"color"?: "#RRGGBB"|"#RRGGBBAA" (default #222222), "width"?: points, 0 to 5 (default 0.5; 0 for none)} (chart: a line round each bar, or each stretch of a stacked one; default none) (label, group, statistic, order, bars, other, stack, values, decimals, barColor, classes, labelAlign, mirror, max, hideLabels and barOutline refused for other kinds unless null, as showNoData is, a scaleBar's decimals aside), "##,
r##""rows"?, "##,
r##""fields"?: [field names] (table: its columns, in this order; default [], every field in the layer's order), "##,
r##""header"?: bool (table: the row of field names; default true), "##,
r##""step"?: degrees, or a measured grid's units (metres) (0 picks one), "##,
r##""type"?: "graticule" (latitudes and longitudes, default) | "measured" (eastings and northings in a projected system), "##,
r##""crs"?: a measured grid's coordinate system: EPSG:25832, WKT or a PROJ string ("" or none: the map's when projected, else the UTM zone at the frame's centre), "##,
Expand Down Expand Up @@ -334,7 +336,7 @@ pub fn commands() -> Vec<C> {
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##""textSize"?: points, 4 to 100 (legend, scaleBar, table, 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), "##,
Expand Down Expand Up @@ -397,6 +399,8 @@ pub fn commands() -> Vec<C> {
r##""barOutline"?: {"color"?, "width"?: points, 0 to 5, a wider one held to 5, the keys not given keeping the outline's}|null (null or a width of 0 for none), "##,
r##""hideLabels"?: bool (chart, as in layout.addElement: null leaves each other one as it is; refused for other elements unless null), "##,
r##""rows"?, "##,
r##""fields"?: [field names] (table, as in layout.addElement, of the layer it will show; [] returns to every field, null leaves them; another "layer" without them drops them), "##,
r##""header"?: bool (table, as in layout.addElement; null leaves it as it is), "##,
r##""image"?: base64 (picture: its new image, its file no longer remembered, which is said when it had one), "##,
r##""path"?: a PNG or JPEG file (picture: read again, its image replacing the one it has, and remembered as its file; a file missing, over 16 MB, not a PNG or JPEG, or one that can't be drawn is refused and the picture left as it was; image and path together are refused; refused in the browser, which has no file paths: give its image; null leaves each as it is; refused for other elements), "##,
r##""background"?: {"fill"?, "outline"?, "width"?, "radius"?, "padding"?, as in layout.addElement, the keys not given keeping theirs} | null (removes it); a map frame takes none}"##,
Expand Down
53 changes: 50 additions & 3 deletions crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,42 @@ pub(in crate::cmd::layout) fn table_rows(p: &Value) -> Result<Option<usize>, Str
}
}

pub(in crate::cmd::layout) const ONLY_TABLE_LOOK: &str = "only tables take fields and header";

/// The field names a table is given as `"fields"`, when it's given (and not null): an error when
/// it's not a list of names. [`table_columns`] reads them against its layer.
pub(in crate::cmd::layout) fn table_fields(p: &Value) -> Result<Option<Vec<&str>>, String> {
let bad = || "fields is a list of field names".to_string();
let Some(v) = p.get("fields").filter(|v| !v.is_null()) else { return Ok(None) };
v.as_array().ok_or_else(bad)?.iter().map(|n| n.as_str().ok_or_else(bad)).collect::<Result<_, _>>().map(Some)
}

/// `names` as the fields of `ds` they name, spelled as it spells them: an error for one it hasn't,
/// or one named twice.
pub(in crate::cmd::layout) fn table_columns(ds: &rustgis_data::Dataset, names: &[&str]) -> Result<Vec<String>, String> {
let mut taken = std::collections::HashSet::new();
names
.iter()
.map(|name| {
let at = rustgis_map::layout::table_field(ds, name);
let (i, field) =
at.and_then(|i| ds.fields.get(i).map(|f| (i, f))).ok_or_else(|| format!("no field '{name}' in {}", ds.name))?;
if !taken.insert(i) {
return Err(format!("fields names '{}' twice", field.name));
}
Ok(field.name.clone())
})
.collect()
}

/// A table's "header", when it's given (and not null): an error when it's not true or false.
pub(in crate::cmd::layout) fn table_header(p: &Value) -> Result<Option<bool>, String> {
match p.get("header").filter(|v| !v.is_null()) {
Some(v) => crate::cmd::bool_value(v).map(Some).ok_or_else(|| "header must be true or false".to_string()),
None => Ok(None),
}
}

/// A line's "dir": `default` when it's not given (or null), an error when it's not a direction's
/// name.
pub(in crate::cmd::layout) fn line_dir(p: &Value, default: LineDir) -> Result<LineDir, String> {
Expand Down Expand Up @@ -272,9 +308,12 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
if kind == "profile" {
return add_profile(s, p);
}
if kind != "legend" && kind != "scaleBar" && p.get("textSize").is_some_and(|v| !v.is_null()) {
if !matches!(kind, "legend" | "scaleBar" | "table") && p.get("textSize").is_some_and(|v| !v.is_null()) {
return Err(ONLY_LAYOUT_TEXT_SIZE.into());
}
if kind != "table" && (gives(p, "fields") || gives(p, "header")) {
return Err(ONLY_TABLE_LOOK.into());
}
if kind != "grid" && p.get("labelSize").is_some_and(|v| !v.is_null()) {
return Err(ONLY_GRID_LABEL_SIZE.into());
}
Expand Down Expand Up @@ -520,7 +559,14 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
let frame = frame_of(l, p)?;
let layer = frame_layer_name(s, l, frame, p)?;
let rows = table_rows(p)?.unwrap_or(12);
("Table Frame", place(p, l, (15.0, ph * 0.6, pw * 0.5, ph * 0.35))?, ElementKind::Table { frame, layer, rows, color: ink })
let fields = match table_fields(p)? {
Some(names) => table_columns(frame_dataset(s, l, frame, &layer).ok_or("no such layer")?, &names)?,
None => Vec::new(),
};
let text_size = text_size_param(p, "textSize", TABLE_TEXT_PT)?.unwrap_or(TABLE_TEXT_PT);
let header = table_header(p)?.unwrap_or(true);
let k = ElementKind::Table { frame, layer, rows, color: ink, fields, text_size, header };
("Table Frame", place(p, l, (15.0, ph * 0.6, pw * 0.5, ph * 0.35))?, k)
}
"chart" => {
let frame = frame_of(l, p)?;
Expand Down Expand Up @@ -1079,7 +1125,8 @@ const ADD_TEXT_KEYS: &[&str] = &[
const ADD_PICTURE_KEYS: &[&str] = &["layout", "kind", "x", "y", "w", "h", "background", "image", "path"];

/// Keys read by `layout.addElement` for a table (#3074).
const ADD_TABLE_KEYS: &[&str] = &["layout", "kind", "frame", "x", "y", "w", "h", "background", "layer", "rows", "color"];
const ADD_TABLE_KEYS: &[&str] =
&["layout", "kind", "frame", "x", "y", "w", "h", "background", "layer", "rows", "color", "fields", "textSize", "header"];

/// Keys read by `layout.addElement` for a chart (#3074).
const ADD_CHART_KEYS: &[&str] = &[
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub(crate) fn align_footer(
}
}

pub(in crate::cmd::layout) const ONLY_LAYOUT_TEXT_SIZE: &str = "only legends and scale bars take textSize";
pub(in crate::cmd::layout) const ONLY_LAYOUT_TEXT_SIZE: &str = "only legends, scale bars and tables take textSize";

/// Says how many lines of the text `id` of the layout `li` don't fit its box (#2346), as the
/// layout view and an export count them: on the series' current page, measured at 300 dpi as a
Expand Down
Loading
Loading