From 8494b14ff781e957215bc4417b63986df30edbf2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 12:18:10 -0800 Subject: [PATCH] Graphs: a pasted graph's axis and ring line rows follow a renamed swatch When a paste added a conflicting swatch under a new name, the series, label and legend rows of a pasted graph were relinked to it, but the rows kept for its axis lines and radar rings still named the destination's swatch, so the next redraw painted the lines with it. --- crates/engine/src/cmd/clipboard/resources.rs | 2 +- crates/engine/src/tests/clipboard.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/clipboard/resources.rs b/crates/engine/src/cmd/clipboard/resources.rs index f457712415..ae0e9a3ba1 100644 --- a/crates/engine/src/cmd/clipboard/resources.rs +++ b/crates/engine/src/cmd/clipboard/resources.rs @@ -699,7 +699,7 @@ impl Relink { self.name(Res::ParaStyle, s); } } - for r in [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows].into_iter().flatten() { + for r in [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows, &mut l.axis_rows, &mut l.ring_rows].into_iter().flatten() { r.paint.fill.iter_mut().chain(r.paint.stroke.iter_mut()).for_each(|p| self.paint(p)); } } diff --git a/crates/engine/src/tests/clipboard.rs b/crates/engine/src/tests/clipboard.rs index 368bc6de10..2e3f24d42d 100644 --- a/crates/engine/src/tests/clipboard.rs +++ b/crates/engine/src/tests/clipboard.rs @@ -468,7 +468,7 @@ fn styles_symbols_and_images_of_the_same_name_are_renamed() { assert_eq!(key(&s, img2), src_key); } -/// A graph whose series fill, value labels and legend rows paint with global swatch "Brand" and +/// A graph whose series fill, value labels, legend rows and axis and ring line rows paint with global swatch "Brand" and /// whose value labels are set in character style "Emphasis" and paragraph style "Body", as a /// later redraw would give them to its marks and labels. fn styled_graph(s: &mut Session) -> NodeId { @@ -484,8 +484,9 @@ fn styled_graph(s: &mut Session) -> NodeId { let l = &mut g.label_styles; l.values = Some(vectorcraft_doc::CharStyle { fill: brand.clone(), style_name: Some("Emphasis".into()), ..Default::default() }); l.values_para = Some(vectorcraft_doc::ParaStyle { style_name: Some("Body".into()), ..Default::default() }); - let rows = vectorcraft_doc::SeriesPaint { stroke: Some(brand), ..Default::default() }; - l.legend_rows = Some(vectorcraft_doc::graph::LabelRows { paint: rows, ..Default::default() }); + let paint = vectorcraft_doc::SeriesPaint { stroke: Some(brand), ..Default::default() }; + let rows = vectorcraft_doc::graph::LabelRows { paint, ..Default::default() }; + (l.legend_rows, l.axis_rows, l.ring_rows) = (Some(rows.clone()), Some(rows.clone()), Some(rows)); id } @@ -515,7 +516,7 @@ fn a_pasted_graph_brings_and_follows_its_label_styles_and_paints() { let d = doc(&s); assert!(d.swatch("Brand").is_some(), "{v}"); assert!(d.char_styles.iter().any(|x| x.name == "Emphasis") && d.para_styles.iter().any(|x| x.name == "Body"), "{v}"); - let brand = vec!["Brand".to_string(); 3]; + let brand = vec!["Brand".to_string(); 5]; assert_eq!(graph_links(&s, ids_of(&v)[0]), (brand.clone(), Some("Emphasis".into()), Some("Body".into()))); // Into a document that gives each name something else: they come in renamed. @@ -524,15 +525,15 @@ fn a_pasted_graph_brings_and_follows_its_label_styles_and_paints() { s.execute("charStyle.new", &json!({"name": "Emphasis", "attrs": {"size": 8.0}})).unwrap(); s.execute("paraStyle.new", &json!({"name": "Body", "attrs": {"space_after": 2.0}})).unwrap(); let v = s.execute("edit.pasteInPlace", &json!({"swatchConflict": "add"})).unwrap(); - let brand2 = vec!["Brand 2".to_string(); 3]; + let brand2 = vec!["Brand 2".to_string(); 5]; assert_eq!(graph_links(&s, ids_of(&v)[0]), (brand2, Some("Emphasis 2".into()), Some("Body 2".into())), "{v}"); // Without formatting: the labels' text styles stay behind. new_doc(&mut s); let v = s.execute("edit.pasteWithoutFormatting", &json!({})).unwrap(); assert!(doc(&s).char_styles.is_empty() && doc(&s).para_styles.is_empty(), "{v}"); - // The value labels' red characters stay behind too; the series fill and the legend rows keep Brand. - assert_eq!(graph_links(&s, ids_of(&v)[0]), (vec!["Brand".to_string(); 2], None, None)); + // The value labels' red characters stay behind too; the series fill, the legend rows and the line rows keep Brand. + assert_eq!(graph_links(&s, ids_of(&v)[0]), (vec!["Brand".to_string(); 4], None, None)); } /// Each label of graph `id` (the text of its Axes and Legend groups) with its size and its first paragraph's format.