Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
390ed5f
feat(layout): scale bar details in the layout model
m-hollis-1 Nov 20, 2026
5ef024e
fix(layout): the fit strategy is adjustDivision
m-hollis-1 Nov 20, 2026
2e60230
test(render): pin how a plain scale bar draws
m-hollis-1 Nov 20, 2026
ceda19a
feat(render): scale bars with subdivisions, divisions before zero and…
m-hollis-1 Nov 20, 2026
e341a9f
feat(render): scale bar labels above or below, a unit label where ask…
m-hollis-1 Nov 21, 2026
dad5f7a
fix(render): scale bar clippy and a real test for the unit-label cap
m-hollis-1 Nov 21, 2026
2ad527a
feat(layout): scale bar details through layout.addElement and layout.…
m-hollis-1 Nov 21, 2026
0f2ba0e
feat(ui): a scale bar's details in the Format pane
m-hollis-1 Nov 21, 2026
0a95c45
docs(layout): scale bar details in the user guide and the print-layou…
m-hollis-1 Nov 21, 2026
98cc1a4
fix(layout): scale bar details: capability for an imported unit label…
m-hollis-1 Nov 21, 2026
6ee172f
docs(layout): scale bar decimals and subdivisions described as they b…
m-hollis-1 Nov 21, 2026
6ea269e
feat(layout): a scale bar's decimals share the chart's auto-or-fixed …
m-hollis-1 Nov 22, 2026
75cfa6a
docs(layout): the shared decimals key, said once in the params text a…
m-hollis-1 Nov 22, 2026
9307f8f
fix(render): a scale bar with divisions before zero keeps drawing whe…
m-hollis-1 Nov 22, 2026
359a172
fix(layout): one subdivision loads as none
m-hollis-1 Nov 22, 2026
1d159c1
fix(ui): a scale bar's typed unit label survives hiding and showing it
m-hollis-1 Nov 22, 2026
96748ee
fix(ui): a scale bar's unit label draft is saved or discarded like th…
m-hollis-1 Nov 22, 2026
322edd3
fix(render): a scale bar's alternation runs unbroken through its subd…
m-hollis-1 Nov 22, 2026
c27dd1e
test(render): pin the plain scale bar under the built-in font
m-hollis-1 Nov 22, 2026
25e5de2
docs(layout): wrap the scale bar paragraphs
m-hollis-1 Nov 22, 2026
64b61c1
fix(layout): scale bar review round two: pane labels in tl!, the kept…
m-hollis-1 Nov 22, 2026
11f7954
fix(layout): a publication's scale box is measured again once its bar…
m-hollis-1 Nov 22, 2026
e58abf4
fix(render): a scale bar's unit label and label rows stay inside the …
m-hollis-1 Nov 22, 2026
a4292eb
test(render): the pin's child process must report that it ran
m-hollis-1 Nov 22, 2026
cdf1c52
fix(render): a scale bar's unit label fits the element wherever it is…
m-hollis-1 Nov 22, 2026
8ff8313
fix(ui): the kept unit label is keyed by the layout's name as well
m-hollis-1 Nov 22, 2026
3547745
fix(render): a scale bar's rows stay inside the element even when the…
m-hollis-1 Nov 22, 2026
3719580
chore(schema): regenerate after rebase
m-hollis-1 Nov 22, 2026
62d85e8
fix(layout): a scale box width set by hand survives its bar going det…
m-hollis-1 Nov 22, 2026
5766fac
perf(render): a unit label is shortened by binary search
m-hollis-1 Nov 22, 2026
2f494bc
fix(layout): a scale bar's decimals take numeric strings and whole fl…
m-hollis-1 Nov 22, 2026
7c1e6e7
fix(render): a first label before zero takes at most half a scale bar…
m-hollis-1 Nov 22, 2026
0ae77b6
test(render): the before-zero fit test looks at the bar's own row
m-hollis-1 Nov 22, 2026
d14b8bc
fix(render): a unit after the labels stays inside both edges of the e…
m-hollis-1 Nov 22, 2026
103fe9f
fix(render): adjustDivision steps the division up rather than stoppin…
m-hollis-1 Nov 22, 2026
9c892bc
Merge upstream main into feat/layout-scale-bar-details (#2660 scale b…
m-hollis-1 Nov 22, 2026
55bd359
refactor(layout): the scale bar's label size is its textSize
m-hollis-1 Nov 22, 2026
4b39df8
refactor(render): the scale bar's rows go through bar_layout
m-hollis-1 Nov 22, 2026
5de6c32
fix(layout): a publication's scale box is measured from every scale b…
m-hollis-1 Nov 22, 2026
ac70333
test(render): a detailed scale bar's box holds all it draws
m-hollis-1 Nov 22, 2026
c52cd99
style(layout): rustfmt after the merge
m-hollis-1 Nov 22, 2026
05ec637
Merge upstream main into feat/layout-scale-bar-details (fixes after #…
m-hollis-1 Nov 22, 2026
76deb02
fix(render): a shortened or left-out unit label is said
m-hollis-1 Nov 22, 2026
10bc284
fix(render): the divisions before zero count toward the ten a scale b…
m-hollis-1 Nov 22, 2026
1a5f8fd
fix(layout): one subdivision in an imported layout needs no capability
m-hollis-1 Nov 22, 2026
b9dd0d2
fix(render): stepped and alternating scale bars agree on which divisi…
m-hollis-1 Nov 22, 2026
b4e0cb7
fix(render): ten divisions in all under every fit
m-hollis-1 Nov 22, 2026
1b4cbed
fix(layout): a null unit label is refused where a unit label would be
m-hollis-1 Nov 22, 2026
623083a
Merge upstream main into feat/layout-scale-bar-details
m-hollis-1 Nov 23, 2026
d8bc7f2
fix(layout): the cut notice names a scale bar's unit label
m-hollis-1 Nov 23, 2026
a7cbe89
chore(engine): the command surface lists the scale bar's detail keys
m-hollis-1 Nov 23, 2026
8e3c83e
Merge upstream main into feat/layout-scale-bar-details (layout file h…
m-hollis-1 Nov 23, 2026
07be6b4
feat(layout): a layout file with scale bar details says so in its header
m-hollis-1 Nov 23, 2026
5b163de
fix(layout): a scale bar's decimals past 255 in a file are brought in…
m-hollis-1 Nov 23, 2026
4f60a72
fix(layout): a negative or fractional scale bar decimals in a file go…
m-hollis-1 Nov 23, 2026
0ebf5bd
fix(layout): a scale bar's decimals of any JSON kind in a file loads:…
m-hollis-1 Nov 24, 2026
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
8 changes: 6 additions & 2 deletions crates/assistant/skills/print-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ description: Make a printable page layout — map frame, title, legend, north ar
`"northArrow"`, `"scaleBar"`, and optionally `"dynamicText"` (the date or a source line). Keep a margin of about
10 mm. The legend and scale bar usually go along the bottom or the right edge. A north arrow takes a `"style"`
(`"classic"`, `"compass"`, `"triangle"`, `"star"`); a scale bar `"units"` (`"auto"`, `"kilometers"`, `"meters"`,
`"miles"`, `"feet"`), `"divisions"` and a `"style"` (`"alternating"`, `"stepped"`, `"line"`). `"grid"` adds a
graticule to the frame (`"style": "ticks"` for neatline ticks, `"format": "dms"`, `"edges"`).
`"miles"`, `"feet"`), `"divisions"` and a `"style"` (`"alternating"`, `"stepped"`, `"line"`); it can also take
`"subdivisions"` (0–10), `"divisionsBeforeZero"` (0–2), `"labelPosition"` (`"above"`, `"below"`), `"unitLabel"`
(text; `""` for none), `"unitLabelPosition"` (`"afterLabels"`, `"afterBar"`, `"above"`, `"below"`), `"decimals"`
(`"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"`). `"grid"` adds a graticule to the frame
(`"style": "ticks"` for neatline ticks, `"format": "dms"`, `"edges"`).
5. Adjust with `layout.update` (`{"element": id, "x", "y", "w", "h", "text", "size", "bold"}`). The ids come from the
results of the earlier calls.
6. `layout.export` `{"path": "map.pdf"}`, or `.png` with a `dpi` (300 for print). Exporting writes a file, so the
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 @@ -281,7 +281,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? font? fallback? title? allClasses? hideOther? showNoData? exclude? columns? textSize? 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? rows? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? outline? units? divisions? x? y? w? h? background?
layout.addElement layout? kind frame? of? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? font? fallback? title? allClasses? hideOther? showNoData? exclude? columns? textSize? 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? rows? step? type? crs? short? mgrs? labels? style? tickLength? format? hemisphere? edges? labelOrientation? labelSize? off? 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 @@ -302,7 +302,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? font? fallback? title? allClasses? hideOther? showNoData? exclude? labels? columns? textSize? orientation? ticks? tickSide? reverse? style? fill? outline? radius? width? dash? dir? head? angle? length? units? divisions? map? scale? center? bearing? pitch? grid? extentIndicator? border? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? rows? background?
layout.update layout? element x? y? w? h? name? visible? locked? text? size? color? bold? italic? align? letterSpacing? rotation? wrap? font? fallback? title? allClasses? hideOther? showNoData? exclude? labels? columns? textSize? 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? layer? field? label? group? statistic? order? bars? other? stack? values? decimals? barColor? classes? labelAlign? 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? overlay? top? replace? id? view? start? end? unit? interval? dates? legend? connection?
Expand Down
211 changes: 165 additions & 46 deletions crates/engine/src/cmd/layout.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub const CAPABILITIES: &[&str] = &[
"label-guide",
PROJECT_CRS,
"dggs-system",
"layout-scale-bar-details",
];
/// An offline area keeping the versions that lost a sync or a Bring Back
/// (`OfflineArea::conflicts`, #2468): an older reader would save it again without them.
Expand Down Expand Up @@ -2693,7 +2694,7 @@ pub(crate) fn layout_notices(
let cut = total(|r| r.elements_cut);
if cut > 0 {
notices.push(format!(
"{name}: {cut} layout element(s) with a name, text, polygon points, legend exclusions or legend labels cut to their limits {when} (in {})",
"{name}: {cut} layout element(s) with a name, text, polygon points, legend exclusions, scale bar unit labels or legend labels cut to their limits {when} (in {})",
layout_names(repairs, |r| r.elements_cut)
));
}
Expand Down
155 changes: 154 additions & 1 deletion crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("layout-frame-border", command_uses_frame_border),
("layout-text-size", command_uses_text_size),
("dggs-system", command_uses_dggs_system),
("layout-scale-bar-details", command_uses_scale_bar_details),
];

/// A saved `map.graticule` that switches to the MGRS grid, its type read as the command reads it:
Expand Down Expand Up @@ -368,6 +369,56 @@ fn command_uses_chart_stack(id: &str, params: &Value) -> bool {
}
}

/// Whether a layout element is a scale bar with details an older reader's can't draw: it would
/// draw a plain bar and save it again without them.
fn bar_details(e: &rustgis_map::layout::Element) -> bool {
e.kind.scale_bar_uses_details()
}

/// A layout command that gives a scale bar a detail off its default: an older reader ignores the
/// keys and draws a plain bar. Giving the defaults, `"decimals": "auto"`, or `"unitLabel": null`
/// (the abbreviation an older reader's bar prints), keeps a bar as an older reader draws it.
fn command_uses_scale_bar_details(id: &str, params: &Value) -> bool {
use rustgis_map::layout::{ScaleBarFit, ScaleLabelPosition, UnitLabelPosition};
// A fixed number of decimals, 0 included, not "auto". A chart takes decimals too: a
// `layout.addElement` says which kind it adds, but a `layout.update` doesn't say what it
// changes, so a chart's decimals there require this as well, as a scale bar's require
// `layout-chart-look`; the layout saved with the element requires what it holds anyway.
let fixed_decimals = |id: &str| {
crate::cmd::uint(params, "decimals").is_some()
&& (id == "layout.update"
|| params.get("kind").and_then(Value::as_str).is_some_and(|k| k.trim().eq_ignore_ascii_case("scaleBar")))
};
match id {
"layout.addElement" | "layout.update" => {
let num = |k: &str| crate::cmd::f(params, k);
let name = |k: &str| params.get(k).and_then(Value::as_str);
num("subdivisions").is_some_and(|n| n >= 2.0)
|| num("divisionsBeforeZero").is_some_and(|n| n >= 1.0)
|| name("labelPosition").and_then(ScaleLabelPosition::from_name).is_some_and(|v| v != ScaleLabelPosition::default())
|| params.get("unitLabel").is_some_and(Value::is_string)
|| name("unitLabelPosition").and_then(UnitLabelPosition::from_name).is_some_and(|v| v != UnitLabelPosition::default())
|| fixed_decimals(id)
|| name("fit").and_then(ScaleBarFit::from_name).is_some_and(|v| v != ScaleBarFit::default())
}
"layout.import" => imported_layout_uses(
params,
&[
"\"subdivisions\"",
"\"divisions_before_zero\"",
"\"label_position\"",
"\"unit_label\"",
"\"unit_label_position\"",
"\"decimals\"",
"\"fit\"",
],
bar_details,
),
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_scale_bar_details)),
_ => false,
}
}

/// Whether a `layout.import` carries its layout as `"text"` with an element `uses`: an older
/// reader reads it without the keys it doesn't know. One read from a `"path"` is a layout file,
/// whose own header requires what it uses (#2277). Every save asks, so a text with none of the
Expand Down Expand Up @@ -657,6 +708,7 @@ fn layout_capabilities(layouts: &[rustgis_map::layout::Layout]) -> Vec<&'static
(elements().any(charts_stack), "layout-chart-stack"),
(elements().any(|e| e.kind.has_custom_border()), "layout-frame-border"),
(elements().any(|e| e.kind.has_custom_text_size()), "layout-text-size"),
(elements().any(bar_details), "layout-scale-bar-details"),
]
.into_iter()
.filter_map(|(used, name)| used.then_some(name))
Expand Down Expand Up @@ -1233,7 +1285,13 @@ mod tests {
let mut document = base.clone();
document["tasks"] = value;
let saved = serde_json::to_value(Project::from_json(&document.to_string()).unwrap()).unwrap();
let expected = if required { json!(["layout-chart-look"]) } else { Value::Null };
// An update's decimals may be a scale bar's too, which it can't tell apart.
let bar_too = id == "layout.update" && params.get("decimals").is_some_and(Value::is_u64);
let expected = match (required, bar_too) {
(true, true) => json!(["layout-chart-look", "layout-scale-bar-details"]),
(true, false) => json!(["layout-chart-look"]),
_ => Value::Null,
};
assert_eq!(saved.get("requires").cloned().unwrap_or(Value::Null), expected, "{id} {params}");
}
}
Expand Down Expand Up @@ -1332,6 +1390,101 @@ mod tests {
}
}

/// A scale bar with details is required where it is saved, so an older reader refuses the project
/// instead of drawing a plain bar and saving it again without them; so is a saved command that
/// sets one. The defaults, or a unit label taken back to its abbreviation, need nothing.
#[test]
fn scale_bar_details_capability_follows_saved_layouts_and_commands() {
use rustgis_map::layout::ElementKind;
let fixture = Project::from_json(include_str!("../../../schema/fixtures/layout_scale_bar_details.rgis")).unwrap();
let saved = serde_json::to_value(&fixture).unwrap();
// Its sized bar's text size is the text size capability's, as for any scale bar.
assert_eq!(saved["requires"], json!(["layout-text-size", "layout-scale-bar-details"]));
let reread = Project::from_json(&saved.to_string()).unwrap();
assert!(reread.layouts[0].elements[1].kind.scale_bar_uses_details());
assert!(!reread.layouts[0].elements[2].kind.scale_bar_uses_details());
let mut clean = fixture;
for e in &mut clean.layouts[0].elements {
if let ElementKind::ScaleBar { frame, units, divisions, style, color, fill, .. } = &e.kind {
let mut plain = ElementKind::scale_bar(*frame);
if let ElementKind::ScaleBar { units: u, divisions: d, style: st, color: c, fill: f, .. } = &mut plain {
(*u, *d, *st, *c, *f) = (*units, *divisions, *style, *color, *fill);
}
e.kind = plain;
}
}
let base = serde_json::to_value(&clean).unwrap();
assert!(base.get("requires").is_none(), "a plain bar needs nothing");
for key in [
"subdivisions",
"divisions_before_zero",
"label_position",
"unit_label",
"unit_label_position",
"decimals",
"text_size",
"\"fit\"",
] {
assert!(!base["layouts"].to_string().contains(key), "nor writes {key}");
}
let layout = &saved["layouts"][0];
let mut position_only = base["layouts"][0].clone();
position_only["elements"][1]["kind"]["ScaleBar"]["unit_label_position"] = json!("afterBar");
// One subdivision clamps to none, so a text whose only detail it is needs nothing.
let mut one_subdivision = base["layouts"][0].clone();
one_subdivision["elements"][1]["kind"]["ScaleBar"]["subdivisions"] = json!(1);
for (id, params, required) in [
("layout.addElement", json!({"kind": "scaleBar", "subdivisions": 4}), true),
("layout.update", json!({"element": 2, "labelPosition": "below"}), true),
("layout.update", json!({"element": 2, "unitLabel": ""}), true),
("layout.update", json!({"element": 2, "fit": "adjustWidth"}), true),
// A text size is no detail: the text size capability covers it.
("layout.update", json!({"element": 2, "textSize": 9}), false),
("layout.addElement", json!({"kind": "scaleBar", "textSize": 12}), false),
("layout.update", json!({"element": 2, "unitLabel": null}), false),
// Fixed decimals, none too, are a detail; "auto" isn't. An update's may be a chart's,
// which it can't tell apart; an addElement's for a chart is the chart's alone.
("layout.addElement", json!({"kind": "scaleBar", "decimals": 0}), true),
("layout.addElement", json!({"kind": "scaleBar", "decimals": "auto"}), false),
("layout.addElement", json!({"kind": "chart", "decimals": 2}), false),
("layout.update", json!({"element": 2, "decimals": 2}), true),
("layout.update", json!({"element": 2, "decimals": "2"}), true),
("layout.update", json!({"element": 2, "decimals": 2.0}), true),
("layout.update", json!({"element": 2, "decimals": "auto"}), false),
(
"layout.update",
json!({"element": 2, "subdivisions": 1, "divisionsBeforeZero": 0, "labelPosition": "above", "unitLabelPosition": "afterLabels", "decimals": "auto", "textSize": null, "fit": "adjustDivisionValue"}),
false,
),
("layout.update", json!({"element": 2, "divisions": 3}), false),
("layout.import", json!({"text": layout.to_string()}), true),
("layout.import", json!({"text": base["layouts"][0].to_string()}), false),
("layout.import", json!({"text": position_only.to_string()}), true),
("layout.import", json!({"text": one_subdivision.to_string()}), false),
("layout.import", json!({"path": "bars.rgislayout"}), false),
] {
let script = format!("{id}= {params}");
for value in [
json!([{"name": "Task", "steps": [{"title": "Bar", "command": id, "params": params}]}]),
json!([{"name": "Script", "steps": [{"title": "Bar", "command": "script.run", "params": {"script": script}}]}]),
] {
let mut document = base.clone();
document["tasks"] = value;
let saved = serde_json::to_value(Project::from_json(&document.to_string()).unwrap()).unwrap();
// Decimals a chart takes too may require its capability as well, and a text size
// its own.
let requires = saved.get("requires").and_then(Value::as_array).cloned().unwrap_or_default();
assert_eq!(requires.contains(&json!("layout-scale-bar-details")), required, "{id} {params}");
assert!(
requires
.iter()
.all(|r| ["layout-scale-bar-details", "layout-chart-look", "layout-text-size"].contains(&r.as_str().unwrap_or(""))),
"{id} {params}"
);
}
}
}

#[test]
fn field_identity_is_preserved_and_required_in_a_plain_saved_project() {
let project = Project::from_json(include_str!("../../../schema/fixtures/field_origin.rgis")).unwrap();
Expand Down
Loading
Loading