From 021e4dc4ca25aafc61688f5bebb1a20d8136cdc6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 21:38:42 -0800 Subject: [PATCH 1/5] Graphs: a style added to a label or axis line keeps only the rows it shows graphicStyle.apply with add stored both the fill and stroke rows a graph label or line showed for its kind. A fill-only style added to one line copied that line's old stroke over the stroke another line had set, and the next redraw lost it. The kind now keeps only the kinds of row visible in the style, with the other kind of row kept in its place relative to the characters. --- crates/engine/src/cmd/graph.rs | 10 ++-- crates/engine/src/cmd/graph/series.rs | 38 ++++++++++++++ crates/engine/src/cmd/graph/tests.rs | 76 +++++++++++++++++++++++++++ crates/engine/src/cmd/style.rs | 10 ++-- docs/mcp.md | 7 +-- 5 files changed, 127 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 50f3333627..3714fef36c 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -46,11 +46,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_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_groups_among, series_marks_in, - series_object_opacity_differs, shown_paint, + LabelTextChange, capture_label_added_rows, 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_groups_among, 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 564f01104f..c6255fa353 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -825,6 +825,9 @@ enum Keep { Object, /// The fill and stroke rows; the object opacity and blend mode stay as the kind keeps them. Rows, + /// The fill row (`fill`) and the stroke row (`stroke`) of an edit that put new rows of those kinds on top of the stack; + /// the other kind of row and the object opacity and blend mode stay as the kind keeps them. + Added { fill: bool, stroke: bool }, } /// `shown` with the parts of the rows `kept` keeps that `keep` leaves as they are. @@ -841,6 +844,33 @@ fn keep_rows(kept: vectorcraft_doc::LabelRows, shown: vectorcraft_doc::LabelRows (shown.paint.opacity, shown.paint.blend) = (kept.paint.opacity, kept.paint.blend); shown } + Keep::Added { fill: false, stroke: false } => kept, + Keep::Added { fill, stroke } => { + // Whether the kept row of the kind the edit did not add paints below the characters: the kept rows, from the + // bottom, are the stroke and the fill (in the order `stroke_under` gives) and the bottom `below` of them paint + // below the characters. + let other_below = { + let present = |f: bool| if f { kept.paint.fill.is_some() } else { kept.paint.stroke.is_some() }; + let order = if kept.stroke_under { [false, true] } else { [true, false] }; + let at = order.iter().filter(|f| present(**f)).position(|f| *f != fill); + at.is_some_and(|at| at < usize::from(kept.below.unwrap_or(0))) + }; + let (mut rows, s) = (kept, &shown.paint); + if fill { + (rows.paint.fill, rows.paint.fill_opacity, rows.paint.fill_blend) = (s.fill.clone(), s.fill_opacity, s.fill_blend); + } + if stroke { + (rows.paint.stroke, rows.paint.stroke_width, rows.paint.stroke_opacity, rows.paint.stroke_blend) = + (s.stroke.clone(), s.stroke_width, s.stroke_opacity, s.stroke_blend); + } + // The added row paints above the characters and above a kept row of the other kind, which keeps its place. + (rows.below, rows.stroke_under) = match (fill, stroke) { + (true, false) => (other_below.then_some(1), rows.paint.stroke.is_some()), + (false, true) => (other_below.then_some(1), false), + (true, true) | (false, false) => (shown.below, shown.stroke_under), + }; + rows + } } } @@ -974,6 +1004,14 @@ pub(crate) fn capture_label_fill_stroke_rows(doc: &mut Document, ids: &[NodeId]) store_label_rows(doc, ids, Keep::Rows) } +/// [`capture_label_fill_stroke_rows`] for an edit that put a new fill row (`fill`) or stroke row (`stroke`) on top of +/// graph labels and graph lines `ids`: only those kinds of row are kept for every label or line of their kind, and the +/// other kind stays as the kind keeps it, also when a label or line still shows another one until the graph is drawn +/// again. Returns whether what the graph keeps changed. +pub(crate) fn capture_label_added_rows(doc: &mut Document, ids: &[NodeId], (fill, stroke): (bool, bool)) -> bool { + store_label_rows(doc, ids, Keep::Added { fill, stroke }) +} + /// Would [`capture_label_object_opacity`] change what a graph keeps for labels `ids`? Reads the document without copying /// it. pub(crate) fn label_object_opacity_differs(doc: &Document, ids: &[NodeId]) -> bool { diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 3499a25dff..181913dba5 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -7114,6 +7114,82 @@ fn a_graphic_style_added_to_a_label_or_axis_line_keeps_the_opacity_its_kind_keep } } +/// A graphic style that shows only a fill, added on top of a graph label's or axis line's appearance, keeps its fill for +/// the kind and leaves the stroke the kind keeps from another label or line, though the one it is added to still shows +/// its old stroke. +#[test] +fn a_fill_only_graphic_style_added_to_a_label_or_axis_line_keeps_the_stroke_its_kind_keeps() { + for label in [true, false] { + 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.setFill", &json!({"ids": [rect.0], "color": "#00ff00"})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#ff0000"})).unwrap(); + s.execute("appearance.setItem", &json!({"ids": [rect.0], "index": top_row(&s, rect, false), "visible": false})).unwrap(); + s.execute("graphicStyle.new", &json!({"id": rect.0, "name": "Green"})).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) + }; + if label { + s.execute("appearance.addStroke", &json!({"ids": [first.0]})).unwrap(); + let at = top_row(&s, first, false); + s.execute("appearance.setItem", &json!({"ids": [first.0], "index": at, "color": "#0000ff", "weight": 2})).unwrap(); + } else { + s.execute("paint.setStroke", &json!({"ids": [first.0], "color": "#0000ff"})).unwrap(); + assert_eq!(line_look(&line_nodes(&s, id)[1]).0, "#000000", "the other lines show black until the graph is drawn again"); + } + s.execute("graphicStyle.apply", &json!({"name": "Green", "ids": [second.0], "add": true})).unwrap(); + if label { + let looks = redrawn_label_rows(&mut s, id); + for q in ["Q1", "Q2", "Q3"] { + let (rows, _) = rows_of(&looks, q); + assert!(rows.iter().any(|r| r.0 && r.1 == "#00ff00"), "{q}: {rows:?}"); + assert!(rows.iter().any(|r| !r.0 && r.1 == "#0000ff"), "{q}: {rows:?}"); + assert!(!rows.iter().any(|r| r.1 == "#ff0000"), "{q}: {rows:?}"); + } + } else { + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#0000ff"), "{looks:?}"); + let fills: Vec> = line_nodes(&s, id).iter().map(|n| n.appearance.fill_paint().color().map(|c| c.to_hex())).collect(); + assert!(fills.iter().all(|f| f.as_deref() == Some("#00ff00")), "{fills:?}"); + } + } +} + +/// A graphic style that shows only a fill, added on top of a graph label, leaves the stroke its kind keeps below the +/// characters there, and the added fill paints above the characters, though the label it is added to has no row below +/// them. +#[test] +fn a_fill_only_graphic_style_added_to_a_label_keeps_the_kind_stroke_below_the_characters() { + 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.setFill", &json!({"ids": [rect.0], "color": "#00ff00"})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#ff0000"})).unwrap(); + s.execute("appearance.setItem", &json!({"ids": [rect.0], "index": top_row(&s, rect, false), "visible": false})).unwrap(); + s.execute("graphicStyle.new", &json!({"id": rect.0, "name": "Green"})).unwrap(); + let (q1, q2) = (text_id(&s, id, "Axes", "Q1"), text_id(&s, id, "Axes", "Q2")); + s.execute("appearance.addStroke", &json!({"ids": [q1.0]})).unwrap(); + let at = top_row(&s, q1, false); + s.execute("appearance.setItem", &json!({"ids": [q1.0], "index": at, "color": "#0000ff", "weight": 2})).unwrap(); + s.execute("appearance.moveItem", &json!({"ids": [q1.0], "from": "contents", "to": at + 1})).unwrap(); + s.execute("graphicStyle.apply", &json!({"name": "Green", "ids": [q2.0], "add": true})).unwrap(); + let looks = redrawn_label_rows(&mut s, id); + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + for q in ["Q1", "Q2", "Q3"] { + let (rows, _) = rows_of(&looks, q); + assert_eq!(rows.iter().map(|r| (r.0, r.1.as_str())).collect::>(), [(false, "#0000ff"), (true, "#00ff00")], "{q}"); + let label = + group(&n, "Axes").children().unwrap().iter().find(|c| matches!(&c.kind, NodeKind::Text(t) if t.plain_text() == q)).unwrap().clone(); + assert_eq!(label.appearance.contents_at(), 1, "{q}: the stroke paints below the characters and the fill above them"); + } +} + /// 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] diff --git a/crates/engine/src/cmd/style.rs b/crates/engine/src/cmd/style.rs index 36716a4905..a5f4e67592 100644 --- a/crates/engine/src/cmd/style.rs +++ b/crates/engine/src/cmd/style.rs @@ -364,6 +364,9 @@ fn style_apply(s: &mut Session, p: &Value) -> Result { let shows = |kind: bool| g.appearance.items.iter().any(|it| it.is_fill() == kind && it.visible()); let kinds = (shows(true), shows(false)); super::appearance::capture_series_writes(&before, d, &ids, kinds, kinds, false, false); + // A label or graph line keeps those kinds of row for its kind. A style added on top leaves the object opacity + // and blend mode, so the kind keeps its own. + super::graph::capture_label_added_rows(d, &ids, kinds); } else { d.graphic_style_id(i); let g = d.graphic_styles[i].clone(); @@ -373,12 +376,7 @@ 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 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 { + // A label or graph line keeps its new rows for its kind. super::graph::capture_label_rows(d, &ids); } Ok(()) diff --git a/docs/mcp.md b/docs/mcp.md index e4385deeda..6af7bf7121 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -895,8 +895,8 @@ their place relative to the Characters row, and the label's object opacity and b 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, 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 +the object's transparency. `graphicStyle.apply` with `add` stores only the kinds of row that are visible in the style +and leaves the other kind of row and 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. @@ -919,7 +919,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. `paint.default` stores the default fill and stroke rows for a line's kind +also when the line still shows other ones. `graphicStyle.apply` with `add` stores only the kinds of row that are +visible in the style, and the kind keeps its other kind of row. `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 From 94d2625c60bdfa9db390f1f54a4288043143d912 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 06:57:45 -0800 Subject: [PATCH 2/5] Graphs: an appended pick or a swap on a label or axis line keeps only what it changes appearance.copyFrom with append stored every fill and stroke row a graph label or line showed for its kind. A fill-only pick appended to one line or label copied its old stroke over the stroke another one had set, and the next redraw lost it. The kind now keeps only the kinds of row the pick adds that are visible in the source, as graphicStyle.apply with add does, and the object opacity and blend mode only when the pick applies the object's transparency. paint.swap on an axis line stored the line's whole fill and stroke rows, so a fill opacity its kind kept from another line went back to 100%. It now keeps only the paints the swap changed. --- crates/engine/src/cmd/appearance.rs | 29 ++++++----- crates/engine/src/cmd/graph.rs | 10 ++-- crates/engine/src/cmd/graph/series.rs | 17 ++---- crates/engine/src/cmd/graph/tests.rs | 74 +++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 9 ++-- docs/mcp.md | 12 +++-- 6 files changed, 110 insertions(+), 41 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index bb53d2dd37..d61fc78d52 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, and the art of a graph design in a series, which is left out: 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}", + "{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, and the art of a graph design in a series, which is left out: 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` the topmost visible fill or stroke row of each kind it adds; 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 (with `append`, only the kinds of row it adds; a pick of some attributes without `append`: only what it changes) → {ids}", has_doc, copy_from ), @@ -1804,22 +1804,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. 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. + // attributes go to the characters. `append` keeps only the kinds of row it added, as `graphicStyle.apply` with + // `add` does, for the graph lines among the targets too. Without a transparency pick, the object opacity and blend + // mode a kind keeps stay, and so does the kind of row `append` did not add, 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), - }; + let added = append && super::graph::capture_label_added_rows(d, &targets, paints); + let rows = transparency && super::graph::capture_label_object_opacity(d, &targets); + let rows = added || rows; // `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 = 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), + // A graph line is a path: a whole pick writes 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 = match (append, whole, transparency) { + (true, ..) => false, + (false, true, true) => super::graph::capture_line_rows(d, &targets), + (false, true, false) => super::graph::capture_line_fill_stroke_rows(d, &targets), + (false, false, _) => super::graph::capture_line_changes(&before, d, &targets), }; Ok(count_changed(d, &before, &targets) + usize::from(kept || painted || object || rows || text || lines)) })?; diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 5aee115f59..d1be18ff64 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -48,11 +48,11 @@ use generate::generate; #[cfg(test)] use series::default_series_color; pub(crate) use series::{ - LabelTextChange, capture_label_added_rows, 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, plain_labels, series_group_marks, series_group_marks_where, - series_groups_among, series_marks_in, series_object_opacity_differs, shown_paint, + LabelTextChange, capture_label_added_rows, 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_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, plain_labels, series_group_marks, series_group_marks_where, series_groups_among, + 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 0ea782e31a..d21e555588 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -1427,17 +1427,10 @@ pub(crate) fn capture_label_object_opacity(doc: &mut Document, ids: &[NodeId]) - } /// 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) -} - -/// [`capture_label_fill_stroke_rows`] for an edit that put a new fill row (`fill`) or stroke row (`stroke`) on top of -/// graph labels and graph lines `ids`: only those kinds of row are kept for every label or line of their kind, and the -/// other kind stays as the kind keeps it, also when a label or line still shows another one until the graph is drawn -/// again. Returns whether what the graph keeps changed. +/// [`capture_label_rows`] keeps them, for an edit that put a new fill row (`fill`) or stroke row (`stroke`) on top of +/// them: only those kinds of row are kept, and the other kind and the object opacity and blend mode 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_added_rows(doc: &mut Document, ids: &[NodeId], (fill, stroke): (bool, bool)) -> bool { store_label_rows(doc, ids, Keep::Added { fill, stroke }) } @@ -1457,7 +1450,7 @@ pub(crate) fn label_object_opacity_differs(doc: &Document, ids: &[NodeId]) -> bo }) } -/// [`capture_label_rows`], [`capture_label_object_opacity`] or [`capture_label_fill_stroke_rows`], as `keep` says. +/// [`capture_label_rows`], [`capture_label_object_opacity`] or [`capture_label_added_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) { diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index d40d919d11..42a7f2a46c 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -7564,6 +7564,28 @@ fn recoloring_a_graph_keeps_its_axis_lines_paint() { assert!(!label_paint.is_empty() && label_paint.iter().all(|l| *l == ("#ffffff".to_string(), true)), "{label_paint:?}"); } +/// Swap Fill and Stroke on an axis line keeps the swapped paint for every axis line and leaves the fill opacity the axis +/// lines keep from another line, though the line swapped still shows 100%. +#[test] +fn swapping_an_axis_lines_paint_keeps_the_fill_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 lines = line_nodes(&s, id); + let (first, second) = (lines[0].id, lines[1].id); + s.execute("paint.setFill", &json!({"ids": [first.0], "color": "#00ff00"})).unwrap(); + s.execute("transparency.set", &json!({"ids": [first.0], "item": top_row(&s, first, true), "opacity": 40})).unwrap(); + let shown = s.doc().unwrap().doc.node(second).unwrap().appearance.fill().map(|f| f.opacity); + assert!(shown.is_none_or(|o| o == 1.0), "the other lines show 100% until the graph is drawn again: {shown:?}"); + s.execute("paint.swap", &json!({"ids": [second.0]})).unwrap(); + s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap(); + for n in line_nodes(&s, id) { + let fill = n.appearance.fill().map(|f| (f.paint.color().map(|c| c.to_hex()), f.opacity)); + assert!(fill.as_ref().is_some_and(|(c, o)| c.as_deref() == Some("#000000") && (*o - 0.4).abs() < 1e-6), "{fill:?}"); + assert!(n.appearance.stroke_paint().is_none(), "the swapped line had no fill, so the lines have no stroke"); + } +} + /// A stroke given the whole graph, or its Axes group, is kept for its axis lines. #[test] fn a_stroke_given_the_whole_graph_or_its_axes_group_is_kept_for_its_axis_lines() { @@ -7888,6 +7910,58 @@ fn an_appended_pick_without_transparency_on_a_label_keeps_the_opacity_its_kind_k } } +/// An Eyedropper pick with `append` from a source that shows only a fill, on a graph label or axis line, keeps the added +/// fill for the kind and leaves the stroke the kind keeps from another label or line, though the one picked onto still +/// shows its old stroke. With the object's transparency, the kind also keeps the picked object opacity. +#[test] +fn an_appended_fill_only_pick_on_a_label_or_axis_line_keeps_the_stroke_its_kind_keeps() { + for (label, transparency) in [(true, false), (false, false), (true, true), (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.setFill", &json!({"ids": [rect.0], "color": "#00ff00"})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#ff0000"})).unwrap(); + s.execute("appearance.setItem", &json!({"ids": [rect.0], "index": top_row(&s, rect, false), "visible": false})).unwrap(); + s.execute("transparency.set", &json!({"ids": [rect.0], "opacity": 50})).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) + }; + if label { + s.execute("appearance.addStroke", &json!({"ids": [first.0]})).unwrap(); + let at = top_row(&s, first, false); + s.execute("appearance.setItem", &json!({"ids": [first.0], "index": at, "color": "#0000ff", "weight": 2})).unwrap(); + } else { + s.execute("paint.setStroke", &json!({"ids": [first.0], "color": "#0000ff"})).unwrap(); + assert_eq!(line_look(&line_nodes(&s, id)[1]).0, "#000000", "the other lines show black until the graph is drawn again"); + } + let mut apply = every_row_attribute_without_transparency(); + apply["appearance"]["transparency"] = json!(transparency); + let pick = json!({"source": rect.0, "ids": [second.0], "apply": apply, "append": true}); + s.execute("appearance.copyFrom", &pick).unwrap(); + let opacity = if transparency { 0.5 } else { 1.0 }; + let case = format!("label {label}, transparency {transparency}"); + if label { + let looks = redrawn_label_rows(&mut s, id); + for q in ["Q1", "Q2", "Q3"] { + let (rows, shown) = rows_of(&looks, q); + assert!(rows.iter().any(|r| r.0 && r.1 == "#00ff00"), "{case}, {q}: {rows:?}"); + assert!(rows.iter().any(|r| !r.0 && r.1 == "#0000ff"), "{case}, {q}: {rows:?}"); + assert!(!rows.iter().any(|r| r.1 == "#ff0000"), "{case}, {q}: {rows:?}"); + assert!((shown - opacity).abs() < 1e-6, "{case}, {q}: {shown}"); + } + } else { + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#0000ff" && (l.2 - opacity).abs() < 1e-6), "{case}: {looks:?}"); + let fills: Vec> = line_nodes(&s, id).iter().map(|n| n.appearance.fill_paint().color().map(|c| c.to_hex())).collect(); + assert!(fills.iter().all(|f| f.as_deref() == Some("#00ff00")), "{case}: {fills:?}"); + } + } +} + /// 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/paint.rs b/crates/engine/src/cmd/paint.rs index 5adb472125..6990524df6 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -39,7 +39,7 @@ pub fn specs() -> Vec { "Swap Fill and Stroke", [], Some("Shift+X"), - "{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md)", + "{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring what the swap changes on its rows for every line of its kind (exceptions: docs/mcp.md)", has_doc, swap ), @@ -998,11 +998,10 @@ 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); + // The graph lines among `ids` keep the paint the swap changed for every line of their kind; the opacity and blend + // modes the kind keeps stay. let labels = super::graph::capture_label_changes(&before, d, &ids, false, None); - // 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)) + Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels)) })?; } if s.paint.stroke.is_none() && !s.paint.fill.is_none() && s.paint.stroke_width == 0.0 { diff --git a/docs/mcp.md b/docs/mcp.md index 56ad3fb3d3..f42152ef5f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -930,8 +930,9 @@ 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, and the object opacity and blend mode only when it also applies -the object's transparency. `graphicStyle.apply` with `add` stores only the kinds of row that are visible in the style +`appearance.copyFrom` with `append` stores only the kinds of row it adds that are visible in the source, and the object +opacity and blend mode only when it also applies the object's transparency; the kind keeps its other kind of row. +`graphicStyle.apply` with `add` stores only the kinds of row that are visible in the style and leaves the other kind of row and 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 @@ -950,13 +951,14 @@ opacity and blend mode. `paint.setFill`, `paint.setStroke` and the recolor comma 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.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 +`graphicStyle.redefine`, and `appearance.copyFrom` with every attribute picked up and applied, 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. 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. `graphicStyle.apply` with `add` stores only the kinds of row that are -visible in the style, and the kind keeps its other kind of row. `paint.default` stores the default fill and stroke rows for a line's kind +visible in the style. `appearance.copyFrom` with `append` stores only the kinds of row it adds that are visible in the +source. After either one, the kind keeps its other kind of row, also when the line still shows another one. `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 From f60d329363f865b1bdcb9b6c3fdc15c51e68b2ea Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 10:39:22 -0800 Subject: [PATCH 3/5] Graphs: rewritten axis line paint and no-op reorders keep what a kind keeps paint.setFill, paint.setStroke, addon.color.fillToStroke and addon.color.strokeToFill on an axis line, tick mark or radar ring that already showed the paint they write stored nothing, so a paint its kind kept from another line came back when the graph was drawn again. The paint written to the line's topmost visible fill or stroke row is now stored for its kind; its other attributes stay as the kind keeps them. That capture runs after the change-based one, so the frontmost written line sets the paint its kind keeps. An appearance.moveItem that left a graph label's rows or Contents row where they were stored that label's rows for its kind, replacing the rows the kind kept from another label, and recorded an undo step. A reorder now keeps rows only for the labels and lines whose stack it changed. --- crates/engine/src/cmd/addons/color.rs | 3 +- crates/engine/src/cmd/appearance.rs | 17 ++++++-- crates/engine/src/cmd/graph.rs | 6 +-- crates/engine/src/cmd/graph/series.rs | 33 ++++++++++++++++ crates/engine/src/cmd/graph/tests.rs | 57 +++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 4 +- docs/mcp.md | 9 ++++- 7 files changed, 118 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/cmd/addons/color.rs b/crates/engine/src/cmd/addons/color.rs index 8462e35207..f5a51beabb 100644 --- a/crates/engine/src/cmd/addons/color.rs +++ b/crates/engine/src/cmd/addons/color.rs @@ -260,7 +260,8 @@ 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_changes(&before, d, &painted); + // A line keeps the paint written to it, also when it already showed it, and the rest stays as its kind keeps it. + let lines = super::super::graph::capture_line_changes(&before, d, &painted) | super::super::graph::capture_line_paint_writes(d, &written); Ok(objects + usize::from(series || labels || lines)) })?; } diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index d61fc78d52..568f6ab50b 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -690,12 +690,14 @@ pub(crate) fn edit_items_then( rows.push(*id); } } - 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); let lines = super::graph::capture_line_changes(&before, d, &edited); + // `after` runs last, so what it keeps for a graph line (a paint written to a line that already showed it) is not + // replaced by the change of a line behind it. + let more = after(&before, d, &edited)?; Ok(count_changed(d, &before, &edited) + usize::from(more || labels || lines)) })?; Ok(aimed) @@ -712,6 +714,13 @@ fn capture_row_edits(before: &vectorcraft_doc::Document, d: &mut vectorcraft_doc labels || lines } +/// [`capture_row_edits`] for a reorder: only the graph labels and lines among `ids` whose rows it changed keep them, so +/// a reorder that leaves a label's or line's stack as it was keeps what its kind keeps from another label or line. +fn capture_reorder_edits(before: &vectorcraft_doc::Document, d: &mut vectorcraft_doc::Document, ids: &[NodeId]) -> bool { + let moved: Vec = ids.iter().copied().filter(|id| d.node(*id).map(|n| &n.appearance) != before.node(*id).map(|n| &n.appearance)).collect(); + capture_row_edits(before, d, &moved) +} + /// The first of `ids` that [`edit_items`] aimed at `item` with `of` changes, and the item it changes there. Read it /// before the edit: once edited, a row that was equal to a row of the art of `of` no longer is. pub(crate) fn first_edited(s: &Session, item: ItemTarget, of: Option, ids: &[NodeId]) -> Option<(NodeId, ItemTarget)> { @@ -1457,7 +1466,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 = capture_row_edits(&before, d, &ids); + let labels = capture_reorder_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. @@ -1503,7 +1512,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 = capture_row_edits(&before, d, ids); + let labels = capture_reorder_edits(&before, d, ids); Ok(count_changed(d, &before, ids) + usize::from(labels)) })?; Ok(json!({ "contents": slot })) diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index d1be18ff64..6e15090100 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -50,9 +50,9 @@ use series::default_series_color; pub(crate) use series::{ LabelTextChange, capture_label_added_rows, 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_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, plain_labels, series_group_marks, series_group_marks_where, series_groups_among, - series_marks_in, series_object_opacity_differs, shown_paint, + capture_line_paint_writes, 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, plain_labels, series_group_marks, series_group_marks_where, + series_groups_among, 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 d21e555588..1ee708e00e 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -1367,6 +1367,39 @@ pub(crate) fn capture_line_changes(before: &Document, doc: &mut Document, ids: & changed } +/// Keep, for every line of their kind, the paint an edit wrote to row `at` of graph line `id` for each `(id, at)` in +/// `written` when that row is the line's topmost visible fill or stroke, also when the line already showed that paint: +/// the paint replaces the one its kind keeps from another line. The other attributes stay as the kind keeps them. Lines +/// of a kind take the frontmost one's paint. Called inside the same edit, so they undo together. Returns whether kept +/// rows changed. +pub(crate) fn capture_line_paint_writes(doc: &mut Document, written: &[(NodeId, usize)]) -> bool { + let ids: Vec = written.iter().map(|(id, _)| *id).collect(); + let mut changed = false; + for (id, graph, line) in lines_of(doc, &ids) { + let Some(n) = doc.node(id) else { continue }; + let items = &n.appearance.items; + let wrote = |fill: bool| items.iter().rposition(|it| it.is_fill() == fill && it.visible()).is_some_and(|at| written.contains(&(id, at))); + let (fill, stroke) = (wrote(true), wrote(false)); + if !fill && !stroke { + continue; + } + let shown = label_rows(n).unwrap_or_default().paint; + 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()); + if fill { + rows.paint.fill = shown.fill; + } + if stroke { + rows.paint.stroke = shown.stroke; + } + 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() diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 42a7f2a46c..b8d431dfd0 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -8056,6 +8056,63 @@ fn default_fill_and_stroke_on_an_axis_line_that_shows_it_is_kept() { assert!(looks.iter().all(|l| (l.2 - 0.5).abs() < 1e-6), "the kind keeps its 50% opacity: {looks:?}"); } +/// A stroke paint written to an axis line that already shows it is kept for every axis line, in place of the stroke the +/// kind keeps from another line. +#[test] +fn a_stroke_written_to_an_axis_line_that_shows_it_is_kept() { + let cases = [("paint.setStroke", json!({"color": "#000000"})), ("addon.color.fillToStroke", json!({}))]; + every_case(cases, |(cmd, params)| { + 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.setFill", &json!({"ids": [lines[1].id.0], "color": "#000000"})).unwrap(); + 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.0 == "#000000"), "{cmd}: {looks:?}"); + }); +} + +/// A reorder that leaves an axis line's rows as they were keeps what its kind keeps from another line and is no edit. +#[test] +fn a_reorder_that_changes_nothing_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 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 stroke = top_row(&s, lines[1].id, false); + let undo = s.doc().unwrap().history.undo.len(); + s.execute("appearance.moveItem", &json!({"ids": [lines[1].id.0], "from": stroke, "to": stroke})).unwrap(); + s.execute("appearance.moveItem", &json!({"ids": [lines[1].id.0], "indices": [stroke], "to": stroke})).unwrap(); + assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changed"); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000"), "{looks:?}"); +} + +/// A Contents row move that leaves a label's stack as it was keeps the rows its kind keeps from another label and is no +/// edit. +#[test] +fn a_reorder_that_changes_nothing_on_a_label_keeps_the_rows_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 v = text_id(&s, id, "Axes", "4"); + s.execute("appearance.addStroke", &json!({"ids": [v.0]})).unwrap(); + s.execute("appearance.setItem", &json!({"ids": [v.0], "index": 0, "color": "#0000ff", "weight": 2})).unwrap(); + let zero = text_id(&s, id, "Axes", "0"); + let undo = s.doc().unwrap().history.undo.len(); + s.execute("appearance.moveItem", &json!({"ids": [zero.0], "from": "contents", "to": 0})).unwrap(); + assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changed"); + let looks = redrawn_label_rows(&mut s, id); + assert_eq!(rows_of(&looks, "0"), (vec![(false, "#0000ff".into(), 1.0, 2.0)], 1.0), "every value axis number: {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 6990524df6..a4249020e5 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -649,6 +649,8 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool) }, |before, d, changed| { let series = super::appearance::capture_series_paint_writes(before, d, changed, &written.borrow()); + // A graph line keeps the paint written to it, also when it already showed it. + let lines = super::graph::capture_line_paint_writes(d, &written.borrow()); let labels = super::graph::capture_label_styles(d, &characters.borrow(), &|st| { if fill { st.fill = unplaced(&paint); @@ -659,7 +661,7 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool) st.stroke = unplaced(&paint); } }); - Ok(series || labels) + Ok(series || lines || labels) }, )?; // Rejected edits leave the next shape's appearance and active proxy untouched. diff --git a/docs/mcp.md b/docs/mcp.md index f499e39f82..aceded6680 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -936,7 +936,9 @@ opacity and blend mode only when it also applies the object's transparency; the and leaves the other kind of row and 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. +last one in the order of the targets (`ids` as given, otherwise paint order) sets what the kind keeps. An +`appearance.moveItem` that leaves a label's rows and its Contents row where they were stores nothing and records no +undo step. `appearance.copyFrom` onto the whole text of a label also stores the character attributes it applies and, from type, the paragraph attributes. `paint.setFill` and `paint.setStroke` store a character fill or stroke when the paint goes to the label's characters (the whole label, or all of its text highlighted with the Type tool), and the row when it goes to @@ -954,7 +956,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, 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. An `appearance.copyFrom` that does not apply the object's +shows different ones until the graph is drawn again. `paint.setFill`, `paint.setStroke`, `addon.color.fillToStroke` +and `addon.color.strokeToFill` also store the paint they write on a line's topmost visible fill or stroke row when the +line already showed it. An `appearance.moveItem` that leaves a line's rows as they were stores nothing and records no +undo step. 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. `graphicStyle.apply` with `add` stores only the kinds of row that are visible in the style. `appearance.copyFrom` with `append` stores only the kinds of row it adds that are visible in the From 1bdc03d2ad6583c28c5795d854d07bddf6db4744 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 11:53:45 -0800 Subject: [PATCH 4/5] Graphs: a stroke painted after an axis line lost its stroke keeps a weight When one line of a kind had its stroke set to None, the kind kept a zero stroke weight. Painting the stroke of another line of that kind kept only the new paint, so the next redraw drew every line of the kind with no weight. The kind now takes the painted line's weight when it kept no stroke paint before the edit. A zero weight set together with a stroke color, or kept with a painted stroke, stays as set. --- crates/engine/src/cmd/graph/series.rs | 28 +++++++++++++-- crates/engine/src/cmd/graph/tests.rs | 50 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/graph/series.rs b/crates/engine/src/cmd/graph/series.rs index 1ee708e00e..fc187b365e 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -1359,7 +1359,11 @@ pub(crate) fn capture_line_changes(before: &Document, doc: &mut Document, 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 = line_slot(&mut spec.label_styles, line); let mut rows = slot.clone().unwrap_or_else(|| line.default_rows()); + let was_unpainted = stroke_unpainted(&rows); merge_row_edits(&mut rows, &old, &new); + if old.paint.stroke != new.paint.stroke { + keep_painted_stroke_weight(&mut rows, was_unpainted, &new.paint); + } let kept = (rows != line.default_rows()).then_some(rows); changed |= *slot != kept; *slot = kept; @@ -1388,10 +1392,12 @@ pub(crate) fn capture_line_paint_writes(doc: &mut Document, written: &[(NodeId, let slot = line_slot(&mut spec.label_styles, line); let mut rows = slot.clone().unwrap_or_else(|| line.default_rows()); if fill { - rows.paint.fill = shown.fill; + rows.paint.fill = shown.fill.clone(); } if stroke { - rows.paint.stroke = shown.stroke; + let was_unpainted = stroke_unpainted(&rows); + rows.paint.stroke = shown.stroke.clone(); + keep_painted_stroke_weight(&mut rows, was_unpainted, &shown); } let kept = (rows != line.default_rows()).then_some(rows); changed |= *slot != kept; @@ -1400,6 +1406,24 @@ pub(crate) fn capture_line_paint_writes(doc: &mut Document, written: &[(NodeId, changed } +/// Give kept line rows whose stroke an edit painted the painted line's stroke weight (`shown`) when the kind kept no +/// stroke paint before the edit (`was_unpainted`) and keeps the zero weight a stroke set to None left. A non-zero kept +/// weight stays, and so do a zero weight kept with a painted stroke and a zero weight the painted line shows. +fn keep_painted_stroke_weight(rows: &mut vectorcraft_doc::LabelRows, was_unpainted: bool, shown: &vectorcraft_doc::SeriesPaint) { + if was_unpainted + && !stroke_unpainted(rows) + && rows.paint.stroke_width.is_some_and(|w| w <= 0.0) + && let Some(w) = shown.stroke_width.filter(|w| *w > 0.0) + { + rows.paint.stroke_width = Some(w); + } +} + +/// Do kept line rows keep no stroke paint? +fn stroke_unpainted(rows: &vectorcraft_doc::LabelRows) -> bool { + rows.paint.stroke.as_ref().is_none_or(Paint::is_none) +} + /// 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() diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index b8d431dfd0..85917acafc 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -8077,6 +8077,56 @@ fn a_stroke_written_to_an_axis_line_that_shows_it_is_kept() { }); } +/// A stroke painted on an axis line after another axis line's stroke was set to None is kept for every axis line with +/// the painted line's weight, not the zero weight the unpainted stroke left on its kind. +#[test] +fn a_stroke_painted_after_an_axis_line_lost_its_stroke_keeps_a_weight() { + let cases = ["paint.setStroke", "addon.color.fillToStroke", "appearance.setItem"]; + every_case(cases, |cmd| { + 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 weight = line_look(&lines[1]).1; + assert!(weight > 0.0, "{cmd}: the line has a stroke weight: {weight}"); + s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "none": true})).unwrap(); + let b = lines[1].id.0; + match *cmd { + "paint.setStroke" => s.execute(cmd, &json!({"ids": [b], "color": "#ff0000"})).unwrap(), + "addon.color.fillToStroke" => { + s.execute("paint.setFill", &json!({"ids": [b], "color": "#ff0000"})).unwrap(); + s.execute(cmd, &json!({"ids": [b]})).unwrap() + } + _ => s.execute(cmd, &json!({"ids": [b], "index": top_row(&s, lines[1].id, false), "color": "#ff0000"})).unwrap(), + }; + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.1 - weight).abs() < 1e-9), "{cmd}: {looks:?}"); + }); +} + +/// A zero stroke weight set together with a stroke color on an axis line is kept for every axis line as set, also when +/// a stroke is painted on another axis line before the graph is drawn again. +#[test] +fn a_zero_weight_set_with_a_stroke_color_on_an_axis_line_is_kept() { + every_case([false, true], |repaint| { + 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], "none": true})).unwrap(); + let at = top_row(&s, lines[1].id, false); + s.execute("appearance.setItem", &json!({"ids": [lines[1].id.0], "index": at, "color": "#ff0000", "weight": 0})).unwrap(); + let color = if *repaint { + s.execute("paint.setStroke", &json!({"ids": [lines[2].id.0], "color": "#0000ff"})).unwrap(); + "#0000ff" + } else { + "#ff0000" + }; + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == color && l.1 == 0.0), "repaint {repaint}: {looks:?}"); + }); +} + /// A reorder that leaves an axis line's rows as they were keeps what its kind keeps from another line and is no edit. #[test] fn a_reorder_that_changes_nothing_on_an_axis_line_keeps_the_stroke_its_kind_keeps() { From 8494b14ff781e957215bc4417b63986df30edbf2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 12:18:10 -0800 Subject: [PATCH 5/5] Graphs: a pasted graph's axis and ring line rows follow a renamed swatch When a paste added a conflicting swatch under a new name, the series, label and legend rows of a pasted graph were relinked to it, but the rows kept for its axis lines and radar rings still named the destination's swatch, so the next redraw painted the lines with it. --- crates/engine/src/cmd/clipboard/resources.rs | 2 +- crates/engine/src/tests/clipboard.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/clipboard/resources.rs b/crates/engine/src/cmd/clipboard/resources.rs index f457712415..ae0e9a3ba1 100644 --- a/crates/engine/src/cmd/clipboard/resources.rs +++ b/crates/engine/src/cmd/clipboard/resources.rs @@ -699,7 +699,7 @@ impl Relink { self.name(Res::ParaStyle, s); } } - for r in [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows].into_iter().flatten() { + for r in [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows, &mut l.axis_rows, &mut l.ring_rows].into_iter().flatten() { r.paint.fill.iter_mut().chain(r.paint.stroke.iter_mut()).for_each(|p| self.paint(p)); } } diff --git a/crates/engine/src/tests/clipboard.rs b/crates/engine/src/tests/clipboard.rs index 368bc6de10..2e3f24d42d 100644 --- a/crates/engine/src/tests/clipboard.rs +++ b/crates/engine/src/tests/clipboard.rs @@ -468,7 +468,7 @@ fn styles_symbols_and_images_of_the_same_name_are_renamed() { assert_eq!(key(&s, img2), src_key); } -/// A graph whose series fill, value labels and legend rows paint with global swatch "Brand" and +/// A graph whose series fill, value labels, legend rows and axis and ring line rows paint with global swatch "Brand" and /// whose value labels are set in character style "Emphasis" and paragraph style "Body", as a /// later redraw would give them to its marks and labels. fn styled_graph(s: &mut Session) -> NodeId { @@ -484,8 +484,9 @@ fn styled_graph(s: &mut Session) -> NodeId { let l = &mut g.label_styles; l.values = Some(vectorcraft_doc::CharStyle { fill: brand.clone(), style_name: Some("Emphasis".into()), ..Default::default() }); l.values_para = Some(vectorcraft_doc::ParaStyle { style_name: Some("Body".into()), ..Default::default() }); - let rows = vectorcraft_doc::SeriesPaint { stroke: Some(brand), ..Default::default() }; - l.legend_rows = Some(vectorcraft_doc::graph::LabelRows { paint: rows, ..Default::default() }); + let paint = vectorcraft_doc::SeriesPaint { stroke: Some(brand), ..Default::default() }; + let rows = vectorcraft_doc::graph::LabelRows { paint, ..Default::default() }; + (l.legend_rows, l.axis_rows, l.ring_rows) = (Some(rows.clone()), Some(rows.clone()), Some(rows)); id } @@ -515,7 +516,7 @@ fn a_pasted_graph_brings_and_follows_its_label_styles_and_paints() { let d = doc(&s); assert!(d.swatch("Brand").is_some(), "{v}"); assert!(d.char_styles.iter().any(|x| x.name == "Emphasis") && d.para_styles.iter().any(|x| x.name == "Body"), "{v}"); - let brand = vec!["Brand".to_string(); 3]; + let brand = vec!["Brand".to_string(); 5]; assert_eq!(graph_links(&s, ids_of(&v)[0]), (brand.clone(), Some("Emphasis".into()), Some("Body".into()))); // Into a document that gives each name something else: they come in renamed. @@ -524,15 +525,15 @@ fn a_pasted_graph_brings_and_follows_its_label_styles_and_paints() { s.execute("charStyle.new", &json!({"name": "Emphasis", "attrs": {"size": 8.0}})).unwrap(); s.execute("paraStyle.new", &json!({"name": "Body", "attrs": {"space_after": 2.0}})).unwrap(); let v = s.execute("edit.pasteInPlace", &json!({"swatchConflict": "add"})).unwrap(); - let brand2 = vec!["Brand 2".to_string(); 3]; + let brand2 = vec!["Brand 2".to_string(); 5]; assert_eq!(graph_links(&s, ids_of(&v)[0]), (brand2, Some("Emphasis 2".into()), Some("Body 2".into())), "{v}"); // Without formatting: the labels' text styles stay behind. new_doc(&mut s); let v = s.execute("edit.pasteWithoutFormatting", &json!({})).unwrap(); assert!(doc(&s).char_styles.is_empty() && doc(&s).para_styles.is_empty(), "{v}"); - // The value labels' red characters stay behind too; the series fill and the legend rows keep Brand. - assert_eq!(graph_links(&s, ids_of(&v)[0]), (vec!["Brand".to_string(); 2], None, None)); + // The value labels' red characters stay behind too; the series fill, the legend rows and the line rows keep Brand. + assert_eq!(graph_links(&s, ids_of(&v)[0]), (vec!["Brand".to_string(); 4], None, None)); } /// Each label of graph `id` (the text of its Axes and Legend groups) with its size and its first paragraph's format.