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 @@ -10,7 +10,7 @@ description: Make a printable page layout — map frame, title, legend, north ar
(`"a4"`, `"a3"` or `"a2"` for a sheet turned to the area's shape, or `"a4-portrait"`, `"a3-landscape"`, … to choose; `"figure-1col"`, `"thesis-full"`, … for a figure), the `"extent"`
to fit, and the texts: `"title"`, `"subtitle"`, `"sources"`, `"note"`, a `"locator"` (`"globe"`: the visible polygon layers held in the project, not streamed ones, over the basemap; `"inset"` or `"none"`; when omitted, `"globe"` on a sheet and `"none"` on a figure), and `"decimal": ","` for a map in a language with a decimal comma. A sheet's `"style"` arranges it: `"classic"` (the default), `"banner"`, `"panel"`, `"editorial"`, `"modular"` or `"poster"` (for a poster-like sheet), with an `"accent"` colour as `"#RRGGBB"`. Its
surrounds (locator, north arrow, legend, scale bar) start from an `"arrangement"` (`"classic"`, `"mirrored"`, `"legendRight"`, `"legendTop"`, or a corner for each; `"best"`, the default, tries the user's favourite, set with `layout.arrangement`, and the others), and one over the data moves to the freest place in the frame, the largest first (the legend, as a rule); read its `"arrangement"`, `"moved"` and `"warnings"`. It places the frame at a round scale, the
graticule, legend, scale bar and north arrow, and wraps the footer. Its result lists every element's id and name
graticule, legend (a long one in up to three columns), scale bar and north arrow, and wraps the footer. Its result lists every element's id and name
(`"elements"`), so skip to step 5 to adjust them. Otherwise,
`layout.new` `{"name": N, "page": "letter"|"a4"|…, "orientation": "landscape"|"portrait"}` creates the layout and
opens it.
Expand Down
261 changes: 228 additions & 33 deletions crates/engine/src/cmd/layout.rs

Large diffs are not rendered by default.

323 changes: 323 additions & 0 deletions crates/engine/src/tests.rs

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion crates/map/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,17 @@ fn divisions() -> usize {
4
}

/// The most columns a legend lays its rows in.
pub const MAX_LEGEND_COLUMNS: usize = 3;

fn one_column() -> usize {
1
}

fn is_one_column(columns: &usize) -> bool {
*columns == 1
}

fn ink() -> Rgba {
Rgba::rgb(0x22, 0x22, 0x22)
}
Expand Down Expand Up @@ -912,6 +923,10 @@ pub enum ElementKind {
/// highlight, a basemap-like layer. Empty, it lists every layer it would otherwise.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
exclude: Vec<String>,
/// The columns its rows are laid in, 1 to [`MAX_LEGEND_COLUMNS`], under its title: as even
/// as they can be, a layer's name staying with the row under it.
#[serde(default = "one_column", skip_serializing_if = "is_one_column")]
columns: usize,
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENTS.md / policy question (about 35% confidence, for maintainers): a new saved field without a format version change.

docs/maintaining.md says a format's version goes up when a file uses something an older reader would lose. A legend with "columns" is that case: an older RustGIS reads the legend in one column and drops the field on its next save. The PR body acknowledges this and says no version changes. The exclude field added the same way is the precedent, so this may be deliberate. Worth a maintainer's confirmation before merge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change here: this is for a maintainer, as you say. The field follows exclude (#518) and the text font family (#675), which were added as optional fields with no version change. By the letter of the rule it is a loss: an older RustGIS draws the legend in one column and drops the setting if it saves the file. No map data is lost. The PR text says this too. If a maintainer wants a version change here, I'll make it. Leaving this open for that view.

🤖 Addressed by Claude Code

},
/// The colour scale of a raster layer in a frame's map: a gradient bar for a stretch, steps
/// for classes, a block per value for unique values and colour tables (#326).
Expand Down Expand Up @@ -1318,10 +1333,11 @@ impl Layout {
g.width = finite_or(g.width, grid_width()).clamp(0.0, MAX_GRID_WIDTH);
}
}
ElementKind::Legend { exclude, .. } => {
ElementKind::Legend { exclude, columns, .. } => {
// Names stay whole: a layer's own name isn't cut, and a cut one would no
// longer match it.
exclude.truncate(MAX_LEGEND_EXCLUDED);
*columns = (*columns).clamp(1, MAX_LEGEND_COLUMNS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never silent (AGENTS.md, about 45% confidence): an out-of-range columns in a saved file is clamped with no notice.

The PR text says a value out of range in a hand-edited file "draws as the nearest". Layout::clamp runs on every layout at load (crates/engine/src/project.rs:800), so "columns": 999 becomes 3 and 0 becomes 1 with nothing said. AGENTS.md says a reader that approximates data must say what, how much and where, and that existing silent losses are bugs.

The other clamps in Layout::clamp are silent too, so this follows an existing pattern. Fixing it would mean Layout::clamp returning what it changed, and the project load passing that to Session::notify. That is larger than a one-line change, so I'm raising it as a question for maintainers rather than suggesting a fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change here: as you say, this is a question for maintainers. Every clamp in Layout::clamp is silent, so columns follows that pattern, and saying what a load changed would mean Layout::clamp returning it and the project load passing it to Session::notify, for all of them. That's better as its own change than as part of this PR. I'm leaving this open for a maintainer's view.

🤖 Addressed by Claude Code

}
ElementKind::Text { text, size, letter_spacing, .. } => {
*size = finite_or(*size, 12.0).clamp(*crate::graphics::FONT_SIZE.start(), *crate::graphics::FONT_SIZE.end());
Expand Down
490 changes: 437 additions & 53 deletions crates/render/src/layout.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/render/src/stream_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ fn layout_export_keeps_all_drawn_legend_classes() {
page.add(
"legend",
(90.0, 0.0, 45.0, 95.0),
ElementKind::Legend { frame, title: "classes".into(), all_classes: false, hide_other: false, exclude: vec![] },
ElementKind::Legend { frame, title: "classes".into(), all_classes: false, hide_other: false, exclude: vec![], columns: 1 },
);
let expected = layout::render(&page, &mut [base.clone()], 96.0, &layout::PageInfo::default()).unwrap();
for size in [1, 3, 20] {
Expand Down
4 changes: 2 additions & 2 deletions crates/render/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ mod tests {
layout.add(
"Legend",
(10.0, 10.0, 40.0, 30.0),
ElementKind::Legend { frame, title: "Map legend".into(), all_classes: true, hide_other: false, exclude: vec![] },
ElementKind::Legend { frame, title: "Map legend".into(), all_classes: true, hide_other: false, exclude: vec![], columns: 1 },
);
assert_eq!(picture_dpi(&layout, 600.0, |e| !written_as_svg(e)), 600.0);
// A frame and an inset filling an A0 page that is already drawn at its pixel limit.
Expand Down Expand Up @@ -371,7 +371,7 @@ mod tests {
let legend = layout.add(
"Legend",
(10.0, 10.0, 40.0, 30.0),
ElementKind::Legend { frame, title: "Map legend".into(), all_classes: true, hide_other: false, exclude: vec![] },
ElementKind::Legend { frame, title: "Map legend".into(), all_classes: true, hide_other: false, exclude: vec![], columns: 1 },
);
let info = PageInfo::default();
let (svg, pictured) = layout_svg(&layout, &mut maps, 72.0, &info).unwrap();
Expand Down
16 changes: 13 additions & 3 deletions crates/ui-egui/src/layoutview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use egui::{Align2, Color32, CornerRadius, CursorIcon, Pos2, Rect, Sense, Stroke, Ui, pos2, vec2};
use rustgis_engine::map::layout::{
Arrange, ArrowStyle, CoordFormat, ElementKind, Grid, GridKind, GridStyle, Layout, LineHead, MAX_COLORBAR_TICKS, MAX_FRAME_SCALE,
MAX_GRID_WIDTH, MAX_SCALE_DIVISIONS, MAX_TICK_MM, MIN_FRAME_SCALE, Orientation, PT_PER_MM, ScaleBarStyle, ScaleUnits, TickSide,
frame_camera, line_angle, line_length,
MAX_GRID_WIDTH, MAX_LEGEND_COLUMNS, MAX_SCALE_DIVISIONS, MAX_TICK_MM, MIN_FRAME_SCALE, Orientation, PT_PER_MM, ScaleBarStyle,
ScaleUnits, TickSide, frame_camera, line_angle, line_length,
};
use serde_json::{Value, json};

Expand Down Expand Up @@ -1564,7 +1564,7 @@ fn properties(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout, li: usize) {
match &e.kind {
// Its text, size, colour and boldness: the shared form, below the grid.
ElementKind::Text { .. } => {}
ElementKind::Legend { title, all_classes, hide_other, .. } => {
ElementKind::Legend { title, all_classes, hide_other, columns, .. } => {
let input_label = ui.label(tl!("Title"));
if let Some(tt) = text_field(app, ui, (li, id, "title"), title, false, input_label.id) {
update(app, json!({"title": tt}));
Expand All @@ -1583,6 +1583,16 @@ fn properties(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout, li: usize) {
update(app, json!({"hideOther": hide}));
}
ui.end_row();
let input_label = ui.label(tl!("Columns"));
let mut n = *columns as u64;
let drag = Dragged::lend(ui, drag_key("columns"), &mut n);
let r = ui
.add(egui::DragValue::new(&mut n).update_while_editing(false).range(1..=MAX_LEGEND_COLUMNS as u64))
.labelled_by(input_label.id);
if drag.settled(ui, &r, &mut n) && n as usize != *columns {
update(app, json!({"columns": n}));
}
ui.end_row();
}
ElementKind::Colorbar { frame, layer, title, orientation, ticks, tick_side, reverse } => {
let input_label = ui.label(tl!("Title"));
Expand Down
18 changes: 15 additions & 3 deletions docs/user-guide/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu
alike, such as a context layer filling the frame, isn't worth a warning); two that overlap (a
frame too small) are said too.
The top visible raster gets a colorbar beneath the vector legend if its renderer has a colour
scale; RGB and untinted hillshade do not. If the legend or colorbar cannot fit, the result
warns about clipping or resizing. A streamed layer still loading gets a fixed-size legend
to adjust by hand.
scale; RGB and untinted hillshade do not. The legend takes the fewest columns, up to three,
that fit the largest rectangle the map leaves free; when none fits, a long one is laid in more
when that shows more of it, or as much while covering at least a quarter less of what the map
draws (the answer's `legendColumns`); in a side column it stays in one. Polygon layers with no
fill and no labels, such as neighbouring borders, don't count as what the map draws here, unless
nothing else is shown. If the legend or colorbar cannot fit, the result warns about clipping or
resizing. A streamed layer still loading gets a fixed-size legend to adjust by hand.
- **Decimal comma**: `"decimal": ","` prints the graticule, scale bar and colorbar numbers and
`{scale}` with a decimal comma and points between thousands (`0,05`, `1:6.300.000`).
`layout.page={"decimal": ","}` sets it on any layout; `"."` restores decimal points.
Expand Down Expand Up @@ -166,6 +170,14 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu
(`"allClasses": true`) to list every class of every visible layer instead, and **Hide other
values** (`"hideOther": true`) to leave `<all other values>` out of the legend in either
mode (the features it stands for are still drawn).
- **Columns** (`"columns"`, 1 to 3): its rows side by side under its title, as even as they go,
each column as wide as its widest row, with its own column of symbols, and a layer's name
staying with the row under it. The box keeps its size, so widen it for the columns: in a box
too narrow they close up and long labels run into the next or past the box, and a box too
short fills each column in turn and leaves out the last rows.
Giving `"columns"`, or changing the box or what a legend in columns lists, says when its box
loses rows or closes the columns up. A legend in one column is told so only when given
`"columns"`.
- **Point symbols**: a point layer's symbol is drawn as the map draws it: its marker or the
stacked marks of its class or layer, its size and outline, the transparency of the layer and
its groups, and its reference scale at the frame's scale, unturned. A row has one symbol, so
Expand Down
Loading