From 9659b884e59d5f7686413c052bc8c7f6abbd4cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 22:12:05 -0500 Subject: [PATCH 1/5] feat(layout): rename a class in one legend without changing the layer (#3187) --- crates/assistant/skills/print-layout/SKILL.md | 3 +- crates/engine/command-surface.txt | 4 +- crates/engine/src/cmd/layer.rs | 21 +- crates/engine/src/cmd/layout.rs | 11 +- crates/engine/src/cmd/layout/elements.rs | 8 + crates/engine/src/cmd/layout/inputs.rs | 25 ++- crates/engine/src/cmd/layout/legend.rs | 121 ++++++++++- .../engine/src/cmd/layout/publication/mod.rs | 1 + .../src/cmd/layout/publication/parts.rs | 1 + crates/engine/src/cmd/layout/update.rs | 16 ++ crates/engine/src/project.rs | 1 + crates/engine/src/project_capabilities.rs | 25 +++ crates/engine/src/tests.rs | 12 ++ crates/engine/src/tests/layout_files.rs | 1 + .../src/tests/layout_legend_class_labels.rs | 193 ++++++++++++++++++ crates/map/src/layout.rs | 3 +- crates/map/src/layout/elements.rs | 9 + crates/map/src/layout/legend.rs | 93 +++++++++ crates/map/src/layout/tests.rs | 43 ++++ crates/render/src/layout.rs | 3 + crates/render/src/layout/legend.rs | 44 +++- crates/render/src/layout/tests.rs | 92 ++++++++- crates/render/src/stream_tests.rs | 1 + crates/render/src/svg.rs | 2 + docs/maintaining.md | 7 + docs/user-guide/layouts.md | 12 +- .../fixtures/layout_legend_class_labels.rgis | 25 +++ schema/project.schema.json | 2 + 28 files changed, 749 insertions(+), 30 deletions(-) create mode 100644 crates/engine/src/tests/layout_legend_class_labels.rs create mode 100644 schema/fixtures/layout_legend_class_labels.rgis diff --git a/crates/assistant/skills/print-layout/SKILL.md b/crates/assistant/skills/print-layout/SKILL.md index 0c6ce92bab..111debf2ad 100644 --- a/crates/assistant/skills/print-layout/SKILL.md +++ b/crates/assistant/skills/print-layout/SKILL.md @@ -26,7 +26,8 @@ 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) and `"showLayerNames": false`. A `"text"` or `"dynamicText"` can take + text or add columns to fit its box), `"showLayerNames": false` and `"classLabels"` + (`{"": {"": ""}}`: its own text for a class, the layer keeping its label). A `"text"` or `"dynamicText"` can take `"valign"` (`"top"`, `"middle"`, `"bottom"`), `"lineSpacing"` (0.5–3, default 1) and `"case"` (`"none"`, `"upper"`, `"lower"`; applied when drawn, the text kept as typed). `"grid"` adds a graticule to the frame (`"style": "ticks"` for neatline ticks, `"format": "dms"`, `"edges"`). diff --git a/crates/engine/command-surface.txt b/crates/engine/command-surface.txt index e6536a90df..a7f81f0b6a 100644 --- a/crates/engine/command-surface.txt +++ b/crates/engine/command-surface.txt @@ -282,7 +282,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? allClasses? hideOther? showNoData? exclude? columns? textSize? 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? 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? allClasses? hideOther? showNoData? exclude? columns? textSize? classLabels? 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? 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? @@ -304,7 +304,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? allClasses? hideOther? showNoData? exclude? labels? columns? textSize? showLayerNames? 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? 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? allClasses? hideOther? showNoData? exclude? labels? classLabels? columns? textSize? showLayerNames? 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? 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? diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 6476664b15..c5d55e0d74 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -7326,7 +7326,7 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str> } let shared = new.is_some_and(|n| named(s, n) > 1); let map = s.map().name.clone(); - let mut unlabelled = 0usize; + let (mut unlabelled, mut unclassed) = (0usize, 0usize); for layout in &mut s.project.layouts { let frames: Vec = layout .elements @@ -7335,7 +7335,7 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str> .map(|e| e.id) .collect(); for e in &mut layout.elements { - if let rustgis_map::layout::ElementKind::Legend { frame, exclude, labels, .. } = &mut e.kind + if let rustgis_map::layout::ElementKind::Legend { frame, exclude, labels, class_labels, .. } = &mut e.kind && frames.contains(frame) { // Its label (#1654), taken off the old name; onto the new one unless another layer @@ -7350,6 +7350,17 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str> (Some(_), Some(_), true) => unlabelled += 1, _ => {} } + // Its classes' labels (#3187) go the same way. + let keys: Vec = class_labels.by_layer.keys().filter(|n| n.eq_ignore_ascii_case(old)).cloned().collect(); + let classes = keys.iter().filter_map(|k| class_labels.by_layer.remove(k)).last(); + match (new, classes, shared) { + (Some(n), Some(c), false) => { + class_labels.by_layer.retain(|x, _| !x.eq_ignore_ascii_case(n)); + class_labels.by_layer.insert(n.to_string(), c); + } + (Some(_), Some(_), true) => unclassed += 1, + _ => {} + } match new { // Another layer the legend lists bears the new name: carrying the exclusion // over would take that one out too, so the renamed layer is listed with it. @@ -7373,6 +7384,12 @@ pub(crate) fn legends_follow_layer(s: &mut Session, old: &str, new: Option<&str> } } } + if let Some(n) = new.filter(|_| unclassed > 0) { + s.notify( + format!("'{old}', renamed '{n}', lost its class labels in {unclassed} legend(s): another layer is called '{n}', and a legend labels layers by name"), + false, + ); + } // The text given for the layer goes while the layer stays: said. (A removed layer's goes // with its row.) if let Some(n) = new.filter(|_| unlabelled > 0) { diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index d0aa917e5e..6baab270b7 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -7,10 +7,10 @@ use std::sync::LazyLock; use rustgis_geom::{Coord, Extent}; use rustgis_map::layout::{ - Arrange, ArrowStyle, Background, CHART_BAR, CHART_BARS, CHART_OUTLINE, ChartOrder, ChartOutline, CoordFormat, ElementKind, 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, + Arrange, ArrowStyle, Background, CHART_BAR, CHART_BARS, CHART_OUTLINE, ChartOrder, ChartOutline, ClassLabels, CoordFormat, ElementKind, + 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, @@ -206,6 +206,7 @@ pub fn commands() -> Vec { r##""exclude"?: [layer names] (legend: layers it leaves out though the map draws them), "##, 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"?: {"": {"": ""}} (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##""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), "##, r##""ticks"?: 2..21 (colorbar: labelled values, ends included), "##, @@ -304,6 +305,7 @@ pub fn commands() -> Vec { r##""showNoData"?: bool (legend; default false), "##, r##""exclude"?: [layer names] (legend; [] lists every layer again), "##, r##""labels"?: {"": "