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 @@ -296,7 +296,7 @@ layout.import path? text?
layout.move name? layout? to
layout.new name? page? orientation? width? height? template?
layout.page layout? page? orientation? width? height? decimal? color?
layout.publication profile? extent? name? title? subtitle? sources? reference? note? author? headings? locator? decimal? colorbar? veil? contextInLegend? northArrow? grid? scaleBar? legendBox? style? paper? kicker? figures? accent? arrangement? coverage?
layout.publication profile? extent? name? title? subtitle? sources? reference? note? author? headings? locator? decimal? colorbar? veil? contextInLegend? northArrow? grid? scaleBar? legend? legendBox? style? paper? kicker? figures? accent? arrangement? coverage?
layout.remove name? layout?
layout.removeElement layout? element
layout.rename name? layout? newName
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn commands() -> Vec<C> {
r#""northArrow"?: "auto" (the default: none when the extent spans 20° or more on its longer side, where the graticule gives north, which a warning says) | "always" | "none" | {"show"?: "auto" | "always", "style"?, "fill"?, "outline"? as layout.update takes a north arrow's}, "#,
r#""grid"?: "none" (no grid on the map frame, and no label strips inside it) | {a frame grid's options as layout.addElement takes them: type, crs, step, short, mgrs, color, width, labels, labelSize, style, tickLength, format, hemisphere, edges, labelOrientation; a graticule takes no crs, short or mgrs, a measured grid no format or hemisphere} over the default graticule (its step by the extent, labelled left and bottom, on a sheet all round); the label strips follow its labels, edges and labelSize (in points as given, not scaled with the sheet), and without a graticule the default reference names none and {grid} in a text reads "—", "#,
r#""scaleBar"?: "none" | {a scale bar's options as layout.update takes them: style, units, divisions, color, fill, textSize, decimals, subdivisions, divisionsBeforeZero, labelPosition, unitLabel, unitLabelPosition, fit; textSize in points as given, not scaled with the sheet} (none on a globe shown whole, whatever is asked), "#,
r#""legend"?: "none" (no legend; a colorbar keeps its box, and the answer's "legendColumns" is null) | {"title"?: text, "columns"?: 1 to 6 (that many; the placement picks 1 to 3 otherwise), "exclude"?: [layer names] (left out besides the context ones)}, "#,
r#""legendBox"?: "auto" (the default: over the map, the legend has no box where the map shows nothing under it but its light plain paper or water, with no layer, context, basemap shape or graticule line there and no veil; the answer's "legendBox" says whether it has one) | "always", "#,
r#""style"?: "classic" (the default: the title over the map, the footer under it) | "banner" (the title and subtitle in a band of the accent colour across the top) | "panel" (the map at the left, a panel at the right with the title, locator, legend, sources and reference) | "editorial" (the title large in serif, a column at the right with the note, the locator and the legend) | "modular" (cards on a light page: the map, the locator and the legend each in one, the sources and reference in tinted ones) | "poster" (the page in the accent colour, the title in light text, the map in a light card, the footer in darker blocks) | "edge" (the map from one side of the page to the other with no border, a kicker and the title over it, the footer with no boxes under a thin rule) (a sheet's arrangement; figures leave it to the caption), "#,
r##""paper"?: "#RRGGBB" (an edge sheet's page colour, as layout.page's "color"; white by default; on a dark one its texts are light), "##,
Expand Down
8 changes: 6 additions & 2 deletions crates/engine/src/cmd/layout/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,15 @@ pub(in crate::cmd::layout) fn legend_exclude(
p: &Value,
) -> Result<Option<Vec<String>>, String> {
let Some(v) = p.get("exclude").filter(|v| !v.is_null()) else { return Ok(None) };
excluded_layers(legend_map(input, l, frame)?, v).map(Some)
}

/// The layers of `map` that `v`, a legend's `exclude`, names, as the map spells them, each once.
pub(in crate::cmd::layout) fn excluded_layers(map: &Map, v: &Value) -> Result<Vec<String>, String> {
let names = v.as_array().ok_or("exclude is a list of layer names")?;
if names.len() > rustgis_map::layout::MAX_LEGEND_EXCLUDED {
return Err(format!("a legend leaves out at most {} layers", rustgis_map::layout::MAX_LEGEND_EXCLUDED));
}
let map = legend_map(input, l, frame)?;
let mut out: Vec<String> = Vec::new();
for n in names {
let n = n.as_str().ok_or("exclude is a list of layer names")?;
Expand All @@ -363,7 +367,7 @@ pub(in crate::cmd::layout) fn legend_exclude(
out.push(name.clone());
}
}
Ok(Some(out))
Ok(out)
}

/// The map a legend's frame shows.
Expand Down
114 changes: 68 additions & 46 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let may_veil = publication_veil(p)?;
let context_in_legend = publication_flag(p, "contextInLegend")?.unwrap_or(false);
let (north_arrow, mut arrow_kind) = publication_north_arrow(p)?;
let legend = publication_legend(p, s.map())?;
let legend_box_always = publication_legend_box(p)?;
// A style or an accent that isn't text is refused, as an unknown one is, rather than left out.
for k in ["style", "accent"] {
Expand Down Expand Up @@ -1135,18 +1136,24 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
// placement already sets aside, is left out of the legend too, unless "contextInLegend" (#1379).
// It is judged again at each other scale the search below draws the map at, as the placement
// judges it there, and the legend takes the one at the scale settled on.
// Those "legend" already asks to leave out aren't among them, so the warning doesn't offer to
// list them; without a legend there are none.
let context_at = |s: &Session, center: Coord, scale: f64| {
if context_in_legend { Vec::new() } else { legend_context(s.map(), center, scale, (fw, fh)) }
let Some(legend) = legend.as_ref().filter(|_| !context_in_legend) else { return Vec::new() };
let mut context = legend_context(s.map(), center, scale, (fw, fh));
context.retain(|c| !legend.exclude.iter().any(|n| n.eq_ignore_ascii_case(c)));
context
};
// The legend's sizes at a render scale: nothing without one.
let legend_sizes = |s: &mut Session, scale: f64, context: &[String]| match &legend {
None => Some([(0.0, 0.0); PUBLICATION_LEGEND_COLUMNS]),
Some(legend) => legend.sizes(s.map_mut(), scale, context, legend_pt),
};
// Whether a legend picture still loading keeps its size at a render scale unknown.
let pictures_pending =
|s: &Session, scale: f64| legend.as_ref().is_some_and(|l| crate::render::layout::tile_legends_pending(s.map(), scale, &l.exclude));
let mut context = context_at(s, center, scale);
let mut sizes = crate::render::layout::legend_sizes_in_columns_mm::<PUBLICATION_LEGEND_COLUMNS>(
s.map_mut(),
render_scale,
false,
false,
(false, legend_pt),
(&context, &Default::default()),
);
let mut sizes = legend_sizes(s, render_scale, &context);
let (mut cw, mut ch) = match sizes {
Some(sizes) => sizes[0],
None => {
Expand All @@ -1155,12 +1162,16 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
(fw * 0.3, fh * 0.25)
}
};
let listed = s.map().layers.iter().any(|l| s.map().shows(l) && crate::render::layout::legend_lists(l));
// Whether a layer the legend isn't asked to leave out may have rows in it.
let listed = legend.as_ref().is_some_and(|legend| {
let asked_out = |name: &str| legend.exclude.iter().any(|n| n.eq_ignore_ascii_case(name));
s.map().layers.iter().any(|l| s.map().shows(l) && crate::render::layout::legend_lists(l) && !asked_out(&l.name))
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
});
if reading && listed {
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
(cw, ch) = (cw.max(fw * 0.3), ch.max(fh * 0.25));
sizes = None;
warnings.push("the legend's classes aren't known yet (a layer still reading): it has a fixed size to fit by hand".into());
} else if crate::render::layout::tile_legends_pending(s.map(), render_scale, &[]) {
} else if pictures_pending(s, render_scale) {
// Not waited for: a slow legend server would hold the command up.
(cw, ch) = (cw.max(fw * 0.3), ch.max(fh * 0.25));
sizes = None;
Expand Down Expand Up @@ -1226,7 +1237,10 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
}
// A colour table whose values can't be known (too many to list) gives the legend no class, and
// the sheet no key for it; classes from an overview may miss a rare one: said, not left out.
warnings.extend(raster_key_notices(s.map(), &[], false));
// Of the rasters the legend keys: none without one.
if let Some(legend) = &legend {
warnings.extend(raster_key_notices(s.map(), &legend.exclude, false));
}
// A page of cards gives the locator in its column a card of the column's width, and the legend
// under it one as wide.
let card = style == Style::Modular && column.is_some();
Expand Down Expand Up @@ -1412,28 +1426,20 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let reading =
s.map_mut().sync_sources_in(&lonlat, own.as_ref(), render_scale, true, &rustgis_data::query::Env::default());
let here_context = if tried == asked_scale { context.clone() } else { context_at(s, centred, tried) };
let here =
if reading || (tried != asked_scale && crate::render::layout::tile_legends_pending(s.map(), render_scale, &[])) {
let here = if reading || (tried != asked_scale && pictures_pending(s, render_scale)) {
unknown_at.get_or_insert(tried);
None
} else if tried == asked_scale {
Some(known)
} else {
// A legend that can't be measured there (a source that can't be read
// through) leaves that scale untried too, which is said.
let measured = legend_sizes(s, render_scale, &here_context);
if measured.is_none() {
unknown_at.get_or_insert(tried);
None
} else if tried == asked_scale {
Some(known)
} else {
// A legend that can't be measured there (a source that can't be read
// through) leaves that scale untried too, which is said.
let measured = crate::render::layout::legend_sizes_in_columns_mm::<PUBLICATION_LEGEND_COLUMNS>(
s.map_mut(),
render_scale,
false,
false,
(false, legend_pt),
(&here_context, &Default::default()),
);
if measured.is_none() {
unknown_at.get_or_insert(tried);
}
measured
};
}
measured
};
let cells = (384.0 * wide.0.max(wide.1) / fw.max(fh)).round() as u32;
// What is context is judged on the frame asked for, not the wide drawing, so
// every move's cut leaves out the same layers.
Expand Down Expand Up @@ -1514,14 +1520,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
*here
} else {
let at_there = crate::render::layout::frame_render_scale(s.map(), there, tried);
let measured = crate::render::layout::legend_sizes_in_columns_mm::<PUBLICATION_LEGEND_COLUMNS>(
s.map_mut(),
at_there,
false,
false,
(false, legend_pt),
(&own_context, &Default::default()),
);
let measured = legend_sizes(s, at_there, &own_context);
// A legend that can't be measured there leaves that move untried, which is
// said, as at a scale.
let Some(measured) = measured else {
Expand Down Expand Up @@ -1786,6 +1785,10 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
.collect();
arrangement_used = "veil".into();
}
// A legend asked for some columns takes them, whichever of the equal sizes was picked.
if let Some(columns) = legend.as_ref().and_then(|l| l.columns) {
legend_cols = columns;
}
if let Some(ElementKind::MapFrame { center: at, scale: drawn_at, .. }) = l.element_mut(frame).map(|e| &mut e.kind) {
(*at, *drawn_at) = (center, scale);
}
Expand Down Expand Up @@ -1820,6 +1823,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
.into(),
);
}
if ch <= 0.0 && legend.as_ref().is_some_and(|l| !l.title.is_empty()) {
warnings.push("the legend lists nothing, so it is left out, its title with it".into());
}
let mut placed: Vec<(&'static str, (f64, f64, f64, f64))> = Vec::new();
let spot_of = |what: Surround| spots.iter().find(|(kind, _)| *kind == what).map(|(_, r)| *r);
// In a column, at its top, centred across it; otherwise in its corner over the map.
Expand Down Expand Up @@ -1911,7 +1917,23 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let bar_need = bar.as_deref().map_or(0.0, |title| colorbar_mm(title, iw));
let bar_fit = colorbar_fit(bar_need, ih, ch + bar_gap, over_map);
let rows_h = (ih - bar_fit - if bar.is_some() { bar_gap } else { 0.0 }).max(0.0);
warnings.extend(legend_fit_warnings(LegendFit::Manual, legend_cols, overflows((cw, ch), (iw, rows_h))));
let (mut too_wide, too_tall) = overflows((cw, ch), (iw, rows_h));
// A title wider than the box is named: the width past it is the title's, unless the rows
// are wider still.
let title = legend.as_ref().map(|l| l.title.as_str()).filter(|t| ch > 0.0 && !t.is_empty());
let title_w = title.map_or(0.0, |t| crate::render::layout::legend_title_width_mm(t, legend_pt));
if title_w > iw + LEGEND_FIT_MM {
warnings.push("the legend's title is wider than its box: shorten it".into());
// `cw` holds the title's width too: where the title is the widest, the rows are
// measured on their own. Rows of unknown size aren't said to be wider.
if let Some(legend) = legend.as_ref().filter(|_| cw <= title_w + LEGEND_FIT_MM) {
let at = crate::render::layout::frame_render_scale(s.map(), center, scale);
let rows = sizes.and_then(|_| legend.rows_sizes(s.map_mut(), at, &context, legend_pt));
let column = legend_cols.min(PUBLICATION_LEGEND_COLUMNS) - 1;
too_wide = rows.is_some_and(|rows| rows[column].0 > iw + LEGEND_FIT_MM);
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
}
}
warnings.extend(legend_fit_warnings(LegendFit::Manual, legend_cols, (too_wide, too_tall)));
let short = bar_need > bar_fit + LEGEND_FIT_MM;
// In a column the colorbar takes the column's width, as its rows do.
if let Some(layer) = bar.as_deref().filter(|_| (base_w > iw + LEGEND_FIT_MM && !legend_in_column) || short) {
Expand All @@ -1922,17 +1944,17 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
warnings.push(format!("the legend's box has no room for the colorbar of '{layer}': it is left out"));
}
}
if ch > 0.0 && rows_h >= 1.0 {
if let Some(legend) = legend.as_ref().filter(|_| ch > 0.0 && rows_h >= 1.0) {
l.add(
"Legend",
(ix, iy, iw, rows_h),
ElementKind::Legend {
frame,
title: String::new(),
title: legend.title.clone(),
all_classes: false,
hide_other: false,
show_no_data: false,
exclude: context.clone(),
exclude: legend.left_out(&context),
columns: legend_cols,
labels: Default::default(),
color: None,
Expand Down Expand Up @@ -2040,7 +2062,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
}
let locator = locator_map.map(|(map, ..)| map);
Ok(
json!({"layout": i, "name": name, "profile": profile.id, "page": [w, h], "scale": scale, "grid": step, "locator": locator, "style": style.code(), "arrangement": arrangement_used, "legendColumns": legend_cols, "mapShift": [map_shift.0, map_shift.1], "veiled": veiled.is_some(), "legendBox": legend_rect.is_some() && !legend_bare, "elements": elements, "moved": moved, "coverage": coverage_written, "warnings": warnings}),
json!({"layout": i, "name": name, "profile": profile.id, "page": [w, h], "scale": scale, "grid": step, "locator": locator, "style": style.code(), "arrangement": arrangement_used, "legendColumns": legend.as_ref().map(|_| legend_cols), "mapShift": [map_shift.0, map_shift.1], "veiled": veiled.is_some(), "legendBox": legend_rect.is_some() && !legend_bare, "elements": elements, "moved": moved, "coverage": coverage_written, "warnings": warnings}),
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
)
}

Expand Down
Loading
Loading