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/src/cmd/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ mod tests {
"1 diagram(s) that could not be read or named no field removed",
"1 diagram category(ies) with a blank field name",
"1 diagram category(ies) repeating an earlier field kept",
"1 layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference or a background on a map frame repaired while opening the project (in \"Poster\")",
"1 layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference, a repeated extent indicator or a background on a map frame repaired while opening the project (in \"Poster\")",
] {
assert!(said.iter().any(|t| t.contains(text)), "{text}: {said:?}");
}
Expand Down
13 changes: 7 additions & 6 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,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, ClassLabels, CoordFormat, ElementKind,
FeatureCounts, FontFamily, FrameShape, GRID_LABEL_PT, Grid, GridEdges, GridKind, GridStyle, Guides, LAYOUT_TEXT_SIZE, LINE_SPACING,
LayerNames, Layout, LegendFit, LegendSizes, 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,
ExtentIndicator, FeatureCounts, FontFamily, FrameShape, GRID_LABEL_PT, Grid, GridEdges, GridKind, GridStyle, Guides, LAYOUT_TEXT_SIZE,
LINE_SPACING, LayerNames, Layout, LegendFit, LegendSizes, 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, TABLE_TEXT_PT, TextAlign, TextCase, TextVAlign, TickSide, UnitLabelPosition,
fit_scale, line_angle, line_at_angle, line_length,
Expand Down Expand Up @@ -195,7 +195,7 @@ pub fn commands() -> Vec<C> {
r##"{"layout"?, "##,
r##""kind": "northArrow"|"scaleBar"|"legend"|"colorbar"|"text"|"dynamicText"|"picture"|"table"|"chart"|"rectangle" (a neatline framing the page unless any of x, y, w, h is given)|"ellipse"|"circle"|"line"|"arrow"|"extentIndicator"|"grid"|"section" (a section line over a map frame, named at both ends, A and A', up to 26 a frame; as a grid or an extentIndicator, it adds no element: the reply's "element" is its frame, the one layout.update changes it on with "section", and "section" its name)|"profile" (a raster's profile along a section line of the frame, beside the frame on the side the line runs along, lined up with it: each sample is read at its point of the page line, through the frame's projection, so the curve is straight across from the place it comes from; its box is the frame's side, which it follows when the frame is moved or resized; a tilted frame, one on the globe, or a raster read in place draws none, which a notice and exports say), "##,
r##""frame"?: element id (default: the first map frame), "##,
r##""of"?: frame id (extentIndicator, which also takes "color" and "width" in points, default red and 2), "##,
r##""of"?: frame id (extentIndicator: the frame to outline, with "color" and "width" in points, default red and 2, or for a frame's first one the look it kept from indicators removed; a frame outlines up to 16 others, and giving one it outlines already restyles that outline), "##,
r##""text"? (a text's words; {count:Layer}, {sum:Layer:field}, {mean:Layer:field}, {min:Layer:field} and {max:Layer:field} show the layer's figure, as {scale} shows the scale: of the first map frame's map, over the features the layer's definition query keeps, with the layout's decimal mark; one with no figure shows as written and says why), "##,
r##""size"?, "##,
r##""color"?: "#RRGGBB"|"#RRGGBBAA" (text, dynamicText, line, arrow, rectangle, ellipse, circle: its outline; extentIndicator; grid; section, default #A8431F; scaleBar; legend, colorbar, table, chart, profile: the ink of its text and lines, default #222222, a chart's bars and a colorbar's colours keeping theirs, and a table drawn without its white cells; refused for other kinds), "##,
Expand Down Expand Up @@ -368,7 +368,7 @@ pub fn commands() -> Vec<C> {
r##""bearing"?: degrees clockwise from north, "##,
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"?: {"color"?, "width"?: points} | false (map frame: its extent indicator's style, or removes it), "##,
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##""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 @@ -601,6 +601,7 @@ fn frame_kind(s: &Session, map: &str, w: f64, shape: FrameShape) -> ElementKind
extent_of: None,
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing,
Expand Down
40 changes: 29 additions & 11 deletions crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,11 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
return Err("of must be another map frame".into());
}
unlocked(l, frame)?;
let (color, width) = indicator_style(p, l.element(frame).map(|e| &e.kind))?;
let kind = &l.element(frame).ok_or_else(|| format!("no element {frame}"))?.kind;
let indicators = with_indicator(kind, of, p)?;
let l = active(s, p)?;
if let Some(ElementKind::MapFrame { extent_of, extent_color, extent_width, .. }) = l.element_mut(frame).map(|e| &mut e.kind) {
*extent_of = Some(of);
*extent_color = color;
*extent_width = width;
if let Some(e) = l.element_mut(frame) {
e.kind.set_extent_indicators(indicators);
}
let range = (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH);
say_held(s, "Add Element", held_width(p, "extent indicator width", range).into_iter().collect());
Expand Down Expand Up @@ -825,14 +824,33 @@ pub(in crate::cmd::layout) fn ticks(p: &Value) -> Result<Option<usize>, String>
}

/// An extent indicator's outline colour and width (points) from `color` and `width` in `p`, each
/// keeping the frame's (`kind`) when not given; one given but not a colour or a number is an
/// error, not left as it was.
pub(in crate::cmd::layout) fn indicator_style(p: &Value, kind: Option<&ElementKind>) -> Result<(Rgba, f64), String> {
let current = match kind {
Some(ElementKind::MapFrame { extent_color, extent_width, .. }) => (*extent_color, *extent_width),
/// keeping `current`'s when not given; one given but not a colour or a number is an error, not
/// left as it was.
pub(in crate::cmd::layout) fn indicator_style(p: &Value, current: (Rgba, f64)) -> Result<(Rgba, f64), String> {
outline_style(p, current, (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH))
}

/// A map frame's extent indicators with `of` outlined as `p` says: restyled when outlined
/// already, else added after the others (#3394).
fn with_indicator(kind: &ElementKind, of: u32, p: &Value) -> Result<Vec<ExtentIndicator>, String> {
let mut list = kind.extent_indicators();
let at = list.iter().position(|i| i.of == of);
if at.is_none() && list.len() >= rustgis_map::layout::MAX_EXTENT_INDICATORS {
return Err(format!("a map frame outlines at most {} other frames", rustgis_map::layout::MAX_EXTENT_INDICATORS));
}
let current = match (at.and_then(|i| list.get(i)), kind) {
(Some(i), _) => (i.color, i.width),
// A frame's first keeps the look of one removed before it.
(None, ElementKind::MapFrame { extent_color, extent_width, .. }) if list.is_empty() => (*extent_color, *extent_width),
_ => (rustgis_map::layout::INDICATOR_COLOR, rustgis_map::layout::INDICATOR_WIDTH),
};
outline_style(p, current, (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH))
let (color, width) = indicator_style(p, current)?;
let new = ExtentIndicator { of, color, width };
match at.and_then(|i| list.get_mut(i)) {
Some(i) => *i = new,
None => list.push(new),
}
Ok(list)
}

/// A map frame's border colour and width (points, 0 for none) from `color` and `width` in `p`,
Expand Down
5 changes: 4 additions & 1 deletion crates/engine/src/cmd/layout/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ pub(in crate::cmd::layout) fn close_inputs(input: &crate::cmd::InputContext<'_>,
/// Stored surround references consumed by rendering or validation, kept as private selector text.
pub(in crate::cmd::layout) fn element_selectors(kind: &ElementKind) -> Option<Value> {
Some(match kind {
ElementKind::MapFrame { map, extent_of, .. } => json!({"map":map,"extentOf":extent_of}),
ElementKind::MapFrame { map, .. } => {
let of: Vec<u32> = kind.extent_indicators().iter().map(|i| i.of).collect();
json!({"map":map,"extentOf":of})
}
ElementKind::Table { frame, layer, .. } => json!({"frame":frame,"layer":layer}),
ElementKind::Chart { frame, layer, field, label, group, stack, .. } => {
json!({"frame":frame,"layer":layer,"field":field,"label":label,"group":group,"stack":stack})
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 @@ -1096,6 +1096,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
extent_of: None,
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
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 @@ -1960,6 +1961,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
extent_of: Some(target),
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
Expand Down
70 changes: 41 additions & 29 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ use super::*;
/// A scale bar's keys beyond its details ([`SCALE_BAR_KEYS`]).
pub(in crate::cmd::layout) const SCALE_BAR_LOOK_KEYS: [&str; 7] = ["style", "units", "divisions", "color", "fill", "textSize", "decimals"];

/// A map frame's extent indicators with the one the object `v` names restyled, or removed with
/// `"remove": true`. `of` is the frame it outlines; left out, the frame's only one (#3394).
fn changed_indicators(kind: &ElementKind, v: &Value) -> Result<Vec<ExtentIndicator>, String> {
let mut list = kind.extent_indicators();
if list.is_empty() {
return Err("this frame has no extent indicator: add one with layout.addElement (kind extentIndicator)".into());
}
let remove = match v.get("remove") {
None | Some(Value::Null) => false,
Some(Value::Bool(b)) => *b,
Some(_) => return Err("remove is true or false".into()),
};
let at = match v.get("of").filter(|of| !of.is_null()) {
Some(of) => {
let of = of.as_u64().ok_or("of is the id of a frame this one outlines")?;
list.iter().position(|i| u64::from(i.of) == of).ok_or_else(|| format!("this frame doesn't outline {of}"))?
}
None if list.len() == 1 => 0,
None => return Err(format!("this frame outlines {} frames: say which with of", list.len())),
};
if let Some(i) = list.get_mut(at) {
// Read before a removal too: a bad colour or width is refused either way.
(i.color, i.width) = indicator_style(v, (i.color, i.width))?;
}
if remove {
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
list.remove(at);
}
Ok(list)
}

/// A north arrow or scale bar with the options in `p` over `kind`'s; `None` for other elements
/// or when `p` has none. A bad value is an error, leaving nothing changed.
pub(in crate::cmd::layout) fn restyle(kind: &ElementKind, p: &Value) -> Result<Option<ElementKind>, String> {
Expand Down Expand Up @@ -243,14 +273,12 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
let (restyled, new_grid, new_indicator, 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 indicator away; an object restyles it.
// `"extentIndicator": false` takes the frame's indicators away; an object restyles or
// removes one.
let indicator = match (kind, p.get("extentIndicator").filter(|v| !v.is_null())) {
(ElementKind::MapFrame { .. }, Some(Value::Bool(false))) => Some(None),
(ElementKind::MapFrame { extent_of: Some(_), .. }, Some(v @ Value::Object(_))) => Some(Some(indicator_style(v, Some(kind))?)),
(ElementKind::MapFrame { .. }, Some(Value::Object(_))) => {
return Err("this frame has no extent indicator: add one with layout.addElement (kind extentIndicator)".into());
}
(ElementKind::MapFrame { .. }, Some(_)) => return Err("extentIndicator is an object of color and width, or false".into()),
(ElementKind::MapFrame { .. }, Some(Value::Bool(false))) => Some(Vec::new()),
(ElementKind::MapFrame { .. }, Some(v @ Value::Object(_))) => Some(changed_indicators(kind, v)?),
(ElementKind::MapFrame { .. }, Some(_)) => return Err("extentIndicator is an object, or false".into()),
(_, Some(_)) => return Err("only map frames have an extent indicator".into()),
_ => None,
};
Expand Down Expand Up @@ -289,8 +317,8 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
if let (Some((_, Some(_))), Some(v)) = (&sections, p.get("section")) {
said.extend(held_width(v, "section width", rustgis_map::layout::SECTION_WIDTHS));
}
if let (ElementKind::MapFrame { .. }, Some(Some(_))) = (kind, &indicator)
&& let Some(v) = p.get("extentIndicator")
if let (ElementKind::MapFrame { .. }, Some(v @ Value::Object(_))) = (kind, p.get("extentIndicator"))
&& v.get("remove") != Some(&Value::Bool(true))
{
let range = (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH);
said.extend(held_width(v, "extent indicator width", range));
Expand Down Expand Up @@ -598,6 +626,9 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
(*dir, *head) = (d, hd);
}
}
if let Some(indicators) = new_indicator {
e.kind.set_extent_indicators(indicators);
}
match &mut e.kind {
ElementKind::Text {
text,
Expand Down Expand Up @@ -726,29 +757,10 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
*reverse = v;
}
}
ElementKind::MapFrame {
map,
center,
scale,
grid,
bearing,
pitch,
extent_of,
extent_color,
extent_width,
border_color,
border_width,
sections,
..
} => {
ElementKind::MapFrame { map, center, scale, grid, bearing, pitch, border_color, border_width, sections, .. } => {
if let Some((new, _)) = &new_sections {
sections.clone_from(new);
}
match new_indicator {
Some(None) => *extent_of = None,
Some(Some((c, w))) => (*extent_color, *extent_width) = (c, w),
None => {}
}
if let Some((c, w)) = new_border {
(*border_color, *border_width) = (c, w);
}
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 @@ -413,6 +413,7 @@ pub fn page_layout(s: &Session, pres: &Presentation, page: &Page) -> Layout {
extent_of: None,
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
more_extents: Vec::new(),
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
Expand Down
5 changes: 3 additions & 2 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub const CAPABILITIES: &[&str] = &[
"layout-legend-counts",
"layout-legend-subtitle",
"layout-legend-nested-sizes",
"layout-extent-indicators",
"layout-legend-order",
"layout-picture-source",
"layout-scale-bar-details",
Expand Down Expand Up @@ -2830,14 +2831,14 @@ pub(crate) fn layout_notices(
let adjusted = total(|r| r.elements_adjusted);
if adjusted > 0 {
notices.push(format!(
"{name}: {adjusted} layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference or a background on a map frame repaired {when} (in {})",
"{name}: {adjusted} layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference, a repeated extent indicator or a background on a map frame repaired {when} (in {})",
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
layout_names(repairs, |r| r.elements_adjusted)
));
}
let cut = total(|r| r.elements_cut);
if cut > 0 {
notices.push(format!(
"{name}: {cut} layout element(s) with a name, text, polygon points, section lines, legend exclusions, scale bar unit labels or legend labels cut to their limits {when} (in {})",
"{name}: {cut} layout element(s) with a name, text, polygon points, section lines, extent indicators, legend exclusions, scale bar unit labels or legend labels cut to their limits {when} (in {})",
layout_names(repairs, |r| r.elements_cut)
));
}
Expand Down
Loading
Loading