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/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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? 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?
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? 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: 2 additions & 0 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ pub fn commands() -> Vec<C> {
r##""pitch"?: degrees of tilt (0 to 85), "##,
r##""grid"?: {grid options as in layout.addElement} | false (map frame; a grid's "labelSize" goes in it, and is refused outside it unless null), "##,
r##""extentIndicator"?: {"of"?: frame id, "color"?, "width"?: points, "remove"?: bool} | false (map frame: restyles one of its extent indicators, or removes it with "remove": true; "of" is the id of the frame that indicator outlines and may be omitted when there is only one; false removes them all), "##,
r##""extentNumbers"?: bool (map frame: numbers its extent indicators 1, 2, 3… in their order, each in its outline's colour at the outline's centre; none where that centre is off the frame or behind a globe's horizon, for an outline in a clear colour, or for a frame with no outline, one showing the whole globe; refused for other elements), "##,
r##""border"?: {"color"?: "#RRGGBB"|"#RRGGBBAA", "width"?: points, 0 to 20, 0 for none} | null (map frame: the outline along its shape, default #303030 and 0.8, the keys not given keeping theirs; null gives the default back; refused for other elements), "##,
r##""section"?: {"name": the section line it changes, "newName"?, "direction"?, "at"?, "color"?, "width"?, "dash"? ([] or null for solid), as in layout.addElement, the keys not given keeping theirs, "remove"?: true to remove it} (map frame; refused for other elements), "##,
r##""layer"?: (colorbar: "" for the top visible raster with a colour scale, not drawn by classes), "##,
Expand Down Expand Up @@ -606,6 +607,7 @@ fn frame_kind(s: &Session, map: &str, w: f64, shape: FrameShape) -> ElementKind
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
extent_numbers: false,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing,
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 @@ -1097,6 +1097,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
extent_numbers: false,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
// A map that runs to the page's edges has no border.
border_width: if edge { 0.0 } else { rustgis_map::layout::FRAME_BORDER_WIDTH },
Expand Down Expand Up @@ -1964,6 +1965,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
extent_numbers: false,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
Expand Down
16 changes: 14 additions & 2 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
// `true` adds the default one, an object changes the options it names, and null (not set)
// leaves it as it is.
let held;
let (restyled, new_grid, new_indicator, new_border, new_sections) = {
let (restyled, new_grid, new_indicator, new_numbers, new_border, new_sections) = {
let l = s.project.layouts.get(li).ok_or("no layout")?;
let kind = &l.element(id).ok_or_else(|| format!("no element {id}"))?.kind;
// `"extentIndicator": false` takes the frame's indicators away; an object restyles or
Expand All @@ -281,6 +281,13 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
(_, Some(_)) => return Err("only map frames have an extent indicator".into()),
_ => None,
};
// Whether the frame numbers its extent indicators (#3394).
let numbers = match (kind, p.get("extentNumbers").filter(|v| !v.is_null())) {
(ElementKind::MapFrame { .. }, Some(Value::Bool(on))) => Some(*on),
(ElementKind::MapFrame { .. }, Some(_)) => return Err("extentNumbers is true or false".into()),
(_, Some(_)) => return Err("only map frames number their extent indicators".into()),
_ => None,
};
// `"border": null` gives the frame the default border back; an object changes the colour
// and width it names, a width of 0 drawing none (#2557).
let border = match (kind, p.get("border")) {
Expand Down Expand Up @@ -326,7 +333,7 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
said.extend(held_width(v, "border width", (0.0, rustgis_map::layout::MAX_FRAME_BORDER_WIDTH)));
}
held = said;
(restyle(kind, p)?, grid, indicator, border, sections)
(restyle(kind, p)?, grid, indicator, numbers, border, sections)
};
// A line turned to an "angle" or made a "length" long, about its centre: its new box,
// direction and heads.
Expand Down Expand Up @@ -644,6 +651,11 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
if let Some(indicators) = new_indicator {
e.kind.set_extent_indicators(indicators);
}
if let Some(on) = new_numbers
&& let ElementKind::MapFrame { extent_numbers, .. } = &mut e.kind
{
*extent_numbers = on;
}
match &mut e.kind {
ElementKind::Text {
text,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ pub fn page_layout(s: &Session, pres: &Presentation, page: &Page) -> Layout {
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
extent_numbers: false,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
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 @@ -129,6 +129,7 @@ pub const CAPABILITIES: &[&str] = &[
"layout-legend-subtitle",
"layout-legend-nested-sizes",
"layout-extent-indicators",
"layout-extent-numbers",
"layout-legend-order",
"layout-legend-column-breaks",
"layout-picture-source",
Expand Down
50 changes: 50 additions & 0 deletions crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("layout-legend-subtitle", command_uses_legend_subtitle),
("layout-legend-nested-sizes", command_uses_legend_nested_sizes),
("layout-extent-indicators", command_uses_extent_indicators),
("layout-extent-numbers", command_numbers_extents),
("layout-legend-order", command_uses_legend_order),
("layout-legend-column-breaks", command_uses_legend_column_breaks),
("layout-picture-source", command_uses_picture_source),
Expand Down Expand Up @@ -738,6 +739,33 @@ fn extent_indicators_features(e: &rustgis_map::layout::Element) -> bool {
e.kind.has_more_extents()
}

/// A layout command that numbers a frame's extent indicators (#3394): an older reader ignores
/// `extentNumbers`, and a frame saved with it, drawing no numbers. `false` and `null` ask for what
/// it draws.
fn command_numbers_extents(id: &str, params: &Value) -> bool {
match id {
"layout.update" => params.get("extentNumbers") == Some(&Value::Bool(true)),
"layout.import" | "report.existingTemplate" => imported_layout_uses(params, &["\"extent_numbers\""], extent_numbers_features),
// It opens its `text` only, whatever else the step holds.
"project.openText" => params.get("text").and_then(Value::as_str).is_some_and(text_numbers_extents),
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_numbers_extents)),
_ => false,
}
}

/// Whether a project's saved text requires `layout-extent-numbers`, as one saved would: its
/// frames', its steps' and its notebooks'. Parsed only when the text names the key, either way it
/// is written, may hide it ([`may_hide_a_key`]), or holds a step's base64 `data` ([`names_data`]).
fn text_numbers_extents(text: &str) -> bool {
(["extent_numbers", "extentNumbers"].iter().any(|key| text.contains(key)) || may_hide_a_key(text) || names_data(text))
&& Project::from_json(text).is_ok_and(|p| p.required_capabilities().contains(&"layout-extent-numbers"))
}

/// Whether a layout element is a map frame that numbers its extent indicators.
fn extent_numbers_features(e: &rustgis_map::layout::Element) -> bool {
e.kind.numbers_extents()
}

Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
/// A layout command that nests a legend's sizes (#3347): an older reader ignores `sizes`, and a
/// legend saved with it, drawing rows. `"rows"` and `null` ask for what it draws.
fn command_uses_legend_nested_sizes(id: &str, params: &Value) -> bool {
Expand Down Expand Up @@ -1764,6 +1792,7 @@ fn layout_capabilities(layouts: &[rustgis_map::layout::Layout]) -> Vec<&'static
(elements().any(legend_subtitle_features), "layout-legend-subtitle"),
(elements().any(legend_nested_sizes_features), "layout-legend-nested-sizes"),
(elements().any(extent_indicators_features), "layout-extent-indicators"),
(elements().any(extent_numbers_features), "layout-extent-numbers"),
(elements().any(legend_orders_layers), "layout-legend-order"),
(elements().any(legend_breaks_columns), "layout-legend-column-breaks"),
(elements().any(pictures_with_files), "layout-picture-source"),
Expand Down Expand Up @@ -2165,6 +2194,7 @@ mod tests {
(&["layout-legend-counts"], "layout.update", json!({"element": 1, "showCounts": true})),
(&["layout-legend-nested-sizes"], "layout.update", json!({"element": 1, "sizes": "nested"})),
(&["layout-extent-indicators"], "layout.addElement", json!({"kind": "extentIndicator", "frame": 1, "of": 2})),
(&["layout-extent-numbers"], "layout.update", json!({"element": 1, "extentNumbers": true})),
(&["layout-legend-subtitle"], "layout.update", json!({"element": 1, "subtitle": "a"})),
(&["layout-legend-order"], "layout.update", json!({"element": 1, "layerOrder": ["a"]})),
(&["layout-legend-column-breaks"], "layout.update", json!({"element": 1, "columnBreaks": ["a"]})),
Expand Down Expand Up @@ -2476,6 +2506,26 @@ mod tests {
}
}

/// A saved step that opens a project from its text requires `layout-extent-numbers` when that
/// project numbers a frame's outlines, header or not, in a script too; and nothing when it
/// doesn't.
#[test]
fn an_opened_project_that_numbers_outlines_requires_it() {
let text = include_str!("../../../schema/fixtures/layout_extent_numbers.rgis");
let mut project: Value = serde_json::from_str(text).unwrap();
project.as_object_mut().unwrap().remove("requires");
let on = project.to_string();
let off = on.replace("\"extent_numbers\":true", "\"extent_numbers\":false");
assert_ne!(on, off);
let needs =
|id: &str, params: Value| model_capabilities(&[ModelStep { tool: id.into(), params }], None).contains(&"layout-extent-numbers");
for (text, wanted) in [(&on, true), (&off, false), (&on.replace("extent_numbers", "extent\\u005fnumbers"), true)] {
assert_eq!(needs("project.openText", json!({"text": text})), wanted, "{text}");
let line = format!("project.openText {}", json!({"text": text}));
assert_eq!(needs("script.run", json!({"script": line})), wanted, "in a script: {text}");
}
}

/// `report.existingTemplate` imports a layout file as `layout.import` does, so a step of it
/// requires what a `layout.import` of the same file does (#3226), by `text` or by `data`. Every
/// `layout_*` fixture is walked, so a capability added with one and read for `layout.import`
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/tests/archive_render_revision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn page(map: &Map) -> map::layout::Layout {
extent_color: map::Rgba::rgb(0, 0, 0),
extent_width: 1.0,
more_extents: Vec::new(),
extent_numbers: false,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
Expand Down
85 changes: 85 additions & 0 deletions crates/engine/src/tests/layout_extents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,88 @@ fn a_files_further_width_past_the_limit_is_said() {
frame["kind"]["MapFrame"]["more_extents"][0]["width"] = json!(99);
assert_eq!(said(&layout), (1, rustgis_map::layout::MAX_INDICATOR_WIDTH));
}

fn number(s: &mut Session, frame: u64, value: Value) -> Result<Value, String> {
s.run("layout.update", &json!({"element": frame, "extentNumbers": value})).map_err(|e| e.to_string())
}

/// What `frame` is saved with under `extent_numbers`.
fn saved_numbers(s: &Session, frame: u64) -> Value {
serde_json::to_value(&s.project.layouts[0].element(frame as u32).unwrap().kind).unwrap()["MapFrame"]["extent_numbers"].clone()
}

fn requires_numbers(project: &Project) -> bool {
serde_json::to_value(project).unwrap()["requires"].as_array().is_some_and(|r| r.contains(&json!("layout-extent-numbers")))
}

#[test]
fn numbering_is_turned_on_and_off_and_undone() {
let (mut s, overview, of) = laid_out(2);
add(&mut s, overview, of[0]);
let depth = s.undo_depth();
number(&mut s, overview, json!(true)).unwrap();
assert_eq!(saved_numbers(&s, overview), true);
assert_eq!(s.undo_depth(), depth + 1);
// Left out as not set: it stays as it is.
number(&mut s, overview, Value::Null).unwrap();
assert_eq!(saved_numbers(&s, overview), true);
number(&mut s, overview, json!(false)).unwrap();
assert_eq!(saved_numbers(&s, overview), Value::Null, "off is left out of the file");
s.run("edit.undo", &Value::Null).unwrap();
assert_eq!(saved_numbers(&s, overview), true);
}

#[test]
fn numbering_refuses_what_is_not_a_map_frame_or_a_switch() {
let (mut s, overview, of) = laid_out(1);
add(&mut s, overview, of[0]);
let legend = s.run("layout.addElement", &json!({"kind": "legend"})).unwrap()["element"].as_u64().unwrap();
for (element, value, said) in [
(legend, json!(true), "only map frames number their extent indicators"),
(overview, json!("yes"), "extentNumbers is true or false"),
(overview, json!(1), "extentNumbers is true or false"),
] {
let before = serde_json::to_value(&s.project).unwrap();
let err = number(&mut s, element, value.clone()).expect_err(&value.to_string());
assert!(err.contains(said), "{value}: {err}");
assert_eq!(serde_json::to_value(&s.project).unwrap(), before, "{value}");
}
}

#[test]
fn numbering_is_saved_with_its_capability_and_left_out_otherwise() {
let (mut s, overview, of) = laid_out(1);
add(&mut s, overview, of[0]);
assert!(!serde_json::to_string(&s.project).unwrap().contains("extent_numbers"));
assert!(!requires_numbers(&s.project));
number(&mut s, overview, json!(true)).unwrap();
assert!(requires_numbers(&s.project));
let text = serde_json::to_string(&s.project).unwrap();
let again: Project = serde_json::from_str(&text).unwrap();
assert_eq!(serde_json::to_string(&again).unwrap(), text);
// With its indicators removed the frame keeps the setting, for the next one added.
update(&mut s, overview, json!(false)).unwrap();
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
assert_eq!(saved_numbers(&s, overview), true);
assert!(requires_numbers(&s.project));
}

#[test]
fn saved_commands_that_number_require_the_capability() {
let (mut s, overview, of) = laid_out(1);
add(&mut s, overview, of[0]);
number(&mut s, overview, json!(true)).unwrap();
let layout = serde_json::to_string(&s.project.layouts[0]).unwrap();
let requires = |id: &str, params: Value| {
let mut p = Project::default();
p.tasks.push(
serde_json::from_value(json!({"name": "t", "title": "t", "steps": [{"title": "s", "command": id, "params": params}]})).unwrap(),
);
requires_numbers(&p)
};
assert!(requires("layout.update", json!({"element": 1, "extentNumbers": true})));
assert!(requires("layout.import", json!({"text": layout})));
assert!(requires("script.run", json!({"script": "layout.update {\"element\": 1, \"extentNumbers\": true}"})));
assert!(!requires("layout.update", json!({"element": 1, "extentNumbers": false})));
assert!(!requires("layout.update", json!({"element": 1, "extentNumbers": null})));
assert!(!requires("layout.addElement", json!({"kind": "northArrow"})));
}
1 change: 1 addition & 0 deletions crates/engine/src/tests/layout_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ fn a_saved_layout_file_requires_what_its_elements_use_and_reads_back_the_same()
("legend-subtitle", include_str!("../../../../schema/fixtures/layout_legend_subtitle.rgis")),
("legend-nested-sizes", include_str!("../../../../schema/fixtures/layout_legend_nested_sizes.rgis")),
("extent-indicators", include_str!("../../../../schema/fixtures/layout_extent_indicators.rgis")),
("extent-numbers", include_str!("../../../../schema/fixtures/layout_extent_numbers.rgis")),
("legend-order", include_str!("../../../../schema/fixtures/layout_legend_order.rgis")),
("legend-column-breaks", include_str!("../../../../schema/fixtures/layout_legend_column_breaks.rgis")),
("picture-source", include_str!("../../../../schema/fixtures/layout_picture_source.rgis")),
Expand Down
Loading
Loading