Repository navigation
fix(layout): a legend's title wraps to its box, and its rows start under the last line (#3129) #3522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(layout): a legend's title wraps to its box, and its rows start under the last line (#3129) #3522
Changes from all commits
fe26f09
780c53e
103e9e1
8d546ba
13a6710
2c2aa9d
d29ec56
1ad99dc
ab442e7
118e83f
3931f6a
ad91682
ebec849
8747922
75f1f15
f09fa8d
488f89f
aa57db8
53db910
5ac23d3
72ce7bc
f98665b
d06a456
55288a8
720cba4
7d891d8
a841b47
ca51b1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -858,7 +858,11 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu | |
| say_chart_losses(s, i, id); | ||
| } | ||
| say_table_cut(s, i, id); | ||
| say_text_fit(s, i, id, true); | ||
| // A legend's title lines its box has no height for are said when it is given a title or a | ||
| // subtitle (#3129), as `layout.update` does; a legend given neither says nothing, as before. | ||
| if kind != "legend" || ["title", "subtitle"].iter().any(|k| p.get(*k).is_some_and(|v| !v.is_null())) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default-titled legends can lose title lines without a notice. A legend added without Suggested fix
|
||
| say_text_fit(s, i, id, true); | ||
| } | ||
| say_text_statistics(s, i, id); | ||
| if let Some(said) = empty_colorbar { | ||
| s.warn(said); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,8 +116,9 @@ pub(in crate::cmd::layout) fn say_raster_keys(s: &mut Session, li: usize, id: u3 | |
|
|
||
| /// Whether a legend `kind`, after a command with `p`, says what it loses in its box (#2581): the | ||
| /// one rule `layout.addElement` and `layout.update` both take. Told when it is given what sets | ||
| /// what it needs of its box (its columns, its missing-value row, its fit, its layer names, or its | ||
| /// text size, `null` included, which gives the default back) or labels (text chosen for the box), | ||
| /// what it needs of its box (its columns, its missing-value row, its fit, its layer names, its | ||
| /// title, which wraps to the box and takes the rows' room (#3129), or its text size, `null` | ||
| /// included, which gives the default back) or labels (text chosen for the box), | ||
| /// and, in columns, at a text size of its own or under a fit, which can stop fitting, when its box | ||
| /// or what it lists changes. A move changes neither. | ||
| pub(in crate::cmd::layout) fn tells_legend_fit(kind: &ElementKind, p: &Value) -> bool { | ||
|
|
@@ -130,7 +131,7 @@ pub(in crate::cmd::layout) fn tells_legend_fit(kind: &ElementKind, p: &Value) -> | |
| || fit.kept() != LegendFit::Manual; | ||
| let refitted = | ||
| ["w", "h", "title", "allClasses", "hideOther", "exclude", "layerOrder", "labels", "classLabels"].iter().any(|k| given(k)); | ||
| ["columns", "showNoData", "labels", "classLabels", "fit", "showLayerNames", "showCounts", "subtitle", "sizes", "oneRow"] | ||
| ["columns", "showNoData", "labels", "classLabels", "fit", "showLayerNames", "showCounts", "title", "subtitle", "sizes", "oneRow"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recheck row fit when a manual legend is resized. If a width change wraps the title and displaces rows, a default one-column manual legend does not run
|
||
| .iter() | ||
| .any(|k| given(k)) | ||
| || p.get("textSize").is_some() | ||
|
|
@@ -140,7 +141,7 @@ pub(in crate::cmd::layout) fn tells_legend_fit(kind: &ElementKind, p: &Value) -> | |
|
|
||
| /// Says what a legend loses in its box, as `layout.publication` does for its own, or that it can't | ||
| /// tell. A manual legend is measured in its own columns at its own size; a fitted one by the | ||
| /// drawing's own fit ([`crate::render::layout::legend_fitted_mm`]), in the room its title leaves, | ||
| /// drawing's own fit ([`crate::render::layout::legend_fitted_mm`]), in the room its wrapped title leaves, | ||
| /// so it says nothing when the page draws it whole and what it tried when it can't. | ||
| pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32) { | ||
| let Some(l) = s.project.layouts.get(li) else { return }; | ||
|
|
@@ -173,7 +174,10 @@ pub(in crate::cmd::layout) fn say_legend_fit(s: &mut Session, li: usize, id: u32 | |
| Some(ElementKind::MapFrame { map, center, scale, .. }) => Some((map.clone(), *center, *scale)), | ||
| _ => None, | ||
| }; | ||
| let room = (e.w, e.h - crate::render::layout::legend_head_mm(title, subtitle, *text_size)); | ||
| // The title wraps to the box (#3129), and a subtitle takes a row under it: the rows have what is left. | ||
| let head = crate::render::layout::legend_title_block_mm(title, (e.w, e.h), *text_size) | ||
| + crate::render::layout::legend_head_mm("", subtitle, *text_size); | ||
| let room = (e.w, e.h - head); | ||
| let (all_classes, hide_other, show_no_data, exclude, columns, labels, text_size) = | ||
| (*all_classes, *hide_other, *show_no_data, exclude.clone(), *columns, labels.clone(), *text_size); | ||
| let (fit, layer_names, class_labels) = (fit.kept(), show_layer_names.shown(), class_labels.clone()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gate leaves out
wandh, solayout.addElementof a legend with no title or subtitle never checks its title. A default-titled legend given a narrowwwraps "Legend" onto lines its box has no height for, and nothing is said at add time.layout.updatedoes say it, becauseTEXT_FIT_KEYSlistswandh, so the two commands disagree. The export and layout-view notices still catch the loss, so this is a missed add-time notice, not silent output. Either drop the gate (say_text_fitonly speaks on a real loss, so clean input stays quiet), or addwandhto the list. If you drop it, check the existing add-time tests first. Confidence: medium.Category: quality