From f0a8c750a3a6c7950272520b85f7ce40bb12243d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 20:44:06 -0800 Subject: [PATCH 1/6] Graphs: a whole-pie recolor leaves wedge legend labels their contrast A recolor that reached a pie's legend labels through the graph kept their new fill as the legend's own when every label ended up with one color (a one-series pie), so a wedge painted light again kept a white label. Legend label fills on such a pie are now kept only when the edit named the labels. --- crates/engine/src/cmd/appearance.rs | 2 +- crates/engine/src/cmd/colorcmds.rs | 2 +- crates/engine/src/cmd/graph/series.rs | 11 +++++++---- crates/engine/src/cmd/graph/tests.rs | 18 ++++++++++++++++++ crates/engine/src/cmd/paint.rs | 4 ++-- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index f006d7314e..6689a25014 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -547,7 +547,7 @@ pub(crate) fn edit_items( edit_items_then(s, ids, item, cmd, label, fill, f, |before, d, edited| { let series = capture_series_changes(before, d, edited); // The rows `f` edited are kept by `edit_items_then`. - let labels = super::graph::capture_label_changes(before, d, edited, false); + let labels = super::graph::capture_label_changes(before, d, edited, false, None); Ok(series || labels) }) } diff --git a/crates/engine/src/cmd/colorcmds.rs b/crates/engine/src/cmd/colorcmds.rs index baaef20c56..d811a9dffe 100644 --- a/crates/engine/src/cmd/colorcmds.rs +++ b/crates/engine/src/cmd/colorcmds.rs @@ -522,7 +522,7 @@ pub(crate) fn keeping_series_paint(d: &mut Document, roots: &[NodeId], recolor: let n = recolor(d)?; if let Some(before) = before.filter(|_| n > 0) { super::appearance::capture_series_changes(&before, d, &marks); - super::graph::capture_label_changes(&before, d, &labels, true); + super::graph::capture_label_changes(&before, d, &labels, true, Some(roots)); } Ok(n) } diff --git a/crates/engine/src/cmd/graph/series.rs b/crates/engine/src/cmd/graph/series.rs index df99ebef51..69cf88d62c 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -899,9 +899,11 @@ pub(crate) fn labels_in(doc: &Document, roots: &[NodeId]) -> Vec { /// and stroke attributes ([`RUN_PAINT`]) that changed on all of a label's characters, on the kind's kept style. The /// frontmost label of a kind sets what that kind keeps, whatever order `ids` are in. On a graph that colors its legend /// labels itself ([`picks_legend_fill`]), their fill is kept only when the legend labels among `ids` end up with one -/// fill. The graph lines among `ids` whose rows changed keep them for every line of their kind ([`capture_line_rows`]), -/// with or without `rows`. Called inside the same edit, so they undo together. Returns whether what a graph keeps changed. -pub(crate) fn capture_label_changes(before: &Document, doc: &mut Document, ids: &[NodeId], rows: bool) -> bool { +/// fill and the edit named them: with `named`, only a legend label among `named` (an edit that reached the others +/// through the graph or a group leaves them the graph's black or white); without it, every label in `ids`. The graph +/// lines among `ids` whose rows changed keep them for every line of their kind ([`capture_line_rows`]), with or without +/// `rows`. Called inside the same edit, so they undo together. Returns whether what a graph keeps changed. +pub(crate) fn capture_label_changes(before: &Document, doc: &mut Document, ids: &[NodeId], rows: bool, named: Option<&[NodeId]>) -> bool { let lines = capture_line_changes(before, doc, ids); if !ids.iter().any(|id| doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Text(_)))) { return lines; @@ -929,7 +931,8 @@ pub(crate) fn capture_label_changes(before: &Document, doc: &mut Document, ids: if rows && label_rows(was) != label_rows(now) { changed_rows.push(id); } - let fill = kind.1 != Role::Legend || one_fill(kind.0); + let aimed = !wedge_fills.contains_key(&kind.0) || named.is_none_or(|n| n.contains(&id)); + let fill = kind.1 != Role::Legend || (one_fill(kind.0) && aimed); characters.extend(run_paint_change(was, now, fill).map(|change| (kind, change))); } let mut changed = capture_label_rows(doc, &changed_rows) | lines; diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 35987ce15d..13b2542ff3 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -5971,6 +5971,24 @@ fn a_recolor_leaves_wedge_legend_labels_their_contrast() { assert_eq!(kept.and_then(|f| f.color()).map(|c| c.to_hex()).as_deref(), Some("#ffffff")); } +/// A recolor of the whole graph that turns every wedge legend label the same color (one series) still leaves them to +/// the graph's black or white, so a label stays readable when its wedge is painted light again. +#[test] +fn a_recolor_of_a_one_series_pie_leaves_its_wedge_label_its_contrast() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = make(&mut s, "pie", ",a\nP1,1"); + s.execute("graph.setType", &json!({"id": id.0, "pieLegend": "wedges"})).unwrap(); + s.execute("paint.setFill", &json!({"ids": [series_0_group(&s, id).0.0], "color": "#ffffff"})).unwrap(); + // The white wedge turns black and its black label white. + s.execute("edit.colors.invert", &json!({"ids": [id.0]})).unwrap(); + assert_eq!(spec(&s, id).label_styles.legend, None); + s.execute("paint.setFill", &json!({"ids": [series_0_group(&s, id).0.0], "color": "#ffffff"})).unwrap(); + s.execute("graph.setData", &json!({"id": id.0, "rows": [[1]]})).unwrap(); + let NodeKind::Text(t) = label_node(&s, id, "Legend", "a").kind else { panic!("a is not type") }; + assert_eq!(t.runs[0].style.fill.color().map(|c| c.to_hex()).as_deref(), Some("#000000")); +} + /// The lines in graph `id`'s Axes group (axis lines, tick marks and a radar graph's rings), in paint order. fn line_nodes(s: &Session, id: NodeId) -> Vec { let n = s.doc().unwrap().doc.node(id).unwrap().clone(); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 67a0281528..32a8fdb2c2 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -925,7 +925,7 @@ fn swap(s: &mut Session, p: &Value) -> Result { } // The swap writes the paint of the topmost fill and stroke, not their opacity. let kept = super::appearance::capture_series_writes(&before, d, &ids, (true, true), (false, false), true, false); - let labels = super::graph::capture_label_changes(&before, d, &ids, false); + let labels = super::graph::capture_label_changes(&before, d, &ids, false, None); Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels)) })?; } @@ -955,7 +955,7 @@ fn default_paint(s: &mut Session, p: &Value) -> Result { } } let kept = super::appearance::capture_series_writes(&before, d, &ids, (true, true), (true, true), false, false); - let labels = super::graph::capture_label_changes(&before, d, &ids, false); + let labels = super::graph::capture_label_changes(&before, d, &ids, false, None); Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels)) })?; } From f1a79b92cc4500beaee7f384e7bf174d9e9d5f3a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 21:36:59 -0800 Subject: [PATCH 2/6] Graphs: an edit of some attributes on an axis line keeps the rest its kind keeps An edit that changed only some attributes of a graph line, such as a transparency-only Eyedropper pick, a cap, or a fill, kept that line's whole fill and stroke rows for every line of its kind. A line that still showed the default stroke until the graph was drawn again then replaced the stroke its kind kept from another line. Such edits now keep only the attributes they change; Clear Appearance, Move Appearance, graphic styles, and a pick of every attribute or with append still keep the whole rows. --- crates/engine/src/cmd/addons/color.rs | 2 +- crates/engine/src/cmd/appearance.rs | 61 +++++++++++++++++---------- crates/engine/src/cmd/graph.rs | 6 +-- crates/engine/src/cmd/graph/series.rs | 59 +++++++++++++++++++++----- crates/engine/src/cmd/graph/tests.rs | 47 +++++++++++++++++++++ crates/engine/src/cmd/stroke.rs | 2 +- docs/mcp.md | 10 +++-- 7 files changed, 145 insertions(+), 42 deletions(-) diff --git a/crates/engine/src/cmd/addons/color.rs b/crates/engine/src/cmd/addons/color.rs index fe594903a0..8462e35207 100644 --- a/crates/engine/src/cmd/addons/color.rs +++ b/crates/engine/src/cmd/addons/color.rs @@ -260,7 +260,7 @@ fn copy_paint(s: &mut Session, p: &Value, to_stroke: bool) -> Result { let series = super::super::appearance::capture_series_paint_writes(&before, d, &ids, &written); let labels = super::super::graph::capture_label_styles(d, &ids, ©_run); let painted: Vec = written.iter().map(|(id, _)| *id).collect(); - let lines = super::super::graph::capture_line_rows(d, &painted); + let lines = super::super::graph::capture_line_changes(&before, d, &painted); Ok(objects + usize::from(series || labels || lines)) })?; } diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 6689a25014..5302e38ed9 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -48,7 +48,7 @@ pub fn specs() -> Vec { "Add New Fill", ["Window", "Appearance"], Some("Cmd+/"), - "{ids?|id?, target?: \"object\"|\"contents\"} add a fill on top of each selected object's own stack, on an image right below its Contents row, with its top fill's paint (type without one: its characters' fill; else the default fill). With a fill row active (appearance.setActiveItem), no `ids`, no `id` and no `target: \"contents\"`, the new fill takes that row's paint, goes right above it, and becomes the active row; appearance.duplicateItem copies a whole row. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind", + "{ids?|id?, target?: \"object\"|\"contents\"} add a fill on top of each selected object's own stack, on an image right below its Contents row, with its top fill's paint (type without one: its characters' fill; else the default fill). With a fill row active (appearance.setActiveItem), no `ids`, no `id` and no `target: \"contents\"`, the new fill takes that row's paint, goes right above it, and becomes the active row; appearance.duplicateItem copies a whole row. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes)", has_doc, |s, p| add_item(s, p, true) ), @@ -57,7 +57,7 @@ pub fn specs() -> Vec { "Add New Stroke", ["Window", "Appearance"], Some("Cmd+Alt+/"), - "{ids?|id?, target?} add a stroke on top of each selected object's own stack, on an image right below its Contents row, with its top stroke's paint (else the default stroke) and that stroke's weight when it has paint, at least 1 pt. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind", + "{ids?|id?, target?} add a stroke on top of each selected object's own stack, on an image right below its Contents row, with its top stroke's paint (else the default stroke) and that stroke's weight when it has paint, at least 1 pt. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes)", has_doc, |s, p| add_item(s, p, false) ), @@ -75,7 +75,7 @@ pub fn specs() -> Vec { "Reduce to Basic Appearance", ["Window", "Appearance"], None, - "{ids?|id?, target?} keep only one visible fill and stroke (without ids: the Appearance panel's active row in place of the topmost one of its kind; else the topmost), without their own opacity, blend mode or effects (a group keeps no rows it lacked), and drop the object's effects. On a path directly in a graph series (a series group's id stands for those paths and the group), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind", + "{ids?|id?, target?} keep only one visible fill and stroke (without ids: the Appearance panel's active row in place of the topmost one of its kind; else the topmost), without their own opacity, blend mode or effects (a group keeps no rows it lacked), and drop the object's effects. On a path directly in a graph series (a series group's id stands for those paths and the group), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes)", has_doc, reduce_basic ), @@ -84,7 +84,7 @@ pub fn specs() -> Vec { "Appearance Item", [], None, - "{index: paint-order item index, ids?|id? (default: the selection), target?: \"object\"|\"contents\", opacity?: 0..100, blend?: name, visible?: bool, weight?: pt (strokes), color?|none?|swatch?|gradient? (as paint.setFill), tint?: 0..100, keepModel?: bool (both as paint.setFill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} edit one fill/stroke of each target object's own appearance stack. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind", + "{index: paint-order item index, ids?|id? (default: the selection), target?: \"object\"|\"contents\", opacity?: 0..100, blend?: name, visible?: bool, weight?: pt (strokes), color?|none?|swatch?|gradient? (as paint.setFill), tint?: 0..100, keepModel?: bool (both as paint.setFill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} edit one fill/stroke of each target object's own appearance stack. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes)", has_doc, set_item ), @@ -93,7 +93,7 @@ pub fn specs() -> Vec { "Remove Item", [], None, - "{index | indices: [..] (paint-order item indices), ids?|id?, target?, aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} remove those fills/strokes from each target object's own stack. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind", + "{index | indices: [..] (paint-order item indices), ids?|id?, target?, aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} remove those fills/strokes from each target object's own stack. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes)", has_doc, remove_item ), @@ -111,7 +111,7 @@ pub fn specs() -> Vec { "Duplicate Item", ["Window", "Appearance"], None, - "{index | indices: [..] (paint-order item indices), to?: paint-order index of the copy (with several, of the lowest copy: they land together in their order; default: each right above its item; not with aligned rows of a mixed selection), contents?: count (with `to`: how many items paint below the Contents (Characters) row afterwards; default: it stays between the same items), ids?|id?, target?, aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} copy fills/strokes with their effects, as Alt-dragging rows places them. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind", + "{index | indices: [..] (paint-order item indices), to?: paint-order index of the copy (with several, of the lowest copy: they land together in their order; default: each right above its item; not with aligned rows of a mixed selection), contents?: count (with `to`: how many items paint below the Contents (Characters) row afterwards; default: it stays between the same items), ids?|id?, target?, aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} copy fills/strokes with their effects, as Alt-dragging rows places them. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes)", has_doc, duplicate_item ), @@ -120,7 +120,7 @@ pub fn specs() -> Vec { "Reorder Appearance Item", [], None, - "{from: paint-order item index | \"contents\", indices?: [..] (several items instead of from: they move as one block in their order, the lowest landing at `to`; a block landing next to the Contents row keeps its lowest item's side), to, contents?: count, ids?|id?, target?, aligned?: bool (refused when the targets' appearances differ)} move fill/stroke `from` to paint-order index `to`; on a group, layer or type the Contents (Characters) row stays between the same items (a moved item landing next to it keeps its side) unless `contents` says how many items paint below it afterwards. from \"contents\": move that row so `to` items paint below the members (characters) and the rest above. On a path directly in a graph series (a series group's id stands for those paths, except with from \"contents\", which moves the group's own row), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind → {index: where the item landed | contents: the row's slot}", + "{from: paint-order item index | \"contents\", indices?: [..] (several items instead of from: they move as one block in their order, the lowest landing at `to`; a block landing next to the Contents row keeps its lowest item's side), to, contents?: count, ids?|id?, target?, aligned?: bool (refused when the targets' appearances differ)} move fill/stroke `from` to paint-order index `to`; on a group, layer or type the Contents (Characters) row stays between the same items (a moved item landing next to it keeps its side) unless `contents` says how many items paint below it afterwards. from \"contents\": move that row so `to` items paint below the members (characters) and the rest above. On a path directly in a graph series (a series group's id stands for those paths, except with from \"contents\", which moves the group's own row), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes) → {index: where the item landed | contents: the row's slot}", has_doc, move_item ), @@ -129,7 +129,7 @@ pub fn specs() -> Vec { "Eyedropper", [], None, - "{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode, and with `append` its topmost visible fill and stroke rows; on a graph's axis line, tick mark or radar ring, its topmost visible fill and stroke rows and object opacity and blend mode for every line of its kind → {ids}", + "{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode, and with `append` its topmost visible fill and stroke rows; on a graph's axis line, tick mark or radar ring, its topmost visible fill and stroke rows and object opacity and blend mode for every line of its kind (a pick of some attributes without `append`: only what it changes) → {ids}", has_doc, copy_from ), @@ -147,7 +147,7 @@ pub fn specs() -> Vec { "Show All Hidden Attributes", ["Window", "Appearance"], None, - "{ids?|id?, target?} make every hidden fill, stroke and effect (the object's and each item's) of each selected object visible again; errors when nothing is hidden. On a path directly in a graph series (a series group's id stands for those paths and the group), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind → {ids}", + "{ids?|id?, target?} make every hidden fill, stroke and effect (the object's and each item's) of each selected object visible again; errors when nothing is hidden. On a path directly in a graph series (a series group's id stands for those paths and the group), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind (of a line, only what the edit changes) → {ids}", has_doc, show_all_hidden ), @@ -532,7 +532,7 @@ fn require_targets(s: &Session, p: &Value, cmd: &str) -> Result> { /// What the edit changes on the topmost visible fill and stroke of graph series marks, and on the /// rows and characters of graph labels, is stored on their graphs in the same step /// ([`capture_series_changes`], [`super::graph::capture_label_changes`]), and so are the rows of -/// the graph lines it reaches ([`super::graph::capture_line_rows`]). Nothing targeted is not +/// the graph lines it reaches ([`super::graph::capture_line_changes`]). Nothing targeted is not /// an edit, and when `f` leaves every target as it was, the document and its undo history stay as /// they are. pub(crate) fn edit_items( @@ -587,14 +587,27 @@ pub(crate) fn edit_items_then( } } let more = after(&before, d, &edited)?; + // A graph line keeps only the attributes of its rows that the edit changed: the others stay as its kind keeps + // them, which the line may not show yet. + rows.retain(|id| !super::graph::is_graph_line(d, *id)); let labels = super::graph::capture_label_rows(d, &rows); - // A graph line keeps the rows the edit wrote, also when the line already showed them. - let lines = super::graph::capture_line_rows(d, &edited); + let lines = super::graph::capture_line_changes(&before, d, &edited); Ok(count_changed(d, &before, &edited) + usize::from(more || labels || lines)) })?; Ok(()) } +/// Keep the object rows of the graph labels among `ids` for every label of their kind +/// ([`super::graph::capture_label_rows`]), and of the graph lines among them only the attributes the edit changed +/// ([`super::graph::capture_line_changes`]): a line's other attributes stay as its kind keeps them, which the line may +/// not show yet. Returns whether what a graph keeps changed. +fn capture_row_edits(before: &vectorcraft_doc::Document, d: &mut vectorcraft_doc::Document, ids: &[NodeId]) -> bool { + let labels: Vec = ids.iter().copied().filter(|id| !super::graph::is_graph_line(d, *id)).collect(); + let labels = super::graph::capture_label_rows(d, &labels); + let lines = super::graph::capture_line_changes(before, d, ids); + labels || lines +} + /// How many of `ids` differ in `d` from `before`. pub(crate) fn count_changed(d: &vectorcraft_doc::Document, before: &vectorcraft_doc::Document, ids: &[NodeId]) -> usize { ids.iter().filter(|id| d.node(**id) != before.node(**id)).count() @@ -727,7 +740,7 @@ fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result { let mut rows = top_paint_changed(&before, d, &ids); rows.extend(painted_rows(d, added)); super::graph::capture_series_top_paints(d, &rows); - super::graph::capture_label_rows(d, &ids); + capture_row_edits(&before, d, &ids); Ok(()) })?; // A fill added above the active row becomes the active row; otherwise the rows above the new @@ -1020,7 +1033,7 @@ fn reduce_basic(s: &mut Session, p: &Value) -> Result { } let kept = super::graph::capture_series_opacity(d, &both_kinds(&ids)); let painted = super::graph::capture_series_top_paints(d, &top_paint_changed(&before, d, &ids)); - let labels = super::graph::capture_label_rows(d, &ids); + let labels = capture_row_edits(&before, d, &ids); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; s.active_appearance_item = None; @@ -1096,7 +1109,7 @@ fn set_item(s: &mut Session, p: &Value) -> Result { let mut rows = top_paint_changed(&before, d, &ids); rows.extend(painted_rows(d, written)); let painted = super::graph::capture_series_top_paints(d, &rows); - let labels = super::graph::capture_label_rows(d, &ids); + let labels = capture_row_edits(&before, d, &ids); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; if let Some(pa) = &paint { @@ -1143,7 +1156,7 @@ fn remove_item(s: &mut Session, p: &Value) -> Result { } let kept = super::graph::capture_series_opacity(d, &top_opacity_changed(&before, d, &ids)); let painted = super::graph::capture_series_top_paints(d, &top_paint_changed(&before, d, &ids)); - let labels = super::graph::capture_label_rows(d, &ids); + let labels = capture_row_edits(&before, d, &ids); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; // The rows removed from the active row's object, which need not come first in `ids`. @@ -1228,7 +1241,7 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result { let mut rows = top_paint_changed(&before, d, &ids); rows.extend(painted_rows(d, added)); super::graph::capture_series_top_paints(d, &rows); - super::graph::capture_label_rows(d, &ids); + capture_row_edits(&before, d, &ids); Ok(()) })?; // Rows at or above each copy move up by one (by the block, for copies placed at `to`). @@ -1268,7 +1281,7 @@ fn show_all_hidden(s: &mut Session, p: &Value) -> Result { } super::graph::capture_series_opacity(d, &top_opacity_changed(&before, d, &shown)); super::graph::capture_series_top_paints(d, &top_paint_changed(&before, d, &shown)); - super::graph::capture_label_rows(d, &shown); + capture_row_edits(&before, d, &shown); Ok(shown) })?; Ok(json!({ "ids": ids.iter().map(|i| i.0).collect::>() })) @@ -1314,7 +1327,7 @@ fn move_item(s: &mut Session, p: &Value) -> Result { } let kept = super::graph::capture_series_opacity(d, &top_opacity_changed(&before, d, &ids)); let painted = super::graph::capture_series_top_paints(d, &top_paint_changed(&before, d, &ids)); - let labels = super::graph::capture_label_rows(d, &ids); + let labels = capture_row_edits(&before, d, &ids); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; // The moved row stays the active one; the rows it passed shift by one. @@ -1360,7 +1373,7 @@ fn move_items(s: &mut Session, p: &Value, ids: &[NodeId], to: usize) -> Result Result { } slot.ok_or_else(|| bad("appearance.moveItem", "only groups, layers, type and images have a Contents (Characters) row"))?; // A graph label's kind keeps where its rows paint relative to the characters. - let labels = super::graph::capture_label_rows(d, ids); + let labels = capture_row_edits(&before, d, ids); Ok(count_changed(d, &before, ids) + usize::from(labels)) })?; Ok(json!({ "contents": slot })) @@ -1669,8 +1682,10 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { }; // `append` adds rows and leaves the characters as they were. let text = !append && super::graph::capture_label_text(d, &targets, kept_text, kept_para)?; - // A graph line is a path: every pick writes its rows. - let lines = super::graph::capture_line_rows(d, &targets); + // A graph line is a path: a whole pick and `append` write its rows. A pick of some attributes keeps those it + // changed, and the rest stay as its kind keeps them, which the line may not show yet. + let lines = + if rows_written { super::graph::capture_line_rows(d, &targets) } else { super::graph::capture_line_changes(&before, d, &targets) }; Ok(count_changed(d, &before, &targets) + usize::from(kept || painted || object || rows || text || lines)) })?; Ok(finish(s, &targets)) diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index b8a88b0bc5..e49ff91f04 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -46,9 +46,9 @@ use generate::generate; use series::default_series_color; pub(crate) use series::{ LabelTextChange, capture_label_anti_alias, capture_label_changes, capture_label_object_opacity, capture_label_paragraphs, capture_label_rows, - capture_label_styles, capture_label_text, capture_line_rows, capture_series_object_opacity, capture_series_opacity, capture_series_top_paints, - is_design_art, label_object_opacity_differs, labels_in, paint_targets, series_group_marks, series_group_marks_where, series_marks_in, - series_object_opacity_differs, shown_paint, + capture_label_styles, capture_label_text, capture_line_changes, capture_line_rows, capture_series_object_opacity, capture_series_opacity, + capture_series_top_paints, is_design_art, is_graph_line, label_object_opacity_differs, labels_in, paint_targets, series_group_marks, + series_group_marks_where, series_marks_in, series_object_opacity_differs, shown_paint, }; #[cfg(test)] diff --git a/crates/engine/src/cmd/graph/series.rs b/crates/engine/src/cmd/graph/series.rs index 69cf88d62c..0c6803bcc4 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -645,15 +645,54 @@ pub(crate) fn capture_line_rows(doc: &mut Document, ids: &[NodeId]) -> bool { store_line_rows(doc, ids, false) } -/// Keep the object rows of the graph lines among `ids` whose rows an edit changed (`before`: the document before the -/// edit) for every line of their kind. Returns whether kept rows changed. -fn capture_line_changes(before: &Document, doc: &mut Document, ids: &[NodeId]) -> bool { - let changed: Vec = ids - .iter() - .copied() - .filter(|id| graph_line(doc, *id).is_some() && before.node(*id).map(label_rows) != doc.node(*id).map(label_rows)) - .collect(); - store_line_rows(doc, &changed, false) +/// Keep, for every line of their kind, the attributes of the object rows ([`label_rows`]) that an edit changed on the +/// graph lines among `ids` (`before`: the document before the edit). The attributes the edit left alone stay as the kind +/// keeps them, also when a line still shows other ones until the graph is drawn again. Lines of a kind that the edit +/// changed differently take the frontmost one's attributes. Called inside the same edit, so they undo together. Returns +/// whether kept rows changed. +pub(crate) fn capture_line_changes(before: &Document, doc: &mut Document, ids: &[NodeId]) -> bool { + let mut changed = false; + for (id, graph, line) in lines_of(doc, ids) { + let old = before.node(id).and_then(label_rows).unwrap_or_default(); + let new = doc.node(id).and_then(label_rows).unwrap_or_default(); + if old == new { + continue; + } + let Some(spec) = doc.node_mut(graph).and_then(|n| n.extras_if_any().and_then(|e| e.graph.as_deref_mut())) else { continue }; + let slot = line_slot(&mut spec.label_styles, line); + let mut rows = slot.clone().unwrap_or_else(|| line.default_rows()); + merge_row_edits(&mut rows, &old, &new); + let kept = (rows != line.default_rows()).then_some(rows); + changed |= *slot != kept; + *slot = kept; + } + changed +} + +/// Is `id` a graph line: a path directly in a graph's Axes group? +pub(crate) fn is_graph_line(doc: &Document, id: NodeId) -> bool { + graph_line(doc, id).is_some() +} + +/// Set each attribute of `rows` that differs between `old` and `new` as `new` has it. +fn merge_row_edits(rows: &mut vectorcraft_doc::LabelRows, old: &vectorcraft_doc::LabelRows, new: &vectorcraft_doc::LabelRows) { + fn take(kept: &mut T, old: &T, new: &T) { + if old != new { + *kept = new.clone(); + } + } + let (k, o, n) = (&mut rows.paint, &old.paint, &new.paint); + take(&mut k.fill, &o.fill, &n.fill); + take(&mut k.stroke, &o.stroke, &n.stroke); + take(&mut k.stroke_width, &o.stroke_width, &n.stroke_width); + take(&mut k.fill_opacity, &o.fill_opacity, &n.fill_opacity); + take(&mut k.stroke_opacity, &o.stroke_opacity, &n.stroke_opacity); + take(&mut k.fill_blend, &o.fill_blend, &n.fill_blend); + take(&mut k.stroke_blend, &o.stroke_blend, &n.stroke_blend); + take(&mut k.opacity, &o.opacity, &n.opacity); + take(&mut k.blend, &o.blend, &n.blend); + take(&mut rows.below, &old.below, &new.below); + take(&mut rows.stroke_under, &old.stroke_under, &new.stroke_under); } /// Would [`store_line_rows`] with `object_only` change what a graph keeps for the lines among `ids`? Reads the document @@ -901,7 +940,7 @@ pub(crate) fn labels_in(doc: &Document, roots: &[NodeId]) -> Vec { /// labels itself ([`picks_legend_fill`]), their fill is kept only when the legend labels among `ids` end up with one /// fill and the edit named them: with `named`, only a legend label among `named` (an edit that reached the others /// through the graph or a group leaves them the graph's black or white); without it, every label in `ids`. The graph -/// lines among `ids` whose rows changed keep them for every line of their kind ([`capture_line_rows`]), with or without +/// lines among `ids` whose rows changed keep what changed for every line of their kind ([`capture_line_changes`]), with or without /// `rows`. Called inside the same edit, so they undo together. Returns whether what a graph keeps changed. pub(crate) fn capture_label_changes(before: &Document, doc: &mut Document, ids: &[NodeId], rows: bool, named: Option<&[NodeId]>) -> bool { let lines = capture_line_changes(before, doc, ids); diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 13b2542ff3..0ab174cba0 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6193,6 +6193,53 @@ fn an_object_opacity_on_an_axis_line_keeps_the_stroke_its_kind_keeps() { } } +/// An Eyedropper pick that applies only the object's transparency to an axis line keeps the stroke its kind keeps, though +/// the line it is applied to still shows the default stroke. +#[test] +fn a_transparency_only_pick_on_an_axis_line_keeps_the_stroke_its_kind_keeps() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let rect = NodeId(s.execute("shape.rectangle", &json!({"x": 600, "y": 600, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap()); + s.execute("transparency.set", &json!({"ids": [rect.0], "opacity": 50})).unwrap(); + let lines = line_nodes(&s, id); + s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "color": "#ff0000"})).unwrap(); + assert_eq!(line_look(&line_nodes(&s, id)[1]).0, "#000000", "the other lines show black until the graph is drawn again"); + let fill = json!({"color": false, "transparency": false, "overprint": false}); + let stroke = json!({"color": false, "transparency": false, "overprint": false, "weight": false, "cap": false, "join": false, "miter": false, "dash": false}); + let apply = json!({"appearance": {"transparency": true, "fill": fill, "stroke": stroke}, "character": false, "paragraph": false}); + s.execute("appearance.copyFrom", &json!({"source": rect.0, "ids": [lines[1].id.0], "apply": apply})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.2 - 0.5).abs() < 1e-6), "{looks:?}"); +} + +/// An edit of some attributes on an axis line that still shows the default stroke keeps what it changes, and the stroke +/// its kind keeps from another line stays: a cap is not kept, so it changes nothing the kind keeps. +#[test] +fn an_edit_of_some_attributes_on_an_axis_line_keeps_the_rest_its_kind_keeps() { + let cases = [ + ("stroke.set", json!({"cap": "round"}), ""), + ("paint.setFill", json!({"color": "#0000ff"}), "#0000ff"), + ("appearance.setItem", json!({"index": 0, "color": "#00ff00"}), "#00ff00"), + ]; + for (cmd, params, fill) in cases { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let lines = line_nodes(&s, id); + s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "color": "#ff0000"})).unwrap(); + assert_eq!(line_look(&line_nodes(&s, id)[1]).0, "#000000", "{cmd}: the other lines show black until the graph is drawn again"); + let mut p = params.clone(); + p["ids"] = json!([lines[1].id.0]); + s.execute(cmd, &p).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| *l == ("#ff0000".into(), 0.5, 1.0)), "{cmd}: {looks:?}"); + let fills: Vec = + line_nodes(&s, id).iter().map(|n| n.appearance.fill_paint().color().map(|c| c.to_hex()).unwrap_or_default()).collect(); + assert!(fills.iter().all(|f| f == fill), "{cmd}: {fills:?}"); + } +} + /// An opacity and a stroke weight given to a radar graph's ring are kept for its rings, and its spokes keep their own. #[test] fn transparency_and_stroke_weight_on_a_radar_ring_are_kept_for_its_rings() { diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index f9dca54298..95483e76c9 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -22,7 +22,7 @@ pub fn specs() -> Vec { "Stroke Options", ["Window", "Stroke"], None, - "{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads → {objects: how many objects took the stroke options}", + "{weight?: pt, cap?: butt|round|square, join?: miter|round|bevel, miterLimit?, align?: center|inside|outside, dash?: [d,g,…]|null (a 0 dash with a round or projecting cap draws dots or squares; a new pattern keeps the current offset and alignment), dashOffset? (exact dashes only), alignDashes?: bool (true: dashes fitted to corners and path ends, every run between them holding whole periods with a dash centred on each corner and end; false, the default for a new pattern: exact lengths), startArrow?, endArrow?: Arrow|ArrowOpen|LineArrow|Barbed|Concave|DoubleArrow|HalfArrowLeft|HalfArrowRight|Chevron|Feather|Swallowtail|Triangle|TriangleOpen|TriangleReverse|TriangleBar|Kite|Leaf|Drop|Circle|CircleOpen|HalfCircle|Oval|Target|Square|SquareOpen|Tag|TagOpen|Diamond|DiamondOpen|Hexagon|HexagonOpen|Star|Cross|Plus|Bar|DoubleBar|DotOnBar|Slash|DoubleSlash|Bracket|Fork|null|{custom: name} (a custom arrowhead of the arrowheads file, stroke.arrowheads.list)|{Custom: {name, path}} (a custom head with its art, as document.inspect reports one; refused when the path fills no area, parts thinner than a millionth of a head unit counting as none, or has more than 4096 anchors, more than 4096 subpaths or a point more than 64 head units from the tip) (HalfArrowLeft/Right: one barb, left or right of the direction the head points), arrowAlign?: \"extend\" (tip past the end point, default)|\"tip\" (tip on the end point; the stroke is shortened), profile?: \"uniform\"|\"lens\"|\"taperStart\"|\"taperEnd\"|\"pinch\"|\"teardrop\"|\"wave\"|a saved profile's name (stroke.widthProfile.list), widthPoints?, gradientMode? (as document.inspect reports them in strokeOptions, so those read back unchanged; ignored here: a custom profile is set with the Width tool, gradientMode with paint.editGradient), item?: stroke item index|null (omitted: the Appearance panel's active item if it is a stroke, else the top stroke, created when missing), ids?|id?, target?: \"object\"|\"contents\", aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection)} Without a stroke item, type takes weight, cap, join, miterLimit, align (around its glyph outlines; the type stays live) and the dash options as its characters' stroke (every run; text.setRangeStyle `strokeOptions` styles a range), and images and symbol instances (also in groups) are left alone. With nothing selected (and no ids) they set up the next object drawn (appearance.newArt; weight always does). On a path directly in a graph series, the graph also stores a weight it changes on the topmost visible stroke (docs/mcp.md); on a graph label's stroke row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters the stroke options they take; on a graph's axis line, tick mark or radar ring, the graph stores the paint, weight, opacity and blend mode of its topmost visible fill and stroke rows that the edit changes for every line of its kind, and not its caps, joins, dashes, alignment or arrowheads → {objects: how many objects took the stroke options}", has_doc, stroke_set ), diff --git a/docs/mcp.md b/docs/mcp.md index 46fef29862..5789c7ed50 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -873,10 +873,12 @@ the paint, weight, opacity and blend mode of its topmost visible fill and stroke opacity and blend mode. `paint.setFill`, `paint.setStroke` and the recolor commands also store them when given the graph, its Axes group or a group that holds the graph, so the lines keep the paint those commands give a whole graph. The other commands store them when given the line itself. `transparency.set` without an `item` and `object.setProps` -store only the object opacity and blend mode. `appearance.copyFrom` stores the rows whatever it picks up, with or -without `append`. The recolor commands, `paint.swap` and `paint.default` store a line's rows when they change them. The -other commands store them even when the line already showed them, except that rows equal to a kind's default stroke -(0.5 pt black for axis lines and tick marks, 0.25 pt gray for rings) are not saved. When one command reaches several lines of one kind, the frontmost line in +store only the object opacity and blend mode. `appearance.clear`, `appearance.transfer`, `graphicStyle.apply`, +`graphicStyle.redefine`, and `appearance.copyFrom` with every attribute picked up and applied or with `append`, store a +line's rows even when the line already showed them. The other commands, an `appearance.copyFrom` of some attributes +included, store only what they change on a line's rows; the kind keeps its other attributes, also when the line still +shows different ones until the graph is drawn again. Rows equal to a kind's default stroke (0.5 pt black for axis lines +and tick marks, 0.25 pt gray for rings) are not saved. When one command reaches several lines of one kind, the frontmost line in paint order sets what the kind keeps, whatever order the `ids` are in. A gradient is stored without its placement, and each line fits it when the graph is drawn again. The graph saves the rows as `axisRows` and `ringRows` in its label styles. Other stroke options (caps, joins, miter limit, alignment, dashes and arrowheads), rows below the topmost one of From a9b5bcc65658e5154dcbd442e697d99aa8c1ef79 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 11:45:33 -0800 Subject: [PATCH 3/6] MCP docs: a recolor stores a pie's legend label fill only when given the labels docs/mcp.md said the legend labels' fill on a pie with Legends in Wedges is stored whenever every legend label the command reaches ends up with one fill. The recolor commands also require the legend labels to be among the objects they are given; a recolor of the whole graph leaves the labels the graph's black or white. --- docs/mcp.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/mcp.md b/docs/mcp.md index a4d9d625b2..d816c0a46e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -857,8 +857,10 @@ own box when the graph is drawn again, so `paint.setGradientGeom` and the `paint placement they set there. A stroke weight and dashes are stored as the label shows them, also on a label that was scaled. When the characters of labels of one kind change differently, the frontmost label sets what the kind keeps. On a pie with Legends in Wedges whose legend labels have no fill of their own, the legend labels' fill is stored only when -every legend label the command reaches ends up with the same fill. Otherwise they are drawn again in black, or white on -a dark wedge. What they change on a graph's axis lines, tick marks and radar rings is stored as described below. +every legend label the command reaches ends up with the same fill. The recolor commands also need to be given the legend +labels themselves: a recolor given the graph or a group that holds it does not store their fill. When their fill is not +stored, they are drawn again in black, or white on a dark wedge. What these commands change on a graph's axis lines, tick marks +and radar rings is stored as described below. `text.setFormat` without `start` and `end`, on a graph or on its labels, stores the character and paragraph attributes it sets for each kind of label it reaches (value axis numbers, category labels, legend labels), and every label of that From cc26358b9f6f961286f0423e22ff0a1b3f7ae0ce Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 12:05:09 -0800 Subject: [PATCH 4/6] Graphs: an appearance moved to an axis line behind its source is kept Move Appearance captured the cleared source and the targets together, and graph lines are captured in paint order, so a source in front of its target replaced the kept axis rows with its cleared ones. The targets are now captured again after the source. --- crates/engine/src/cmd/appearance.rs | 5 +++-- crates/engine/src/cmd/graph/tests.rs | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index eab6f17fdf..9c810baeef 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -974,8 +974,9 @@ fn transfer(s: &mut Session, p: &Value) -> Result { rows.extend(painted_rows(d, both_kinds(&targets))); let painted = super::graph::capture_series_top_paints(d, &rows); let object = super::graph::capture_series_object_opacity(d, &changed); - // The targets last: on two labels of one kind, the target's rows are the ones the kind keeps. - let labels = super::graph::capture_label_rows(d, &changed); + // The targets last: on two labels of one kind, the target's rows are the ones the kind keeps. Graph lines are + // taken in paint order, so the targets are captured again on their own, after a cleared source in front of them. + let labels = super::graph::capture_label_rows(d, &changed) | super::graph::capture_label_rows(d, &targets); let all: Vec = from.iter().chain(&targets).chain(&group).copied().collect(); Ok(count_changed(d, &before, &all) + usize::from(kept || painted || object || labels)) })?; diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 8681442db3..7f516dd58b 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6473,6 +6473,21 @@ fn the_frontmost_axis_line_sets_what_its_recolor_keeps() { assert_eq!(kept.as_deref(), Some("#00ffff"), "the inverted red of the frontmost line"); } +/// An appearance moved from an axis line to one behind it is kept for every axis line, not the cleared source's. +#[test] +fn an_appearance_moved_to_an_axis_line_behind_is_kept() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let lines = line_nodes(&s, id); + let (back, front) = (lines[0].id, lines[lines.len() - 1].id); + s.execute("paint.setStroke", &json!({"ids": [front.0], "color": "#ff0000"})).unwrap(); + s.execute("appearance.transfer", &json!({"source": front.0, "target": back.0})).unwrap(); + let kept = spec(&s, id).label_styles.axis_rows.unwrap().paint.stroke.and_then(|p| p.color()).map(|c| c.to_hex()); + assert_eq!(kept.as_deref(), Some("#ff0000"), "the moved red, not the cleared source"); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#ff0000")); +} + /// A radar graph's spoke brought in front of its rings is still a spoke: what is set on it is kept for the spokes. #[test] fn a_radar_spoke_moved_in_front_of_the_rings_keeps_its_kind() { From 289fb4b7704880f60678e4007c31568b425dfe30 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 12:20:46 -0800 Subject: [PATCH 5/6] Graphs: a pick or added style without transparency keeps the opacity a line or label kind keeps A whole pick of every fill and stroke attribute, or an append pick, onto a graph's axis line, tick mark or radar ring stored the line's rows in full, object opacity and blend mode included, even when the pick did not apply the object's transparency. On a line that still showed 100% until the graph was drawn again, that replaced the opacity its kind kept (40% set on another line became 100%). An append pick onto a graph label, and graphicStyle.apply with add on a label or line, did the same. Without Transparency applied, these picks, and a style added on top, now store the fill and stroke rows and leave the kept object opacity and blend mode as they were. --- crates/engine/src/cmd/appearance.rs | 21 +++--- crates/engine/src/cmd/graph.rs | 9 +-- crates/engine/src/cmd/graph/series.rs | 99 ++++++++++++++++++--------- crates/engine/src/cmd/graph/tests.rs | 86 +++++++++++++++++++++++ crates/engine/src/cmd/style.rs | 11 ++- docs/mcp.md | 13 ++-- 6 files changed, 186 insertions(+), 53 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 9c810baeef..addacdfad6 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -129,7 +129,7 @@ pub fn specs() -> Vec { "Eyedropper", [], None, - "{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode, and with `append` its topmost visible fill and stroke rows; on a graph's axis line, tick mark or radar ring, its topmost visible fill and stroke rows and object opacity and blend mode for every line of its kind (a pick of some attributes without `append`: only what it changes) → {ids}", + "{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode when transparency is applied, and with `append` its topmost visible fill and stroke rows; on a graph's axis line, tick mark or radar ring, its topmost visible fill and stroke rows, and when transparency is applied its object opacity and blend mode, for every line of its kind (a pick of some attributes without `append`: only what it changes) → {ids}", has_doc, copy_from ), @@ -1675,18 +1675,23 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { let object = super::graph::capture_series_object_opacity(d, &objects); // Graph labels keep their new rows, characters and paragraphs per kind of label. // On type, only `append` adds rows and a transparency pick changes the object's opacity and blend mode; the other - // attributes go to the characters. - let rows = if append { - super::graph::capture_label_rows(d, &targets) - } else { - attrs.appearance.transparency && super::graph::capture_label_object_opacity(d, &targets) + // attributes go to the characters. Without a transparency pick, the object opacity and blend mode a kind keeps stay, + // also when the label or line picked onto still shows other ones until the graph is drawn again. + let transparency = attrs.appearance.transparency; + let rows = match (append, transparency) { + (true, true) => super::graph::capture_label_rows(d, &targets), + (true, false) => super::graph::capture_label_fill_stroke_rows(d, &targets), + (false, _) => transparency && super::graph::capture_label_object_opacity(d, &targets), }; // `append` adds rows and leaves the characters as they were. let text = !append && super::graph::capture_label_text(d, &targets, kept_text, kept_para)?; // A graph line is a path: a whole pick and `append` write its rows. A pick of some attributes keeps those it // changed, and the rest stay as its kind keeps them, which the line may not show yet. - let lines = - if rows_written { super::graph::capture_line_rows(d, &targets) } else { super::graph::capture_line_changes(&before, d, &targets) }; + let lines = match (rows_written, transparency) { + (true, true) => super::graph::capture_line_rows(d, &targets), + (true, false) => super::graph::capture_line_fill_stroke_rows(d, &targets), + (false, _) => super::graph::capture_line_changes(&before, d, &targets), + }; Ok(count_changed(d, &before, &targets) + usize::from(kept || painted || object || rows || text || lines)) })?; Ok(finish(s, &targets)) diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index e49ff91f04..808b538f3d 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -45,10 +45,11 @@ use generate::generate; #[cfg(test)] use series::default_series_color; pub(crate) use series::{ - LabelTextChange, capture_label_anti_alias, capture_label_changes, capture_label_object_opacity, capture_label_paragraphs, capture_label_rows, - capture_label_styles, capture_label_text, capture_line_changes, capture_line_rows, capture_series_object_opacity, capture_series_opacity, - capture_series_top_paints, is_design_art, is_graph_line, label_object_opacity_differs, labels_in, paint_targets, series_group_marks, - series_group_marks_where, series_marks_in, series_object_opacity_differs, shown_paint, + LabelTextChange, capture_label_anti_alias, capture_label_changes, capture_label_fill_stroke_rows, capture_label_object_opacity, + capture_label_paragraphs, capture_label_rows, capture_label_styles, capture_label_text, capture_line_changes, capture_line_fill_stroke_rows, + capture_line_rows, capture_series_object_opacity, capture_series_opacity, capture_series_top_paints, is_design_art, is_graph_line, + label_object_opacity_differs, labels_in, paint_targets, series_group_marks, series_group_marks_where, series_marks_in, + series_object_opacity_differs, shown_paint, }; #[cfg(test)] diff --git a/crates/engine/src/cmd/graph/series.rs b/crates/engine/src/cmd/graph/series.rs index cb10be3154..318ba68505 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -732,30 +732,51 @@ fn lines_of(doc: &Document, ids: &[NodeId]) -> Vec<(NodeId, NodeId, Line)> { out } -/// What lines of kind `line` keep (`slot`) after line `n` shows its rows ([`label_rows`]), or with `object_only` what -/// `slot` keeps with the line's object opacity and blend mode: `None` when that is how the graph draws them with no -/// kept rows. -fn line_rows_after(slot: Option<&vectorcraft_doc::LabelRows>, line: Line, n: &Node, object_only: bool) -> Option { +/// Which of the object rows ([`label_rows`]) a graph label or line shows its kind keeps after an edit. +#[derive(Clone, Copy, PartialEq, Eq)] +enum Keep { + /// All of them. + All, + /// Only the object opacity and blend mode; the fill and stroke rows stay as the kind keeps them. + Object, + /// The fill and stroke rows; the object opacity and blend mode stay as the kind keeps them. + Rows, +} + +/// `shown` with the parts of the rows `kept` keeps that `keep` leaves as they are. +fn keep_rows(kept: vectorcraft_doc::LabelRows, shown: vectorcraft_doc::LabelRows, keep: Keep) -> vectorcraft_doc::LabelRows { + match keep { + Keep::All => shown, + Keep::Object => { + let mut kept = kept; + (kept.paint.opacity, kept.paint.blend) = (shown.paint.opacity, shown.paint.blend); + kept + } + Keep::Rows => { + let mut shown = shown; + (shown.paint.opacity, shown.paint.blend) = (kept.paint.opacity, kept.paint.blend); + shown + } + } +} + +/// What lines of kind `line` keep (`slot`) after line `n` shows its rows ([`label_rows`]), of which `keep` says what is +/// taken from the line: `None` when that is how the graph draws them with no kept rows. +fn line_rows_after(slot: Option<&vectorcraft_doc::LabelRows>, line: Line, n: &Node, keep: Keep) -> Option { let shown = label_rows(n).unwrap_or_default(); - let rows = if object_only { - let mut kept = slot.cloned().unwrap_or_else(|| line.default_rows()); - (kept.paint.opacity, kept.paint.blend) = (shown.paint.opacity, shown.paint.blend); - kept - } else { - shown - }; + let rows = keep_rows(slot.cloned().unwrap_or_else(|| line.default_rows()), shown, keep); (rows != line.default_rows()).then_some(rows) } /// Keep the object rows ([`label_rows`]) of the graph lines among `ids` for every line of their kind (axis lines and tick -/// marks, or a radar graph's rings), with `object_only` only their object opacity and blend mode, even when a line -/// already showed them. Returns whether kept rows changed. -fn store_line_rows(doc: &mut Document, ids: &[NodeId], object_only: bool) -> bool { +/// marks, or a radar graph's rings), the part of them `keep` says, even when a line already showed them. Returns whether +/// kept rows changed. +fn store_line_rows(doc: &mut Document, ids: &[NodeId], keep: Keep) -> bool { let mut changed = false; for (id, graph, line) in lines_of(doc, ids) { let Some(spec) = doc.node(graph).and_then(|n| n.extras().graph.as_deref()) else { continue }; let Some(n) = doc.node(id) else { continue }; - let kept = line_rows_after(kept_line_rows(&spec.label_styles, line), line, n, object_only); + let kept = line_rows_after(kept_line_rows(&spec.label_styles, line), line, n, keep); let Some(spec) = doc.node_mut(graph).and_then(|n| n.extras_if_any().and_then(|e| e.graph.as_deref_mut())) else { continue }; let slot = line_slot(&mut spec.label_styles, line); changed |= *slot != kept; @@ -768,7 +789,14 @@ fn store_line_rows(doc: &mut Document, ids: &[NodeId], object_only: bool) -> boo /// for an edit that wrote their fill or stroke. Lines of a kind that the edit reached differently take the frontmost /// one's rows. Called inside the same edit, so they undo together. Returns whether kept rows changed. pub(crate) fn capture_line_rows(doc: &mut Document, ids: &[NodeId]) -> bool { - store_line_rows(doc, ids, false) + store_line_rows(doc, ids, Keep::All) +} + +/// [`capture_line_rows`] for an edit that wrote the fill and stroke rows of graph lines `ids` and left their object +/// opacity and blend mode alone: those stay as the kind keeps them, also when a line still shows other ones until the +/// graph is drawn again. +pub(crate) fn capture_line_fill_stroke_rows(doc: &mut Document, ids: &[NodeId]) -> bool { + store_line_rows(doc, ids, Keep::Rows) } /// Keep, for every line of their kind, the attributes of the object rows ([`label_rows`]) that an edit changed on the @@ -821,8 +849,8 @@ fn merge_row_edits(rows: &mut vectorcraft_doc::LabelRows, old: &vectorcraft_doc: take(&mut rows.stroke_under, &old.stroke_under, &new.stroke_under); } -/// Would [`store_line_rows`] with `object_only` change what a graph keeps for the lines among `ids`? Reads the document -/// without copying it. +/// Would [`store_line_rows`] with [`Keep::Object`] change what a graph keeps for the lines among `ids`? Reads the +/// document without copying it. fn line_object_opacity_differs(doc: &Document, ids: &[NodeId]) -> bool { let mut kept: Vec<(NodeId, Line, Option)> = vec![]; for (id, graph, line) in lines_of(doc, ids) { @@ -831,7 +859,7 @@ fn line_object_opacity_differs(doc: &Document, ids: &[NodeId]) -> bool { Some(i) => kept.swap_remove(i).2, None => kept_line_rows(&spec.label_styles, line).cloned(), }; - kept.push((graph, line, line_rows_after(slot.as_ref(), line, n, true))); + kept.push((graph, line, line_rows_after(slot.as_ref(), line, n, Keep::Object))); } kept.into_iter().any(|(graph, line, rows)| { doc.node(graph).and_then(|n| n.extras().graph.as_deref()).is_some_and(|spec| kept_line_rows(&spec.label_styles, line) != rows.as_ref()) @@ -844,14 +872,22 @@ fn line_object_opacity_differs(doc: &Document, ids: &[NodeId]) -> bool { /// looked up. The graph lines among `ids` keep their rows for every line of their kind too ([`capture_line_rows`]). /// Called inside the same edit, so they undo together. Returns whether kept rows changed. pub(crate) fn capture_label_rows(doc: &mut Document, ids: &[NodeId]) -> bool { - store_label_rows(doc, ids, false) + store_label_rows(doc, ids, Keep::All) } /// Keep the object opacity and blend mode of graph labels and graph lines `ids` for every label or line of their kind, as /// [`capture_label_rows`] keeps them, and leave the kept fill and stroke rows as they are. Returns whether what the graph /// keeps changed. pub(crate) fn capture_label_object_opacity(doc: &mut Document, ids: &[NodeId]) -> bool { - store_label_rows(doc, ids, true) + store_label_rows(doc, ids, Keep::Object) +} + +/// Keep the fill and stroke rows of graph labels and graph lines `ids` for every label or line of their kind, as +/// [`capture_label_rows`] keeps them, for an edit that left their object opacity and blend mode alone: those stay as the +/// kind keeps them, also when a label or line still shows other ones until the graph is drawn again. Returns whether what +/// the graph keeps changed. +pub(crate) fn capture_label_fill_stroke_rows(doc: &mut Document, ids: &[NodeId]) -> bool { + store_label_rows(doc, ids, Keep::Rows) } /// Would [`capture_label_object_opacity`] change what a graph keeps for labels `ids`? Reads the document without copying @@ -865,13 +901,13 @@ pub(crate) fn label_object_opacity_differs(doc: &Document, ids: &[NodeId]) -> bo Role::Category => &spec.label_styles.categories_rows, Role::Legend => &spec.label_styles.legend_rows, }; - *slot != kept_label_rows(slot, rows, true) + *slot != kept_label_rows(slot, rows, Keep::Object) }) } -/// [`capture_label_rows`], or with `object_only` [`capture_label_object_opacity`]. -fn store_label_rows(doc: &mut Document, ids: &[NodeId], object_only: bool) -> bool { - let mut changed = store_line_rows(doc, ids, object_only); +/// [`capture_label_rows`], [`capture_label_object_opacity`] or [`capture_label_fill_stroke_rows`], as `keep` says. +fn store_label_rows(doc: &mut Document, ids: &[NodeId], keep: Keep) -> bool { + let mut changed = store_line_rows(doc, ids, keep); for (graph, role, rows) in label_rows_of(doc, ids) { let Some(spec) = doc.node_mut(graph).and_then(|n| n.extras_if_any().and_then(|e| e.graph.as_deref_mut())) else { continue }; let slot = match role { @@ -879,26 +915,23 @@ fn store_label_rows(doc: &mut Document, ids: &[NodeId], object_only: bool) -> bo Role::Category => &mut spec.label_styles.categories_rows, Role::Legend => &mut spec.label_styles.legend_rows, }; - let kept = kept_label_rows(slot, rows, object_only); + let kept = kept_label_rows(slot, rows, keep); changed |= *slot != kept; *slot = kept; } changed } -/// What a kind keeps after a label of it shows `rows`: those rows, or with `object_only` what `slot` keeps with the -/// label's object opacity and blend mode. +/// What a kind keeps (`slot`) after a label of it shows `rows`, of which `keep` says what is taken from the label. fn kept_label_rows( slot: &Option, rows: Option, - object_only: bool, + keep: Keep, ) -> Option { - if !object_only { + if keep == Keep::All { return rows; } - let mut kept = slot.clone().unwrap_or_default(); - let shown = rows.unwrap_or_default(); - (kept.paint.opacity, kept.paint.blend) = (shown.paint.opacity, shown.paint.blend); + let kept = keep_rows(slot.clone().unwrap_or_default(), rows.unwrap_or_default(), keep); (kept != vectorcraft_doc::LabelRows::default()).then_some(kept) } diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 7f516dd58b..5d734003b2 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6590,6 +6590,92 @@ fn a_transparency_only_pick_on_an_axis_line_keeps_the_stroke_its_kind_keeps() { assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.2 - 0.5).abs() < 1e-6), "{looks:?}"); } +/// The Eyedropper Options that apply every fill and stroke attribute but not the object's transparency. +fn every_row_attribute_without_transparency() -> serde_json::Value { + let fill = json!({"color": true, "transparency": true, "overprint": true}); + let stroke = + json!({"color": true, "transparency": true, "overprint": true, "weight": true, "cap": true, "join": true, "miter": true, "dash": true}); + json!({"appearance": {"transparency": false, "fill": fill, "stroke": stroke}, "character": false, "paragraph": false}) +} + +/// An Eyedropper pick of every fill and stroke attribute without the object's transparency, with or without `append`, +/// keeps the object opacity the axis lines keep from another line, though the line it is applied to still shows 100%. +#[test] +fn a_pick_without_transparency_on_an_axis_line_keeps_the_opacity_its_kind_keeps() { + for append in [false, true] { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let rect = NodeId(s.execute("shape.rectangle", &json!({"x": 600, "y": 600, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap()); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#ff0000"})).unwrap(); + s.execute("paint.setFill", &json!({"ids": [rect.0], "none": true})).unwrap(); + let lines = line_nodes(&s, id); + s.execute("transparency.set", &json!({"ids": [lines[0].id.0], "opacity": 40})).unwrap(); + assert_eq!(line_look(&line_nodes(&s, id)[1]).2, 1.0, "append {append}: the other lines show 100% until the graph is drawn again"); + let pick = json!({"source": rect.0, "ids": [lines[1].id.0], "apply": every_row_attribute_without_transparency(), "append": append}); + s.execute("appearance.copyFrom", &pick).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.2 - 0.4).abs() < 1e-6), "append {append}: {looks:?}"); + } +} + +/// A graphic style added on top of a graph label's or axis line's appearance keeps the object opacity its kind keeps +/// from another label or line, though the one it is added to still shows 100%. +#[test] +fn a_graphic_style_added_to_a_label_or_axis_line_keeps_the_opacity_its_kind_keeps() { + for label in [false, true] { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let rect = NodeId(s.execute("shape.rectangle", &json!({"x": 600, "y": 600, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap()); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#ff0000"})).unwrap(); + s.execute("paint.setFill", &json!({"ids": [rect.0], "none": true})).unwrap(); + s.execute("graphicStyle.new", &json!({"id": rect.0, "name": "Red"})).unwrap(); + let (first, second) = if label { + (text_id(&s, id, "Axes", "Q1"), text_id(&s, id, "Axes", "Q2")) + } else { + let lines = line_nodes(&s, id); + (lines[0].id, lines[1].id) + }; + s.execute("transparency.set", &json!({"ids": [first.0], "opacity": 40})).unwrap(); + assert_eq!(s.doc().unwrap().doc.node(second).unwrap().opacity, 1.0, "label {label}: 100% until the graph is drawn again"); + s.execute("graphicStyle.apply", &json!({"name": "Red", "ids": [second.0], "add": true})).unwrap(); + if label { + let looks = redrawn_label_rows(&mut s, id); + for q in ["Q1", "Q2", "Q3"] { + let (rows, opacity) = rows_of(&looks, q); + assert!((opacity - 0.4).abs() < 1e-6 && rows.iter().any(|r| !r.0 && r.1 == "#ff0000"), "{q}: {rows:?} {opacity}"); + } + } else { + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.2 - 0.4).abs() < 1e-6), "{looks:?}"); + } + } +} + +/// An Eyedropper pick with `append` and without the object's transparency on a graph label keeps the object opacity its +/// kind keeps from another label, though the label it is applied to still shows 100%. +#[test] +fn an_appended_pick_without_transparency_on_a_label_keeps_the_opacity_its_kind_keeps() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let rect = NodeId(s.execute("shape.rectangle", &json!({"x": 600, "y": 600, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap()); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#ff0000"})).unwrap(); + s.execute("paint.setFill", &json!({"ids": [rect.0], "none": true})).unwrap(); + s.execute("transparency.set", &json!({"ids": [text_id(&s, id, "Axes", "Q1").0], "opacity": 40})).unwrap(); + let q2 = text_id(&s, id, "Axes", "Q2"); + assert_eq!(s.doc().unwrap().doc.node(q2).unwrap().opacity, 1.0, "Q2 shows 100% until the graph is drawn again"); + let pick = json!({"source": rect.0, "ids": [q2.0], "apply": every_row_attribute_without_transparency(), "append": true}); + s.execute("appearance.copyFrom", &pick).unwrap(); + let looks = redrawn_label_rows(&mut s, id); + for q in ["Q1", "Q2", "Q3"] { + let (rows, opacity) = rows_of(&looks, q); + assert!((opacity - 0.4).abs() < 1e-6, "{q}: {opacity}"); + assert!(rows.iter().any(|r| !r.0 && r.1 == "#ff0000"), "{q}: {rows:?}"); + } +} + /// An edit of some attributes on an axis line that still shows the default stroke keeps what it changes, and the stroke /// its kind keeps from another line stays: a cap is not kept, so it changes nothing the kind keeps. #[test] diff --git a/crates/engine/src/cmd/style.rs b/crates/engine/src/cmd/style.rs index bdcd759f4a..36716a4905 100644 --- a/crates/engine/src/cmd/style.rs +++ b/crates/engine/src/cmd/style.rs @@ -31,7 +31,7 @@ pub fn specs() -> Vec { "Apply Graphic Style", ["Window", "Graphic Styles"], None, - "{name, add?: bool, ids?|id? (layers too), target?: \"object\"|\"contents\"} give the objects (default: the selection; a group or layer itself, its fills and strokes painting its members and its effects applying to them as one piece; target contents: the objects inside instead) the style's appearance, opacity, blend mode, isolate and knockout, and link them to it (placed gradients land at the same place relative to each object's bounds); add: true (Alt-click) adds its fills, strokes and effects on top of the existing appearance instead and unlinks. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (with `add`: of the kinds of row the style shows) and, without `add`, the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and object opacity and blend mode for every label or line of its kind. With nothing selected (and no ids) the next object drawn takes the style instead (see appearance.newArt) → {newArt: true}", + "{name, add?: bool, ids?|id? (layers too), target?: \"object\"|\"contents\"} give the objects (default: the selection; a group or layer itself, its fills and strokes painting its members and its effects applying to them as one piece; target contents: the objects inside instead) the style's appearance, opacity, blend mode, isolate and knockout, and link them to it (placed gradients land at the same place relative to each object's bounds); add: true (Alt-click) adds its fills, strokes and effects on top of the existing appearance instead and unlinks. On a path directly in a graph series (a series group's id stands for those paths), the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke (with `add`: of the kinds of row the style shows) and, without `add`, the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows and, without `add`, its object opacity and blend mode for every label or line of its kind. With nothing selected (and no ids) the next object drawn takes the style instead (see appearance.newArt) → {newArt: true}", has_doc, style_apply ), @@ -374,8 +374,13 @@ fn style_apply(s: &mut Session, p: &Value) -> Result { super::appearance::clear_stood_for(d, &groups); super::appearance::capture_series_writes(&before, d, &ids, (true, true), (true, true), false, true); } - // A label keeps its new rows for its kind of label. - super::graph::capture_label_rows(d, &ids); + // A label or graph line keeps its new rows for its kind. A style added on top leaves the object opacity and blend + // mode, so the kind keeps its own. + if add { + super::graph::capture_label_fill_stroke_rows(d, &ids); + } else { + super::graph::capture_label_rows(d, &ids); + } Ok(()) })?; ok() diff --git a/docs/mcp.md b/docs/mcp.md index d816c0a46e..fece2ab3a3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -874,9 +874,10 @@ kind of label: the paint, weight, opacity and blend mode of its topmost visible their place relative to the Characters row, and the label's object opacity and blend mode. They store them even when the label already showed them. `transparency.set` without an `item`, `object.setProps` with an opacity or blend mode, and an `appearance.copyFrom` (Eyedropper) pick of transparency store only the label's object opacity and blend mode; -`appearance.copyFrom` with `append` stores the rows. When the graph is drawn again, every label of that kind gets what -is stored, with a placed gradient fitted to each label, and the graph saves it as `valuesRows`, `categoriesRows` and -`legendRows` in its label styles. Rows below the topmost one of each kind, a row's effects, other stroke options (caps, +`appearance.copyFrom` with `append` stores the rows, and the object opacity and blend mode only when it also applies +the object's transparency. `graphicStyle.apply` with `add` stores the rows and leaves the object opacity and blend +mode the kind keeps. When the graph is drawn again, every label of that kind gets what is stored, with a placed +gradient fitted to each label, and the graph saves it as `valuesRows`, `categoriesRows` and `legendRows` in its label styles. Rows below the topmost one of each kind, a row's effects, other stroke options (caps, joins, dashes) and effects applied with `effect.*` are not stored. When labels of one kind are edited together, the last one in the order of the targets (`ids` as given, otherwise paint order) sets what the kind keeps. `appearance.copyFrom` onto the whole text of a label also stores the character attributes it applies and, from type, @@ -896,8 +897,10 @@ store only the object opacity and blend mode. `appearance.clear`, `appearance.tr `graphicStyle.redefine`, and `appearance.copyFrom` with every attribute picked up and applied or with `append`, store a line's rows even when the line already showed them. The other commands, an `appearance.copyFrom` of some attributes included, store only what they change on a line's rows; the kind keeps its other attributes, also when the line still -shows different ones until the graph is drawn again. Rows equal to a kind's default stroke (0.5 pt black for axis lines -and tick marks, 0.25 pt gray for rings) are not saved. When one command reaches several lines of one kind, the frontmost line in +shows different ones until the graph is drawn again. An `appearance.copyFrom` that does not apply the object's +transparency, and `graphicStyle.apply` with `add`, leave the object opacity and blend mode a kind keeps as they are, +also when the line still shows other ones. Rows equal to a kind's default stroke (0.5 pt black for axis lines and tick +marks, 0.25 pt gray for rings) are not saved. When one command reaches several lines of one kind, the frontmost line in paint order sets what the kind keeps, whatever order the `ids` are in. A gradient is stored without its placement, and each line fits it when the graph is drawn again. The graph saves the rows as `axisRows` and `ringRows` in its label styles. Other stroke options (caps, joins, miter limit, alignment, dashes and arrowheads), rows below the topmost one of From 69005d7b3ee3fab7643a0a1ee7c55112ed2cc1a4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 13:30:21 -0800 Subject: [PATCH 6/6] Graphs: Default Fill and Stroke on an axis line stores the default rows for its kind Default Fill and Stroke on an axis line, tick mark or radar ring that already shows the default paint now stores the default fill and stroke rows for every line of its kind, so a stroke the kind kept from another line no longer comes back when the graph is drawn again. The object opacity and blend mode the kind keeps stay as they are. --- crates/engine/src/cmd/graph/tests.rs | 17 +++++++++++++++++ crates/engine/src/cmd/paint.rs | 5 ++++- docs/mcp.md | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 5d734003b2..ef469f7dd9 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6753,6 +6753,23 @@ fn default_fill_and_stroke_and_fill_to_stroke_on_an_axis_line_are_kept() { assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#0000ff"), "the blue fill on the stroke"); } +/// Default Fill and Stroke on an axis line that already shows the default paint is kept for every axis line, in place of +/// the stroke the kind keeps from another line, and leaves the object opacity the kind keeps from another line. +#[test] +fn default_fill_and_stroke_on_an_axis_line_that_shows_it_is_kept() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let lines = line_nodes(&s, id); + s.execute("paint.default", &json!({"ids": [lines[0].id.0]})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [lines[1].id.0], "color": "#ff0000"})).unwrap(); + s.execute("object.setProps", &json!({"ids": [lines[1].id.0], "opacity": 50})).unwrap(); + s.execute("paint.default", &json!({"ids": [lines[0].id.0]})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| (l.0.as_str(), l.1) == ("#000000", 1.0)), "the 1 pt black default stroke: {looks:?}"); + assert!(looks.iter().all(|l| (l.2 - 0.5).abs() < 1e-6), "the kind keeps its 50% opacity: {looks:?}"); +} + #[test] fn pie_names_and_wedge_labels_keep_their_style() { let mut s = Session::new(); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 32e1a8bd38..264d23a737 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1020,7 +1020,10 @@ fn default_paint(s: &mut Session, p: &Value) -> Result { } let kept = super::appearance::capture_series_writes(&before, d, &ids, (true, true), (true, true), false, false); let labels = super::graph::capture_label_changes(&before, d, &ids, false, None); - Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels)) + // The graph keeps the default fill and stroke rows for every line of a kind it reached, also when one already + // showed them; the object opacity the kind keeps stays. + let lines = super::graph::capture_line_fill_stroke_rows(d, &ids); + Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels || lines)) })?; } super::newart::reset(s); diff --git a/docs/mcp.md b/docs/mcp.md index fece2ab3a3..e32f35ad8e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -899,7 +899,8 @@ line's rows even when the line already showed them. The other commands, an `appe included, store only what they change on a line's rows; the kind keeps its other attributes, also when the line still shows different ones until the graph is drawn again. An `appearance.copyFrom` that does not apply the object's transparency, and `graphicStyle.apply` with `add`, leave the object opacity and blend mode a kind keeps as they are, -also when the line still shows other ones. Rows equal to a kind's default stroke (0.5 pt black for axis lines and tick +also when the line still shows other ones. `paint.default` stores the default fill and stroke rows for a line's kind +even when the line already showed them, and leaves the object opacity and blend mode the kind keeps. Rows equal to a kind's default stroke (0.5 pt black for axis lines and tick marks, 0.25 pt gray for rings) are not saved. When one command reaches several lines of one kind, the frontmost line in paint order sets what the kind keeps, whatever order the `ids` are in. A gradient is stored without its placement, and each line fits it when the graph is drawn again. The graph saves the rows as `axisRows` and `ringRows` in its label