From 436bbe504af148d014b938718c73cc33800f3ea2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 01:50:18 -0800 Subject: [PATCH 1/2] Color: Show Opacity leaves out the art of a graph design The fill and stroke opacity the Color Wheel panel shows now skips the art of a column or marker design in a graph series, which paint.setFill and paint.setStroke leave out. With only that art selected the panel shows no opacity, also when a row of the art is the Appearance panel's active item, instead of offering an edit the command refuses. --- crates/engine/src/cmd/graph/tests.rs | 21 +++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 17 ++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 4b81d56802..62b2fd569a 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -1443,6 +1443,27 @@ fn paint_targets_leave_a_graph_designs_copy_out() { assert_eq!(super::paint_targets(d, &[copy, art, mark]), [mark]); } +/// The fill opacity the proxies show leaves out the art of a column or marker design in a series, which +/// `paint.setFill {opacity}` leaves out too: with only that art selected there is none, also with a row of the art +/// active, and with a mark selected after it the mark's. +#[test] +fn proxy_opacity_leaves_a_graph_designs_art_out() { + let (mut s, _, _, art, mark) = design_art(); + let (mut m, _, marker_art) = marker_design_art(); + for (s, art) in [(&mut s, art), (&mut m, marker_art)] { + s.execute("select.set", &json!({"ids": [art.0]})).unwrap(); + assert_eq!(s.proxy_opacity(false), None); + assert!(s.execute("paint.setFill", &json!({"opacity": 50})).is_err()); + let fill = top_row(s, art, true); + s.execute("appearance.setActiveItem", &json!({"index": fill})).unwrap(); + assert_eq!(s.proxy_opacity(false), None, "with the art's fill row active"); + assert!(s.execute("paint.setFill", &json!({"opacity": 50})).is_err()); + } + s.execute("paint.setFill", &json!({"ids": [mark.0], "opacity": 40})).unwrap(); + s.execute("select.set", &json!({"ids": [art.0, mark.0]})).unwrap(); + assert!((s.proxy_opacity(false).unwrap() - 0.4).abs() < 1e-6, "the mark's fill opacity"); +} + /// The art of a marker design in series 1 of a line graph: the design's copy and a path inside it. fn marker_design_art() -> (Session, NodeId, NodeId) { let mut s = Session::new(); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 787aefa6de..ef17c5c960 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -217,7 +217,8 @@ impl Session { /// would edit are read in order (a group without an active Appearance row stands for its /// contents), and the first that exists answers. `None` with nothing selected, for an object /// selected in a symbol instance, while the Type tool has characters selected, and when only - /// type characters or objects without that item are selected. + /// type characters, objects without that item or the art of graph designs in a graph series + /// are selected. pub fn proxy_opacity(&self, stroke: bool) -> Option { let st = self.active()?; if st.selection.symbol_part.is_some() { @@ -242,16 +243,22 @@ impl Session { if stroke { n.appearance.stroke_at(item).map(|s| s.opacity) } else { n.appearance.fill_at(item).map(|f| f.opacity) } }; let subjects = st.selection.subjects(); + // The command leaves out the art of a graph design in a series, which the graph draws again + // from the design, and a series group stands for the paths directly in it + // (graph::paint_targets). + let editable = |id: &&NodeId| !super::graph::is_design_art(&st.doc, **id); // As the command picks its rows (ItemTarget::of_kind): the active item when it is a row of // this kind in the first selected object's stack, read in the selected objects' own - // stacks; else the topmost one of the painted leaves (a group's contents). - let first = subjects.first().and_then(|id| st.doc.node(*id)); + // stacks; else the topmost one of the painted leaves (a group's contents). A row of a + // graph design's art selected first stands for nothing (item_target_at). + let first = subjects.first().filter(editable).and_then(|id| st.doc.node(*id)); let active = item.filter(|i| first.and_then(|n| n.appearance.items.get(*i)).is_some_and(|it| it.is_fill() == !stroke)); if active.is_some() { - return subjects.iter().filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, active)); + let targets = super::graph::series_group_marks_where(&st.doc, subjects, |n| n.extras().series_index.is_some()); + return targets.iter().filter(editable).filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, active)); } let leaves = super::leaf_targets(self, subjects).ok()?; - leaves.iter().filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, None)) + leaves.iter().filter(editable).filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, None)) } pub(crate) fn remember_paint_now(&mut self, p: &Paint) { From 42e5553c867675089462504a8a15cb722a5e54b4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 02:11:06 -0800 Subject: [PATCH 2/2] Color: an opacity alone refuses a span other than "object" paint.setFill and paint.setStroke given only `opacity` now check `span` as they do with a paint: "selection" asks for a gradient, and an unknown value is an error, instead of the opacity going through unchecked. --- crates/engine/src/cmd/paint.rs | 6 ++---- crates/engine/src/tests/paintopacity.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index ef17c5c960..2a2cab339d 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -560,10 +560,8 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool) fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option, opacity: Option, fill: bool) -> Result { let cmd = if fill { "paint.setFill" } else { "paint.setStroke" }; let focus = switch_or(p, "focus", true, cmd)?; - let span = match &paint { - Some(paint) => spans_targets(p, paint).map_err(|e| bad(cmd, e))?, - None => false, - }; + // An opacity alone places no gradient, so `span` may only be "object" with it. + let span = spans_targets(p, paint.as_ref().unwrap_or(&Paint::None)).map_err(|e| bad(cmd, e))?; // Characters selected with the Type tool take the paint, not the whole type object (#1063). if p.get("ids").is_none() && p.get("id").is_none() diff --git a/crates/engine/src/tests/paintopacity.rs b/crates/engine/src/tests/paintopacity.rs index a1e2018e83..e733bbab1c 100644 --- a/crates/engine/src/tests/paintopacity.rs +++ b/crates/engine/src/tests/paintopacity.rs @@ -156,6 +156,15 @@ fn errors_leave_the_document_and_defaults_alone() { } let e = s.execute("paint.setFill", &json!({})).unwrap_err(); assert!(e.to_string().contains("give color, none, swatch, gradient or opacity"), "{e}"); + // An opacity alone places no gradient across the selection. + let doc = s.doc().unwrap().doc.clone(); + for (span, says) in [(json!("selection"), "give `gradient`"), (json!("all"), "span must be \"object\" or \"selection\"")] { + let e = s.execute("paint.setFill", &json!({"opacity": 40, "span": span})).unwrap_err(); + assert!(e.to_string().contains(says), "{span}: {e}"); + } + assert_eq!(*s.doc().unwrap().doc, *doc); + s.execute("paint.setFill", &json!({"opacity": 40, "span": "object"})).unwrap(); + assert!((fill_opacity(&s, id) - 0.4).abs() < 1e-6); s.execute("select.none", &json!({})).unwrap(); let doc = s.doc().unwrap().doc.clone(); for p in [json!({"opacity": 40}), json!({"color": "#ff0000", "opacity": 40})] {