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.
This commit is contained in:
dotCooCoo
2026-11-15 06:57:45 -08:00
parent a83c7a8bb3
commit 94d2625c60
6 changed files with 110 additions and 41 deletions
+15 -14
View File
@@ -129,7 +129,7 @@ pub fn specs() -> Vec<CommandSpec> {
"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<Value> {
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))
})?;
+5 -5
View File
@@ -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)]
+5 -12
View File
@@ -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) {
+74
View File
@@ -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<Option<String>> = 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]
+4 -5
View File
@@ -39,7 +39,7 @@ pub fn specs() -> Vec<CommandSpec> {
"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<Value> {
}
// 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 {
+7 -5
View File
@@ -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