Repository navigation
fix(layout): a legend's title wraps to its box, and its rows start under the last line (#3129) #3188
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
fix(layout): a legend's title wraps to its box, and its rows start under the last line (#3129) #3188
Changes from all commits
fe26f09
780c53e
103e9e1
8d546ba
13a6710
2c2aa9d
d29ec56
1ad99dc
ab442e7
118e83f
3931f6a
ad91682
ebec849
8747922
aa57db8
53db910
5ac23d3
72ce7bc
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 |
|---|---|---|
|
|
@@ -2030,10 +2030,16 @@ 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); | ||
| 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. | ||
| // are wider still. It wraps to the box (#3129), and the lines it draws past its first take | ||
| // the rows' room, which `ch` (one line of title) doesn't hold. A line the box has no height | ||
| // for is left out, takes none, and is the text-loss report's to say, not the rows'. | ||
| let title = legend.as_ref().map(|l| l.title.as_str()).filter(|t| ch > 0.0 && !t.is_empty()); | ||
| let title_extra = title.map_or(0.0, |t| { | ||
| let drawn = crate::render::layout::legend_title_block_mm(t, (iw, rows_h), legend_pt); | ||
| (drawn - crate::render::layout::legend_title_mm(legend_pt)).max(0.0) | ||
| }); | ||
| let (mut too_wide, too_tall) = overflows((cw, ch + title_extra), (iw, rows_h)); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
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. The wrapped title's extra lines are counted here, but the placement that chooses this box doesn't count them. The PR says sizing still prefers a one-line title. If that is the intent, say in the PR description that a wrapped title can cost rows, and add a test where a wrapped title makes a column count lose rows that another column count keeps. If not, add the wrapped block's height to the sizes and to that fit check. Confidence: medium (about 0.5). I read the code but did not run the layout with a wrapped title, so this is not verified by a test. Category: bug |
||
| 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()); | ||
|
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. The title now wraps to the box, but this warning still tells the user to "shorten it" for any title wider than the box plus the fit margin. The wrapped title isn't lost on that account, so the advice is now only partly right. This is a wording point: consider "the title wraps to its box; shorten it to fit one line" or a shorter form. The test Category: quality
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. Claude autofix (declined): Left for the release quality pass. The wording is a point of style; the test |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,14 +454,48 @@ fn the_publication_legend_fixture_opens_and_keeps_its_requirement() { | |
| assert_eq!(serde_json::to_value(&fixture).unwrap()["requires"], json!(["layout-publication-legend"])); | ||
| } | ||
|
|
||
| /// A title wider than a side column's box wraps (#3129), and its lines past the first take the | ||
| /// room of the rows, which the sheet then says it left out: a title of two lines in a panel's one | ||
| /// column used to say only that it was wider than its box. | ||
| #[test] | ||
| fn a_publication_legend_title_wrapped_in_its_box_says_the_rows_it_loses() { | ||
| let (_, r) = sheet(json!({"legend": {"title": "A legend title ".repeat(2), "columns": 1}, "style": "panel"})); | ||
| let said = r["warnings"].to_string(); | ||
| assert!(said.contains("the legend's title is wider than its box: shorten it"), "{said}"); | ||
| assert!(said.contains("the legend lists more than fits its box: its last rows or the ends of long labels are left out"), "{said}"); | ||
| // A title that fits its box in one line loses nothing to it. | ||
| let (_, r) = sheet(json!({"legend": {"title": "Key", "columns": 1}, "style": "panel"})); | ||
| assert!(!r["warnings"].to_string().contains("legend lists more"), "{}", r["warnings"]); | ||
| } | ||
|
|
||
| /// A title line the box has no height to draw is left out (#3129), so it takes no room from the | ||
| /// rows: with one row and a two-line title in a box that holds the first line and the row, every | ||
| /// row is drawn and the sheet doesn't say rows are lost. | ||
| #[test] | ||
| fn a_publication_legend_title_line_left_out_does_not_say_a_drawn_row_is_lost() { | ||
| // One layer drawn in one plain colour: a single row. | ||
| let mut w = world(); | ||
| w.map_mut().layers.retain(|l| l.name == "Rivers"); | ||
| let (s, r) = { | ||
| let r = publish(&mut w, json!({"legend": {"title": "A legend title ".repeat(2), "columns": 1}, "style": "panel"})).unwrap(); | ||
| (w, r) | ||
| }; | ||
| let said = r["warnings"].to_string(); | ||
| assert!(find(&s, "Legend").is_some(), "{said}"); | ||
|
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. Nit: this Category: quality |
||
| assert!(!said.contains("the legend lists more than fits its box"), "{said}"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_publication_legend_title_wider_than_its_box_is_named() { | ||
| let long = "A very long legend title ".repeat(8); | ||
| for (columns, style) in [(1, "classic"), (2, "classic"), (1, "panel")] { | ||
| let (_, r) = sheet(json!({"legend": {"title": long, "columns": columns}, "style": style})); | ||
| let said = r["warnings"].to_string(); | ||
| assert!(said.contains("the legend's title is wider than its box: shorten it"), "{columns} {style}: {said}"); | ||
| assert!(!said.contains("columns are wider") && !said.contains("ends of long labels"), "{columns} {style}: {said}"); | ||
| // The title is named, not the rows' columns as wider than the box; its lines, wrapped to the | ||
| // box (#3129), take the rows' room, which is said. | ||
| assert!(!said.contains("columns are wider"), "{columns} {style}: {said}"); | ||
| assert!(said.contains("its last rows"), "{columns} {style}: {said}"); | ||
| } | ||
| let (_, r) = sheet(json!({"legend": {"title": "Key"}})); | ||
| assert!(!r["warnings"].to_string().contains("wider than its box"), "{}", r["warnings"]); | ||
|
|
||
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.
A legend added with neither
titlenorsubtitleskipssay_text_fit, but its default title "Legend" now wraps to the box too (#3129). In a legend narrower than that word, or shorter than two of its title lines, a line of the title is left out atlayout.addElementand nothing is said until an export's cut-off check. Before this change the default title drew whole, so this loss is new. The rule in AGENTS.md ("lines left out below a text's box are said as soon as they are") and the layouts guide both promise the setting-time notice.say_text_fitalready says nothing for a legend whose title fits, so the guard isn't needed for silence. Suggested change: call it for every legend. Please add a test for a default-titled legend in a too-short box (one notice) and a roomy one (none). I could not run the test suite here, so existingaddElementtests that count warnings should be checked too.Category: bug