From 0b207f4e8540c56047f73991059cf2692c6006f7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 17:04:58 -0800 Subject: [PATCH 01/15] Graphs: axis lines, tick marks and radar rings keep the paint set on them A graph drew its axis lines and tick marks in 0.5 pt black and a radar graph's rings in 0.25 pt gray every time, with nothing stored for them. A stroke, fill, weight, recolor, Appearance row, graphic style, Eyedropper pick or opacity given to them was lost when the graph was drawn again. - The graph now stores the rows of its axis lines and tick marks (axisRows) and, separately, of a radar graph's rings (ringRows): the paint, weight, opacity and blend mode of the topmost visible fill and stroke row, their order, and the line's object opacity and blend mode. Every line of the kind is drawn with them. Dashes, caps, joins and arrowheads are not stored. - These commands store a line's rows: paint.setFill, paint.setStroke, the stroke, gradient and recolor commands, paint.swap, paint.default, Apply Fill to Stroke and Stroke to Fill, the appearance commands with the Eyedropper, graphic styles, transparency.set and object.setProps. paint.setFill, paint.setStroke and the recolor commands given a whole graph now also store what they give its lines. - When one command reaches several lines of a kind, the frontmost line in paint order sets what the kind keeps. A gradient is stored without its placement. - Lines that show their default stroke store nothing, and a global swatch edit or a document color conversion reaches the stored paint. Docs: docs/mcp.md, the params text of these commands, docs/target-app-parity.md. --- crates/doc/src/graph.rs | 10 +- crates/doc/src/swatches.rs | 24 ++- crates/engine/src/cmd/addons/color.rs | 12 +- crates/engine/src/cmd/appearance.rs | 33 +-- crates/engine/src/cmd/colorcmds.rs | 2 +- crates/engine/src/cmd/colormgmt.rs | 9 +- crates/engine/src/cmd/freeform.rs | 2 +- crates/engine/src/cmd/gradient.rs | 4 +- crates/engine/src/cmd/graph.rs | 2 +- crates/engine/src/cmd/graph/generate.rs | 2 +- crates/engine/src/cmd/graph/labels.rs | 61 +++++- crates/engine/src/cmd/graph/series.rs | 163 +++++++++++++-- crates/engine/src/cmd/graph/tests.rs | 254 +++++++++++++++++++++++ crates/engine/src/cmd/object/commands.rs | 2 +- crates/engine/src/cmd/paint.rs | 10 +- crates/engine/src/cmd/recolor.rs | 2 +- crates/engine/src/cmd/stroke.rs | 4 +- crates/engine/src/cmd/style.rs | 4 +- crates/engine/src/tests/swatches.rs | 14 +- docs/mcp.md | 20 +- docs/target-app-parity.md | 2 +- 21 files changed, 555 insertions(+), 81 deletions(-) diff --git a/crates/doc/src/graph.rs b/crates/doc/src/graph.rs index 43074a4e80..1ef8e99e75 100644 --- a/crates/doc/src/graph.rs +++ b/crates/doc/src/graph.rs @@ -140,7 +140,7 @@ impl crate::Document { /// the text in graphs): the value axis numbers, the category labels (category axis, radar spokes, pie names) and the /// legend labels (beside or across the top, or in pie wedges). `None` draws the default 9 pt black. The `*_para` /// fields are the paragraph attributes each kind keeps the same way (`None`: the defaults); the graph still sets each -/// label's alignment. +/// label's alignment. [`Self::axis_rows`] and [`Self::ring_rows`] are the rows the graph's lines keep the same way. #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct LabelStyles { @@ -176,6 +176,14 @@ pub struct LabelStyles { /// The object fill and stroke rows the legend labels keep, as [`Self::values_rows`]. #[serde(skip_serializing_if = "Option::is_none")] pub legend_rows: Option, + /// The object rows the axis lines and tick marks keep once set with the paint, stroke or Appearance controls + /// ([`LabelRows`]). They replace the default 0.5 pt black stroke; kept rows without paint draw none. `None`: the + /// default stroke. + #[serde(skip_serializing_if = "Option::is_none")] + pub axis_rows: Option, + /// The object rows the rings of a radar graph keep, as [`Self::axis_rows`]. `None`: the default 0.25 pt gray stroke. + #[serde(skip_serializing_if = "Option::is_none")] + pub ring_rows: Option, } impl LabelStyles { diff --git a/crates/doc/src/swatches.rs b/crates/doc/src/swatches.rs index 844aa8c810..34e21fa6fa 100644 --- a/crates/doc/src/swatches.rs +++ b/crates/doc/src/swatches.rs @@ -382,14 +382,14 @@ pub fn override_paints(n: &Node) -> impl Iterator { n.extras().symbol_overrides.iter().flat_map(|o| [o.fill.as_ref(), o.stroke.as_ref()]).flatten() } -/// The paints a graph keeps for its series and its labels ([`crate::graph::GraphSpec`]), which its -/// marks and labels take each time it is drawn again and which [`node_paints`] leaves out. +/// The paints a graph keeps for its series, its labels and its lines ([`crate::graph::GraphSpec`]), which +/// its marks, labels and lines take each time it is drawn again and which [`node_paints`] leaves out. pub fn graph_paints(n: &Node) -> impl Iterator { let g = n.extras().graph.as_deref(); let series = g.into_iter().flat_map(|g| &g.series_paints).flat_map(|s| [s.fill.as_ref(), s.stroke.as_ref()]).flatten(); let labels = g.into_iter().flat_map(|g| [&g.label_styles.values, &g.label_styles.categories, &g.label_styles.legend]).flatten(); let l = g.map(|g| &g.label_styles); - let rows = l.into_iter().flat_map(|l| [&l.values_rows, &l.categories_rows, &l.legend_rows]).flatten(); + let rows = l.into_iter().flat_map(|l| [&l.values_rows, &l.categories_rows, &l.legend_rows, &l.axis_rows, &l.ring_rows]).flatten(); series.chain(labels.flat_map(|st| [&st.fill, &st.stroke])).chain(rows.flat_map(|r| [r.paint.fill.as_ref(), r.paint.stroke.as_ref()]).flatten()) } @@ -398,7 +398,7 @@ fn graph_paints_mut(g: &mut crate::graph::GraphSpec) -> impl Iterator, _: &mut f32| s.as_deref() == Some("Brand") && std::mem::replace(c, blue) != blue; - assert_eq!(d.map_solid_paints(&mut to_blue), 5); + assert_eq!(d.map_solid_paints(&mut to_blue), 7); let g = d.node(a).unwrap().extras().graph.clone().unwrap(); assert_eq!(g.series_paints[0].fill, Some(linked(blue, "Brand"))); assert_eq!(g.series_paints[0].stroke, Some(linked(blue, "Brand"))); let legend = g.label_styles.legend.unwrap(); assert_eq!((legend.fill, legend.stroke), (linked(blue, "Brand"), Paint::None)); assert_eq!(g.label_styles.values_rows.unwrap().paint.fill, Some(linked(blue, "Brand"))); + assert_eq!(g.label_styles.axis_rows.unwrap().paint.stroke, Some(linked(blue, "Brand"))); + assert_eq!(g.label_styles.ring_rows.unwrap().paint.stroke, Some(linked(blue, "Brand"))); let mut cleared = |p: &Paint| (*p == linked(blue, "Brand")).then_some(Paint::None); - assert_eq!(d.map_paints(&mut cleared), 5, "the fill and the graph's four"); + assert_eq!(d.map_paints(&mut cleared), 7, "the fill and the graph's six"); assert!(graph_paints(d.node(a).unwrap()).all(Paint::is_none)); } diff --git a/crates/engine/src/cmd/addons/color.rs b/crates/engine/src/cmd/addons/color.rs index 8701d379f7..3f8cbf936f 100644 --- a/crates/engine/src/cmd/addons/color.rs +++ b/crates/engine/src/cmd/addons/color.rs @@ -43,7 +43,7 @@ pub fn specs() -> Vec { "Apply as Filter", ["Object", "Plug-ins", "Color Effects"], None, - "{effect: a colour adjustment's effect id (adjust.brightnessContrast, adjust.curves, adjust.hueSaturation, adjust.levels, adjust.shiftToColor, adjust.temperatureTint, addon.color.exposure, addon.color.desaturate, addon.color.duotone or addon.color.invert), params?: {…} (as effect.apply; missing keys take the dialog defaults), fill?: true, stroke?: true, includeImages?: true, includePatterns?: true, ids?: [id…] (default: the selection)} recolour the objects and everything inside them as the live effect would draw them, but in their colours, as edit.colors.invert does (fills, strokes, type, gradient meshes, embedded images and pattern tiles), as one undo step; their effects stay. Duotone links a colour to its one tone's swatch as the live effect does. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows for every label of its kind (docs/mcp.md) → {changed}", + "{effect: a colour adjustment's effect id (adjust.brightnessContrast, adjust.curves, adjust.hueSaturation, adjust.levels, adjust.shiftToColor, adjust.temperatureTint, addon.color.exposure, addon.color.desaturate, addon.color.duotone or addon.color.invert), params?: {…} (as effect.apply; missing keys take the dialog defaults), fill?: true, stroke?: true, includeImages?: true, includePatterns?: true, ids?: [id…] (default: the selection)} recolour the objects and everything inside them as the live effect would draw them, but in their colours, as edit.colors.invert does (fills, strokes, type, gradient meshes, embedded images and pattern tiles), as one undo step; their effects stay. Duotone links a colour to its one tone's swatch as the live effect does. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows 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 (docs/mcp.md) → {changed}", has_selection, filter ), @@ -52,7 +52,7 @@ pub fn specs() -> Vec { "Print Ink Fixes", ["Object", "Plug-ins", "Color Effects"], None, - "{scope?: \"selection\" (the selection, or `ids`; by default, the document while nothing is selected) | \"document\" (every layer), inkLimit?: total ink % 1..400 (0 or left out: off), excludePureBlack?: true (black-only and grey colours keep their ink), removeWhiteOverprint?: false (white fills and strokes stop overprinting), overprintBlack?: black % 1..100 (black-only and grey fills and strokes this dark or darker overprint, as edit.colors.overprintBlack; 0 or left out: off), textOnly?: false (Overprint Black on type only), fill?: true, stroke?: true, ids?: [id…]} prepare a CMYK document's inks for print as one undo step: CMYK colours (solid, gradient stops, gradient meshes) with more total ink than inkLimit are scaled down to it (colours of spot swatches and Registration stay), white overprint is removed and black overprint set. Refused in RGB documents (File › Document Color Mode › CMYK Color first). On a path directly in a graph series, the graph also stores a paint the ink limit changes on the topmost visible fill or stroke, and on a graph label the new paint of its characters and rows for every label of its kind (docs/mcp.md) → {changed, inkLimited: paints and meshes scaled, whiteOverprintRemoved: objects, blackOverprinted: objects}", + "{scope?: \"selection\" (the selection, or `ids`; by default, the document while nothing is selected) | \"document\" (every layer), inkLimit?: total ink % 1..400 (0 or left out: off), excludePureBlack?: true (black-only and grey colours keep their ink), removeWhiteOverprint?: false (white fills and strokes stop overprinting), overprintBlack?: black % 1..100 (black-only and grey fills and strokes this dark or darker overprint, as edit.colors.overprintBlack; 0 or left out: off), textOnly?: false (Overprint Black on type only), fill?: true, stroke?: true, ids?: [id…]} prepare a CMYK document's inks for print as one undo step: CMYK colours (solid, gradient stops, gradient meshes) with more total ink than inkLimit are scaled down to it (colours of spot swatches and Registration stay), white overprint is removed and black overprint set. Refused in RGB documents (File › Document Color Mode › CMYK Color first). On a path directly in a graph series, the graph also stores a paint the ink limit changes on the topmost visible fill or stroke, and on a graph label the new paint of its characters and rows 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 (docs/mcp.md) → {changed, inkLimited: paints and meshes scaled, whiteOverprintRemoved: objects, blackOverprinted: objects}", has_doc, print_fixes::run ), @@ -70,7 +70,7 @@ pub fn specs() -> Vec { "Apply Nearest Swatch", ["Object", "Plug-ins", "Color Effects"], None, - "{library?: as addon.color.nearestSwatch (default: \"document\"), fill?: true, stroke?: true, ids?: [id…] (default: the selection)} give each solid colour and gradient stop of the selected objects' fills and strokes (their type's and those of the objects inside them; gradient meshes too) the colour of its nearest swatch in the library, as addon.color.nearestSwatch finds it, as one undo step: a global or spot swatch's colour links to it. A library's swatches the colours take are added to the document's first, as swatch.library.add adds them (a spot colour stays spot); images and patterns keep their colours. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows for every label of its kind (docs/mcp.md) → {changed: paints changed, swatches: [the document swatches the colours took], added: [swatches added to the document]}", + "{library?: as addon.color.nearestSwatch (default: \"document\"), fill?: true, stroke?: true, ids?: [id…] (default: the selection)} give each solid colour and gradient stop of the selected objects' fills and strokes (their type's and those of the objects inside them; gradient meshes too) the colour of its nearest swatch in the library, as addon.color.nearestSwatch finds it, as one undo step: a global or spot swatch's colour links to it. A library's swatches the colours take are added to the document's first, as swatch.library.add adds them (a spot colour stays spot); images and patterns keep their colours. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows 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 (docs/mcp.md) → {changed: paints changed, swatches: [the document swatches the colours took], added: [swatches added to the document]}", has_selection, nearest::apply ), @@ -79,7 +79,7 @@ pub fn specs() -> Vec { "Apply Fill to Stroke", ["Object", "Plug-ins", "Color Effects"], None, - "{ids?|id?, skipNone?: bool} each target's top stroke takes its own top fill, as it is (a colour in its model, a global or spot colour linked at its tint, a gradient or pattern with its placement, None); a stroke given paint at width 0 gets 1 pt, as Swap Fill and Stroke does. Type: each run's stroke takes its own fill, and while the Type tool has characters selected (no ids), only those. A graph's labels keep the paint when the graph is drawn again. On a path directly in a graph series, the graph also stores the paint and weight of the topmost visible stroke when the command wrote that row (exceptions: docs/mcp.md). skipNone: leave alone a target whose fill is None. A target whose stroke already has that paint is left as it is, and when nothing changes no undo step is recorded. The default stroke takes the default fill the same way → {objects}", + "{ids?|id?, skipNone?: bool} each target's top stroke takes its own top fill, as it is (a colour in its model, a global or spot colour linked at its tint, a gradient or pattern with its placement, None); a stroke given paint at width 0 gets 1 pt, as Swap Fill and Stroke does. Type: each run's stroke takes its own fill, and while the Type tool has characters selected (no ids), only those. A graph's labels keep the paint when the graph is drawn again, and its axis lines, tick marks and radar rings keep their new rows for every line of their kind. On a path directly in a graph series, the graph also stores the paint and weight of the topmost visible stroke when the command wrote that row (exceptions: docs/mcp.md). skipNone: leave alone a target whose fill is None. A target whose stroke already has that paint is left as it is, and when nothing changes no undo step is recorded. The default stroke takes the default fill the same way → {objects}", has_doc, |s, p| copy_paint(s, p, true) ), @@ -259,7 +259,9 @@ fn copy_paint(s: &mut Session, p: &Value, to_stroke: bool) -> Result { // The graph keeps the paint its series marks and labels now have. let series = super::super::appearance::capture_series_paint_writes(&before, d, &ids, &written); let labels = super::super::graph::capture_label_styles(d, &ids, ©_run); - Ok(objects + usize::from(series || labels)) + let painted: Vec = written.iter().map(|(id, _)| *id).collect(); + let lines = super::super::graph::capture_line_rows(d, &painted); + Ok(objects + usize::from(series || labels || lines)) })?; } // The defaults for new art change the same way, as Swap Fill and Stroke changes them. diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 94b35e9f93..1b5279a799 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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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", 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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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", has_doc, |s, p| add_item(s, p, false) ), @@ -66,7 +66,7 @@ pub fn specs() -> Vec { "Clear Appearance", ["Window", "Appearance"], None, - "{ids?|id?, target?} leave each object one empty fill and stroke (None; a group none of its own) and reset its opacity and blend mode. 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 and the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label of its kind", + "{ids?|id?, target?} leave each object one empty fill and stroke (None; a group none of its own) and reset its opacity and blend mode. 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 and 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", has_doc, clear_appearance ), @@ -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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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", 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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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", 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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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", 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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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", 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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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 → {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 → {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 → {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, the graph stores that label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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 → {ids}", has_doc, show_all_hidden ), @@ -165,7 +165,7 @@ pub fn specs() -> Vec { "Move Appearance", [], None, - "{source: id, target: id, copy?: bool} give `target` (a layer, group or object) the appearance (fills, strokes, effects) and transparency (opacity, blend mode, isolation, knockout) of `source`, as dragging a target circle onto another in the Layers panel does; the source is left with a cleared appearance (as appearance.clear) unless `copy` (Alt-drag). Opacity masks stay; placed gradients keep their place relative to each object's bounds. On a path directly in a graph series (a series group's id stands for those paths; as `source`, when the group has no effect, opacity, blend mode, isolation, knockout or style link of its own, the topmost one is read and a move clears them all; as `target` each takes the appearance and the group is cleared, a `source` among them keeps its look, and a `source` that is the group's only path is an error), 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 that label's topmost visible fill and stroke rows and object opacity and blend mode for every label of its kind → {source, target}", + "{source: id, target: id, copy?: bool} give `target` (a layer, group or object) the appearance (fills, strokes, effects) and transparency (opacity, blend mode, isolation, knockout) of `source`, as dragging a target circle onto another in the Layers panel does; the source is left with a cleared appearance (as appearance.clear) unless `copy` (Alt-drag). Opacity masks stay; placed gradients keep their place relative to each object's bounds. On a path directly in a graph series (a series group's id stands for those paths; as `source`, when the group has no effect, opacity, blend mode, isolation, knockout or style link of its own, the topmost one is read and a move clears them all; as `target` each takes the appearance and the group is cleared, a `source` among them keeps its look, and a `source` that is the group's only path is an error), 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, 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 → {source, target}", has_doc, transfer ), @@ -510,7 +510,8 @@ fn require_targets(s: &Session, p: &Value, cmd: &str) -> Result> { /// edit aimed at `item` changes there (`None`: the topmost one; text then edits its characters). /// 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`]). Nothing targeted is not +/// ([`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 /// 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( @@ -566,7 +567,9 @@ pub(crate) fn edit_items_then( } let more = after(&before, d, &edited)?; let labels = super::graph::capture_label_rows(d, &rows); - Ok(count_changed(d, &before, &edited) + usize::from(more || labels)) + // 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); + Ok(count_changed(d, &before, &edited) + usize::from(more || labels || lines)) })?; Ok(()) } @@ -1639,7 +1642,9 @@ 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)?; - Ok(count_changed(d, &before, &targets) + usize::from(kept || painted || object || rows || text)) + // A graph line is a path: every pick writes its rows. + let lines = super::graph::capture_line_rows(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/colorcmds.rs b/crates/engine/src/cmd/colorcmds.rs index 7ad53d5bf5..6eb6dda499 100644 --- a/crates/engine/src/cmd/colorcmds.rs +++ b/crates/engine/src/cmd/colorcmds.rs @@ -36,7 +36,7 @@ pub fn specs() -> Vec { "Invert Colors", ["Edit", "Edit Colors"], None, - "{fill?: true, stroke?: true, includeImages?: true, includePatterns?: true, ids?} replace each colour by its RGB inverse (keeps the colour model) in fills, strokes, text, gradient meshes (with fills), colorized image fills (their pixels stay unchanged), other embedded images (a recoloured copy) and pattern tiles (a new pattern swatch; the original stays), as one undo step. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows for every label of its kind (docs/mcp.md) → {changed, notChanged: {locked, hidden} (when the selection is everything select.all takes: the locked and hidden objects it left out whose colors would have changed; an object both hidden and locked counts as hidden), warning?: set when notChanged counts any object}", + "{fill?: true, stroke?: true, includeImages?: true, includePatterns?: true, ids?} replace each colour by its RGB inverse (keeps the colour model) in fills, strokes, text, gradient meshes (with fills), colorized image fills (their pixels stay unchanged), other embedded images (a recoloured copy) and pattern tiles (a new pattern swatch; the original stays), as one undo step. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows 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 (docs/mcp.md) → {changed, notChanged: {locked, hidden} (when the selection is everything select.all takes: the locked and hidden objects it left out whose colors would have changed; an object both hidden and locked counts as hidden), warning?: set when notChanged counts any object}", has_selection, |s, p| recolor(s, p, "edit.colors.invert", "Invert Colors", &invert) ), diff --git a/crates/engine/src/cmd/colormgmt.rs b/crates/engine/src/cmd/colormgmt.rs index 66295f50f2..7eaab7ab6a 100644 --- a/crates/engine/src/cmd/colormgmt.rs +++ b/crates/engine/src/cmd/colormgmt.rs @@ -653,8 +653,8 @@ fn map_effect_colors(a: &mut vectorcraft_doc::Appearance, f: &mut dyn FnMut(&Col } } -/// `f` applied to the series paints and the label styles that graph `g` keeps, which its marks and -/// labels take each time it is drawn again. +/// `f` applied to the series paints, the label styles and the line rows that graph `g` keeps, which +/// its marks, labels and lines take each time it is drawn again. fn map_graph_colors(g: &mut vectorcraft_doc::GraphSpec, f: &mut dyn FnMut(&Color, proof::Link) -> Color) { for p in g.series_paints.iter_mut() { for paint in [&mut p.fill, &mut p.stroke].into_iter().flatten() { @@ -666,7 +666,10 @@ fn map_graph_colors(g: &mut vectorcraft_doc::GraphSpec, f: &mut dyn FnMut(&Color map_paint_colors(&mut st.fill, f); map_paint_colors(&mut st.stroke, f); } - for r in [&mut styles.values_rows, &mut styles.categories_rows, &mut styles.legend_rows].into_iter().flatten() { + for r in [&mut styles.values_rows, &mut styles.categories_rows, &mut styles.legend_rows, &mut styles.axis_rows, &mut styles.ring_rows] + .into_iter() + .flatten() + { for paint in [&mut r.paint.fill, &mut r.paint.stroke].into_iter().flatten() { map_paint_colors(paint, f); } diff --git a/crates/engine/src/cmd/freeform.rs b/crates/engine/src/cmd/freeform.rs index 5f2a5e4070..dcc2e4d849 100644 --- a/crates/engine/src/cmd/freeform.rs +++ b/crates/engine/src/cmd/freeform.rs @@ -19,7 +19,7 @@ pub fn specs() -> Vec { "Add Freeform Point", [], None, - "{at: [x,y] (document coordinates), color? (default: the gradient's colour there; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %; the radius of pure colour around the point, a fraction of half the object's larger side; default 0), line?: true (join it to the selected point: extends the line ending there, else starts one), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), target?: \"object\"|\"contents\"} add a point to the freeform gradient (an unplaced one keeps its automatic points first) and select it. On a path directly in a graph series, the graph also stores the edited gradient when it is on the topmost visible fill or stroke, as for the other paint.freeform edits (docs/mcp.md); on a graph label's row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind; the points on a label's characters are not stored → {index}", + "{at: [x,y] (document coordinates), color? (default: the gradient's colour there; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill), opacity?: 0..1 (or 0..100), spread?: 0..1 (or 0..100 %; the radius of pure colour around the point, a fraction of half the object's larger side; default 0), line?: true (join it to the selected point: extends the line ending there, else starts one), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), target?: \"object\"|\"contents\"} add a point to the freeform gradient (an unplaced one keeps its automatic points first) and select it. On a path directly in a graph series, the graph also stores the edited gradient when it is on the topmost visible fill or stroke, as for the other paint.freeform edits (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its points); the points on a label's characters are not stored → {index}", has_doc, add_point ), diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index 8062d6110a..0a85d111a5 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -24,7 +24,7 @@ pub fn specs() -> Vec { "Gradient", ["Window", "Gradient"], None, - "{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), ids?|id?, strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters their gradient without its placement, fitted to each label", + "{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), ids?|id?, strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label", has_doc, edit_gradient ), @@ -33,7 +33,7 @@ pub fn specs() -> Vec { "Gradient Vector", [], None, - "{start?: [x,y], end?: [x,y] (document coordinates; both or neither: omitted, the vector stays), aspect?: % (radial, conic and diamond: the extent's height / width across the vector, a negative one mirroring a conic's sweep and an error for the other kinds; default: kept), focal?: [x,y] (document coordinates) | null (radial: the focal point, where the first stop sits, pulled inside the extent ellipse; null centres it; default: it keeps its place in the ellipse; an error on a conic or diamond gradient), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (alias: index; omitted: the Appearance panel's active item when it is of the edited kind), target?: \"object\"|\"contents\", index?: appearance item index (as item)} set the gradient vector, aspect ratio and focal point (solid paints become the default gradient; type objects set it on their runs, in text space). On a path directly in a graph series, the graph also stores the gradient with its placement when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, the graph stores the label's topmost visible fill and stroke rows for every label of its kind, and on its characters their gradient without the placement this command sets, fitted to each label", + "{start?: [x,y], end?: [x,y] (document coordinates; both or neither: omitted, the vector stays), aspect?: % (radial, conic and diamond: the extent's height / width across the vector, a negative one mirroring a conic's sweep and an error for the other kinds; default: kept), focal?: [x,y] (document coordinates) | null (radial: the focal point, where the first stop sits, pulled inside the extent ellipse; null centres it; default: it keeps its place in the ellipse; an error on a conic or diamond gradient), ids?|id?, stroke?: bool (default: the targeted item's kind, else the active proxy), item?: fill/stroke item index|null (alias: index; omitted: the Appearance panel's active item when it is of the edited kind), target?: \"object\"|\"contents\", index?: appearance item index (as item)} set the gradient vector, aspect ratio and focal point (solid paints become the default gradient; type objects set it on their runs, in text space). On a path directly in a graph series, the graph also stores the gradient with its placement when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without the placement this command sets, fitted to each label", has_doc, set_gradient_geom ), diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 0413a55dbb..8cbf933134 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -46,7 +46,7 @@ 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_series_object_opacity, capture_series_opacity, capture_series_top_paints, + capture_label_styles, capture_label_text, capture_line_rows, capture_series_object_opacity, capture_series_opacity, capture_series_top_paints, label_object_opacity_differs, labels_in, paint_targets, series_group_marks, series_group_marks_where, series_marks_in, series_object_opacity_differs, shown_paint, }; diff --git a/crates/engine/src/cmd/graph/generate.rs b/crates/engine/src/cmd/graph/generate.rs index 60217105d8..e12cd2a291 100644 --- a/crates/engine/src/cmd/graph/generate.rs +++ b/crates/engine/src/cmd/graph/generate.rs @@ -437,7 +437,7 @@ impl<'a> Plot<'a> { } for v in tick_values(lo, hi, step).into_iter().skip(1) { let ring: Vec = (0..ncat).map(|c| at(c, v)).collect(); - axes.push(self.b.path(polyline(&ring, true), Paint::None, Paint::solid(Color::rgb(0.6, 0.6, 0.6)), 0.25)); + axes.push(self.b.ring(polyline(&ring, true))); } let ax = self.b.group("Axes", axes); self.b.out.push(ax); diff --git a/crates/engine/src/cmd/graph/labels.rs b/crates/engine/src/cmd/graph/labels.rs index 290e099500..ac2aaf9dec 100644 --- a/crates/engine/src/cmd/graph/labels.rs +++ b/crates/engine/src/cmd/graph/labels.rs @@ -82,9 +82,49 @@ fn kept_rows(styles: &vectorcraft_doc::LabelStyles, role: Role) -> Option<&vecto } } -/// Give label `n` the object rows `kept` keeps: a fill row and a stroke row for the kept paints, in their kept order and -/// place relative to the characters, and the object opacity and blend mode. An opacity read from a file is held to 0..1 -/// and a weight to 0..1000 pt; one that is not a number is left out (a stroke then takes 1 pt). +/// What a graph line is, for the rows it keeps: an axis line or tick mark, or a ring of a radar graph. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(crate) enum Line { + Axis, + Ring, +} + +impl Line { + /// The stroke and weight the graph draws lines of this kind with when they keep no rows. They have no fill. + fn default_stroke(self) -> (Paint, f64) { + match self { + Line::Axis => (Paint::solid(Color::BLACK), 0.5), + Line::Ring => (Paint::solid(Color::rgb(0.6, 0.6, 0.6)), 0.25), + } + } + + /// The rows ([`super::series::label_rows`]) a line of this kind shows as the graph draws it with no kept rows. + pub(super) fn default_rows(self) -> vectorcraft_doc::LabelRows { + let (stroke, width) = self.default_stroke(); + let paint = vectorcraft_doc::SeriesPaint { fill: Some(Paint::None), stroke: Some(stroke), stroke_width: Some(width), ..Default::default() }; + vectorcraft_doc::LabelRows { paint, ..Default::default() } + } +} + +/// The rows lines of kind `line` keep, if any. +pub(super) fn kept_line_rows(styles: &vectorcraft_doc::LabelStyles, line: Line) -> Option<&vectorcraft_doc::LabelRows> { + match line { + Line::Axis => styles.axis_rows.as_ref(), + Line::Ring => styles.ring_rows.as_ref(), + } +} + +/// The slot of `styles` that holds the rows lines of kind `line` keep. +pub(super) fn line_slot(styles: &mut vectorcraft_doc::LabelStyles, line: Line) -> &mut Option { + match line { + Line::Axis => &mut styles.axis_rows, + Line::Ring => &mut styles.ring_rows, + } +} + +/// Give label or graph line `n` the object rows `kept` keeps: a fill row and a stroke row for the kept paints, in their +/// kept order and place relative to the contents, and the object opacity and blend mode. An opacity read from a file is +/// held to 0..1 and a weight to 0..1000 pt; one that is not a number is left out (a stroke then takes 1 pt). fn apply_label_rows(n: &mut Node, kept: &vectorcraft_doc::LabelRows) { use vectorcraft_doc::{AppearanceItem, FillLayer, StrokeLayer}; let rows = &kept.paint; @@ -124,7 +164,20 @@ impl Gen<'_> { let mut bp = BezPath::new(); bp.move_to(a); bp.line_to(b); - self.path(PathData::from_bezpath(&bp), Paint::None, Paint::solid(Color::BLACK), 0.5) + self.kept_line(Line::Axis, PathData::from_bezpath(&bp)) + } + /// A ring of a radar graph through `pd`. + pub(super) fn ring(&mut self, pd: PathData) -> Arc { + self.kept_line(Line::Ring, pd) + } + /// A graph line of kind `line` through `pd`, with the rows lines of its kind keep, else its default stroke. + fn kept_line(&mut self, line: Line, pd: PathData) -> Arc { + let (stroke, width) = line.default_stroke(); + let mut n = Node::path(self.d.alloc_id(), pd, Appearance::basic(Paint::None, stroke, width)); + if let Some(rows) = kept_line_rows(self.styles, line) { + apply_label_rows(&mut n, rows); + } + Arc::new(n) } pub(super) fn text(&mut self, role: Role, at: Point, s: &str, justify: Justify) -> Arc { let t = self.text_object(role, at, s, justify); diff --git a/crates/engine/src/cmd/graph/series.rs b/crates/engine/src/cmd/graph/series.rs index 806d95047f..8d5847f7d5 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -1,7 +1,7 @@ use vectorcraft_color::BlendMode; use super::axis::radar_axis; -use super::labels::{Role, filled_lines_on, label_para, label_style}; +use super::labels::{Line, Role, filled_lines_on, kept_line_rows, label_para, label_style, line_slot}; use super::{Arc, CharStyle, Color, Document, GraphKind, GraphSpec, HashMap, Node, NodeId, NodeKind, Paint, Result, Session, Value, bad}; // ---------- generation ---------- @@ -561,16 +561,117 @@ pub(crate) fn label_rows(n: &Node) -> Option { (rows != vectorcraft_doc::LabelRows::default()).then_some(rows) } +/// The graph and kind of graph line `id`: a path directly in a graph's Axes group. Looked up through its parents, with no +/// pass over the document. +fn graph_line(doc: &Document, id: NodeId) -> Option<(NodeId, Line)> { + let line = doc.node(id)?; + if !matches!(line.kind, NodeKind::Path { .. }) { + return None; + } + let path = doc.ancestry(id)?; + let [.., graph, axes, _] = path.as_slice() else { return None }; + let spec = doc.node(*graph)?.extras().graph.as_deref()?; + Some((*graph, line_in(spec, doc.node(*axes)?, line)?)) +} + +/// The kind of graph line `line` is when `axes` is the Axes group of a graph drawn from `spec` and `line` a path directly +/// in it. A radar graph's rings are its closed paths; its spokes, open, are axis lines. +fn line_in(spec: &GraphSpec, axes: &Node, line: &Node) -> Option { + if axes.name.as_deref() != Some("Axes") || axes.extras().series_index.is_some() || !matches!(axes.kind, NodeKind::Group { .. }) { + return None; + } + let NodeKind::Path { path, .. } = &line.kind else { return None }; + Some(if spec.kind == GraphKind::Radar && path.is_closed() { Line::Ring } else { Line::Axis }) +} + +/// The graph lines among `ids`, each with its graph and kind, from the back to the front and each once: a later line's +/// capture replaces an earlier one's, so the frontmost line of a kind sets what the kind keeps. +fn lines_of(doc: &Document, ids: &[NodeId]) -> Vec<(NodeId, NodeId, Line)> { + let mut out: Vec<(NodeId, NodeId, Line)> = ids.iter().filter_map(|id| graph_line(doc, *id).map(|(g, line)| (*id, g, line))).collect(); + out.sort_by_cached_key(|(id, ..)| doc.index_path(*id)); + out.dedup_by_key(|(id, ..)| *id); + 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 { + 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 + }; + (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 { + 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 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; + *slot = kept; + } + changed +} + +/// Keep the object rows of graph lines `ids` for every line of their kind, as [`capture_label_rows`] keeps a label's, +/// 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) +} + +/// 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) +} + +/// Would [`store_line_rows`] with `object_only` 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) { + let (Some(spec), Some(n)) = (doc.node(graph).and_then(|n| n.extras().graph.as_deref()), doc.node(id)) else { continue }; + let slot = match kept.iter().position(|(g, l, _)| *g == graph && *l == line) { + 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.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()) + }) +} + /// Keep the object rows ([`label_rows`]) of graph labels `ids` for every label of their kind, as /// [`capture_label_styles`] keeps a character format, even when a label already showed them: the last label of a kind /// in the order of `ids` sets what that kind keeps. Objects other than type are left out before the graph's labels are -/// looked up. Called inside the same edit, so they undo together. Returns whether kept rows changed. +/// 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) } -/// Keep the object opacity and blend mode of graph labels `ids` for every label 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. +/// 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) } @@ -578,20 +679,21 @@ pub(crate) fn capture_label_object_opacity(doc: &mut Document, ids: &[NodeId]) - /// 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 { - label_rows_of(doc, ids).into_iter().any(|(graph, role, rows)| { - let Some(spec) = doc.node(graph).and_then(|n| n.extras().graph.as_deref()) else { return false }; - let slot = match role { - Role::Value => &spec.label_styles.values_rows, - Role::Category => &spec.label_styles.categories_rows, - Role::Legend => &spec.label_styles.legend_rows, - }; - *slot != kept_label_rows(slot, rows, true) - }) + line_object_opacity_differs(doc, ids) + || label_rows_of(doc, ids).into_iter().any(|(graph, role, rows)| { + let Some(spec) = doc.node(graph).and_then(|n| n.extras().graph.as_deref()) else { return false }; + let slot = match role { + Role::Value => &spec.label_styles.values_rows, + Role::Category => &spec.label_styles.categories_rows, + Role::Legend => &spec.label_styles.legend_rows, + }; + *slot != kept_label_rows(slot, rows, true) + }) } /// [`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 = false; + let mut changed = store_line_rows(doc, ids, object_only); 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 { @@ -741,23 +843,38 @@ pub(super) fn picks_legend_fill(g: &GraphSpec) -> bool { && !g.label_styles.legend.as_ref().is_some_and(|st| st.fill != Paint::solid(Color::BLACK)) } -/// The graph labels among `roots` and inside them, for an edit that reaches graph labels without naming them. +/// The graph labels and graph lines among `roots` and inside them, for an edit that reaches them without naming them. pub(crate) fn labels_in(doc: &Document, roots: &[NodeId]) -> Vec { let mut texts = Vec::new(); + let mut lines = Vec::new(); for id in roots { + // A root that is a line, or the Axes group: found through its parents. + if graph_line(doc, *id).is_some() { + lines.push(*id); + } let Some(root) = doc.node(*id) else { continue }; + if let Some(parent) = doc.parent_of(*id).and_then(|p| doc.node(p)) + && let Some(spec) = parent.extras().graph.as_deref() + { + lines.extend(root.children().into_iter().flatten().filter(|c| line_in(spec, root, c).is_some()).map(|c| c.id)); + } root.walk(&mut |n| { if matches!(n.kind, NodeKind::Text(_)) { texts.push(n.id); } + if let Some(spec) = n.extras().graph.as_deref() { + for axes in n.children().into_iter().flatten() { + lines.extend(axes.children().into_iter().flatten().filter(|c| line_in(spec, axes, c).is_some()).map(|c| c.id)); + } + } }); } // Graph labels are type: without type among `roots`, the graph's labels are not looked up. - if texts.is_empty() { - return texts; + if !texts.is_empty() { + let labels = graph_labels(doc); + texts.retain(|id| labels.contains_key(id)); } - let labels = graph_labels(doc); - texts.retain(|id| labels.contains_key(id)); + texts.extend(lines.into_iter().filter(|id| doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Path { .. })))); // Nested roots (a graph and one of its labels) reach a label twice. texts.sort_unstable(); texts.dedup(); @@ -769,10 +886,12 @@ 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. Called inside the same edit, so they undo together. Returns whether what a graph keeps changed. +/// 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 { + 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 false; + return lines; } let labels = graph_labels(doc); let mut picked: Vec = ids.iter().copied().filter(|id| labels.contains_key(id)).collect(); @@ -800,7 +919,7 @@ pub(crate) fn capture_label_changes(before: &Document, doc: &mut Document, ids: let fill = kind.1 != Role::Legend || one_fill(kind.0); characters.extend(run_paint_change(was, now, fill).map(|change| (kind, change))); } - let mut changed = capture_label_rows(doc, &changed_rows); + let mut changed = capture_label_rows(doc, &changed_rows) | lines; for ((graph, role), (style, entries)) in &characters { changed |= store_label_style(doc, *graph, *role, &|st| { for i in entries { diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index ea47c82112..672408d899 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -5839,6 +5839,260 @@ 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")); } +/// 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(); + group(&n, "Axes").children().unwrap().iter().filter(|c| !matches!(c.kind, NodeKind::Text(_))).map(|c| (**c).clone()).collect() +} + +/// How line `n` looks: its stroke color (empty without one), stroke weight and object opacity. +fn line_look(n: &vectorcraft_doc::Node) -> (String, f64, f32) { + let stroke = n.appearance.stroke_paint().color().map(|c| c.to_hex()).unwrap_or_default(); + (stroke, n.appearance.stroke_width(), n.opacity) +} + +/// The looks of graph `id`'s lines after it is drawn again. +fn redrawn_line_looks(s: &mut Session, id: NodeId) -> Vec<(String, f64, f32)> { + s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap(); + line_nodes(s, id).iter().map(line_look).collect() +} + +/// A stroke, a weight, no stroke or an opacity given to one axis line is kept for every axis line and tick mark when the +/// graph is drawn again, and undo takes it back with its edit. +#[test] +fn paint_set_on_one_axis_line_is_kept_for_every_line() { + let cases = [ + ("paint.setStroke", json!({"color": "#ff0000"}), ("#ff0000", 0.5, 1.0)), + ("stroke.set", json!({"weight": 2}), ("#000000", 2.0, 1.0)), + ("paint.setStroke", json!({"none": true}), ("", 0.0, 1.0)), + ("appearance.clear", json!({}), ("", 0.0, 1.0)), + ("transparency.set", json!({"opacity": 40}), ("#000000", 0.5, 0.4)), + ]; + every_case(cases, |(cmd, params, (hex, width, opacity))| { + 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); + assert!(lines.len() > 2, "{lines:?}"); + let mut p = params.clone(); + p["ids"] = json!([lines[0].id.0]); + s.execute(cmd, &p).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + let want = (hex.to_string(), *width, *opacity); + assert!(looks.iter().all(|l| (&l.0, (l.1 - want.1).abs() < 1e-9, (l.2 - want.2).abs() < 1e-6) == (&want.0, true, true)), "{cmd}: {looks:?}"); + // Undo takes back the redraw, then the edit and what the graph keeps. + for _ in 0..2 { + s.execute("edit.undo", &json!({})).unwrap(); + } + assert_eq!(spec(&s, id).label_styles.axis_rows, None, "{cmd}"); + }); +} + +/// A recolor of the whole graph, or Swap Fill and Stroke on its axis lines, is kept for its axis lines, and the labels' +/// paint stays its own. +#[test] +fn recoloring_a_graph_keeps_its_axis_lines_paint() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + s.execute("edit.colors.invert", &json!({"ids": [id.0]})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#ffffff"), "inverted black lines are white"); + let ids: Vec = line_nodes(&s, id).iter().map(|n| n.id.0).collect(); + s.execute("paint.swap", &json!({"ids": ids})).unwrap(); + let kept = spec(&s, id).label_styles.axis_rows.unwrap(); + assert_eq!((kept.paint.fill.and_then(|p| p.color()).map(|c| c.to_hex()), kept.paint.stroke), (Some("#ffffff".into()), Some(Paint::None))); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0.is_empty()), "the lines have no stroke after the swap"); + // The value labels keep their inverted fill, not the lines' swapped paint. + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + let label_paint: Vec<(String, bool)> = group(&n, "Axes") + .children() + .unwrap() + .iter() + .filter_map(|c| match &c.kind { + NodeKind::Text(t) => Some((t.runs[0].style.fill.color().map(|c| c.to_hex()).unwrap_or_default(), t.runs[0].style.stroke.is_none())), + _ => None, + }) + .collect(); + assert!(!label_paint.is_empty() && label_paint.iter().all(|l| *l == ("#ffffff".to_string(), true)), "{label_paint:?}"); +} + +/// 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() { + for axes 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 target = if axes { group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").id } else { id }; + s.execute("paint.setStroke", &json!({"ids": [target.0], "color": "#ff0000"})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#ff0000"), "axes: {axes}"); + } +} + +/// A radar graph's rings keep what is set on one of them, apart from its spokes. +#[test] +fn a_radar_graphs_rings_keep_their_paint_apart_from_its_spokes() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "radar"); + let lines = line_nodes(&s, id); + // Three categories: three spokes, then the rings. + assert_eq!(line_look(&lines[3]), ("#999999".into(), 0.25, 1.0)); + s.execute("paint.setStroke", &json!({"ids": [lines[3].id.0], "color": "#00ff00"})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks[..3].iter().all(|l| l.0 == "#000000" && l.1 == 0.5), "{looks:?}"); + assert!(looks[3..].iter().all(|l| l.0 == "#00ff00" && l.1 == 0.25), "{looks:?}"); + s.execute("paint.setStroke", &json!({"ids": [line_nodes(&s, id)[0].id.0], "color": "#0000ff"})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks[..3].iter().all(|l| l.0 == "#0000ff") && looks[3..].iter().all(|l| l.0 == "#00ff00"), "{looks:?}"); +} + +/// When an edit gives axis lines different paint, the frontmost one sets what they keep, whatever order `ids` are in. +#[test] +fn the_frontmost_axis_line_sets_what_its_recolor_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 (back, front) = (lines[0].id, lines[lines.len() - 1].id); + s.execute("paint.setStroke", &json!({"ids": [front.0], "color": "#ff0000"})).unwrap(); + s.execute("edit.colors.invert", &json!({"ids": [front.0, 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("#00ffff"), "the inverted red of the frontmost line"); +} + +/// 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() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "radar"); + let spoke = line_nodes(&s, id)[0].id; + s.execute("object.arrange.bringToFront", &json!({"ids": [spoke.0]})).unwrap(); + assert_eq!(line_nodes(&s, id).last().map(|n| n.id), Some(spoke), "the spoke is in front of the rings"); + s.execute("paint.setStroke", &json!({"ids": [spoke.0], "color": "#0000ff"})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks[..3].iter().all(|l| l.0 == "#0000ff") && looks[3..].iter().all(|l| l.0 == "#999999"), "{looks:?}"); +} + +/// A graphic style linked to an axis line passes a redefinition on to every axis line. +#[test] +fn a_redefined_graphic_style_on_an_axis_line_is_kept() { + 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("graphicStyle.new", &json!({"id": rect.0, "name": "Axis"})).unwrap(); + let line = line_nodes(&s, id)[0].id; + s.execute("graphicStyle.apply", &json!({"name": "Axis", "ids": [line.0]})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [rect.0], "color": "#00ff00"})).unwrap(); + s.execute("graphicStyle.redefine", &json!({"name": "Axis", "id": rect.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("#00ff00")); +} + +/// An Eyedropper pick and Apply Stroke to Fill on an axis line are kept for every axis line. +#[test] +fn an_eyedropper_pick_and_stroke_to_fill_on_an_axis_line_are_kept() { + 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 line = line_nodes(&s, id)[0].id; + s.execute("appearance.copyFrom", &json!({"source": rect.0, "ids": [line.0]})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#ff0000" && l.1 == 1.0), "the picked 1 pt red stroke"); + let line = line_nodes(&s, id)[1].id; + s.execute("addon.color.strokeToFill", &json!({"ids": [line.0]})).unwrap(); + s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap(); + 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 == "#ff0000"), "{fills:?}"); +} + +/// Setting a line to the paint it is drawn with by default keeps nothing, and is no edit. +#[test] +fn axis_lines_given_their_default_paint_keep_nothing() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let line = line_nodes(&s, id)[0].id; + let undo = s.doc().unwrap().history.undo.len(); + s.execute("paint.setStroke", &json!({"ids": [line.0], "color": "#000000"})).unwrap(); + assert_eq!(spec(&s, id).label_styles.axis_rows, None); + assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changed"); +} + +/// `object.setProps` and `transparency.set` without an `item` keep only a line's object opacity: the stroke its kind +/// keeps from another line stays, though the line they are given still shows the default stroke. +#[test] +fn an_object_opacity_on_an_axis_line_keeps_the_stroke_its_kind_keeps() { + for (cmd, params) in [("object.setProps", json!({"opacity": 50})), ("transparency.set", json!({"opacity": 50}))] { + 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 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 == "#ff0000" && (l.2 - 0.5).abs() < 1e-6), "{cmd}: {looks:?}"); + } +} + +/// 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() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "radar"); + let ring = line_nodes(&s, id)[3].id; + s.execute("transparency.set", &json!({"ids": [ring.0], "opacity": 40})).unwrap(); + s.execute("stroke.set", &json!({"ids": [ring.0], "weight": 1})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks[..3].iter().all(|l| *l == ("#000000".into(), 0.5, 1.0)), "{looks:?}"); + assert!(looks[3..].iter().all(|l| l.0 == "#999999" && l.1 == 1.0 && (l.2 - 0.4).abs() < 1e-6), "{looks:?}"); +} + +/// A placed gradient on an axis line's stroke is kept for every axis line without its placement. +#[test] +fn a_gradient_on_an_axis_line_is_kept_without_its_placement() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let line = line_nodes(&s, id)[0].id; + s.execute("paint.editGradient", &json!({"ids": [line.0], "kind": "linear", "stroke": true})).unwrap(); + let placement = json!({"ids": [line.0], "stroke": true, "start": [100, 100], "end": [200, 100], "aspect": 50}); + s.execute("paint.setGradientGeom", &placement).unwrap(); + let shown = line_nodes(&s, id)[0].appearance.stroke_paint().clone(); + assert!(matches!(&shown, Paint::Gradient(g) if g.geom.is_some()), "the line's gradient is placed: {shown:?}"); + let kept = spec(&s, id).label_styles.axis_rows.unwrap().paint.stroke; + assert!(matches!(&kept, Some(Paint::Gradient(g)) if g.geom.is_none() && g.freeform.is_none()), "{kept:?}"); + s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap(); + assert!(line_nodes(&s, id).iter().all(|n| matches!(n.appearance.stroke_paint(), Paint::Gradient(_)))); +} + +/// Default Fill and Stroke and Apply Fill to Stroke on an axis line are kept for every axis line. +#[test] +fn default_fill_and_stroke_and_fill_to_stroke_on_an_axis_line_are_kept() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let line = line_nodes(&s, id)[0].id; + s.execute("paint.setStroke", &json!({"ids": [line.0], "color": "#ff0000"})).unwrap(); + s.execute("paint.default", &json!({"ids": [line.0]})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| *l == ("#000000".into(), 1.0, 1.0)), "the 1 pt black default stroke"); + 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 == "#ffffff"), "{fills:?}"); + let line = line_nodes(&s, id)[1].id; + s.execute("paint.setFill", &json!({"ids": [line.0], "color": "#0000ff"})).unwrap(); + s.execute("addon.color.fillToStroke", &json!({"ids": [line.0]})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#0000ff"), "the blue fill on the stroke"); +} + #[test] fn pie_names_and_wedge_labels_keep_their_style() { let mut s = Session::new(); diff --git a/crates/engine/src/cmd/object/commands.rs b/crates/engine/src/cmd/object/commands.rs index 6ffdb04a5c..52f18f3e3c 100644 --- a/crates/engine/src/cmd/object/commands.rs +++ b/crates/engine/src/cmd/object/commands.rs @@ -251,7 +251,7 @@ pub fn specs() -> Vec { "Object Properties", [], None, - "{ids?|id?, name?, visible?, locked? (visible: false or locked: true deselects every selected object hidden or locked after the call, the key object included), opacity?: 0..100, blend?: \"Multiply\"…, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, data?: {key: \"value\" | null (removes it)} (the object's own data, SVG data-* attributes: {pivot: \"100,180\"} is data-pivot; document.node → attrs.data)}. On a path directly in a graph series, the graph also stores the object's opacity and blend mode (exceptions: docs/mcp.md); on a graph label, the graph stores the label's opacity and blend mode for every label of its kind", + "{ids?|id?, name?, visible?, locked? (visible: false or locked: true deselects every selected object hidden or locked after the call, the key object included), opacity?: 0..100, blend?: \"Multiply\"…, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, data?: {key: \"value\" | null (removes it)} (the object's own data, SVG data-* attributes: {pivot: \"100,180\"} is data-pivot; document.node → attrs.data)}. On a path directly in a graph series, the graph also stores 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 opacity and blend mode for every label or line of its kind", has_doc, set_props ), diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 60c5180f40..850feb1c6a 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -21,7 +21,7 @@ pub fn specs() -> Vec { "Fill", [], None, - "{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), ids?|id?, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid colour recolours only the gradient mesh point last clicked with the Mesh tool or Direct Selection; while the Type tool has characters selected (and no ids or item are given), the paint goes to those characters only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did → {objects: how many objects took the paint (the objects inside a group, unless an appearance item of the group's own is targeted; 0 when only the default changed)}", + "{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), ids?|id?, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid colour recolours only the gradient mesh point last clicked with the Mesh tool or Direct Selection; while the Type tool has characters selected (and no ids or item are given), the paint goes to those characters only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind → {objects: how many objects took the paint (the objects inside a group, unless an appearance item of the group's own is targeted; 0 when only the default changed)}", has_doc, |s, p| set_paint(s, p, true) ), @@ -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 (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 its rows for every line of its kind (exceptions: docs/mcp.md)", has_doc, swap ), @@ -48,7 +48,7 @@ pub fn specs() -> Vec { "Default Fill and Stroke", [], Some("D"), - "{ids?|id?} white fill and 1 pt black stroke for the selection and the defaults; type gets black fill and no stroke. 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 on a graph label the black fill and no stroke of its characters for every label of its kind (exceptions: docs/mcp.md)", + "{ids?|id?} white fill and 1 pt black stroke for the selection and the defaults; type gets black fill and no stroke. 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 on a graph label the black fill and no stroke 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)", has_doc, default_paint ), @@ -81,7 +81,7 @@ pub fn specs() -> Vec { "Transparency", ["Window", "Transparency"], None, - "{ids?|id?, opacity?: 0..100, blend?: name, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, item?: appearance item index|null, 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)} for `ids`, the selection, or the object whose opacity mask is being edited; opacity and blend go to the targeted fill/stroke item (omitted: the Appearance panel's active item, else the objects; a gradient mesh point last clicked with the Mesh tool or Direct Selection takes the opacity itself). With an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, opacity and blend change that object for this instance only (isolate, knockout, knockoutShape, aligned and target are refused). On a path directly in a graph series (for a fill or stroke item, a series group's id stands for those paths), the graph also stores the opacity and blend mode of the object and of the topmost visible fill and stroke (exceptions: docs/mcp.md); on a graph label, the graph stores the label's object opacity and blend mode for every label of its kind, and with `item` its topmost visible fill and stroke rows too", + "{ids?|id?, opacity?: 0..100, blend?: name, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, item?: appearance item index|null, 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)} for `ids`, the selection, or the object whose opacity mask is being edited; opacity and blend go to the targeted fill/stroke item (omitted: the Appearance panel's active item, else the objects; a gradient mesh point last clicked with the Mesh tool or Direct Selection takes the opacity itself). With an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, opacity and blend change that object for this instance only (isolate, knockout, knockoutShape, aligned and target are refused). On a path directly in a graph series (for a fill or stroke item, a series group's id stands for those paths), the graph also stores the opacity and blend mode of the object and 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 opacity and blend mode for every label or line of its kind, and with `item` its topmost visible fill and stroke rows too", has_doc, transparency ), @@ -96,7 +96,7 @@ pub fn proxy_specs() -> Vec { "Invert", [], None, - "{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind (docs/mcp.md) → {changed}", + "{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows 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 (docs/mcp.md) → {changed}", has_doc, |s, p| proxy_recolor(s, p, "paint.invert", "Invert", &super::colorcmds::invert) ), diff --git a/crates/engine/src/cmd/recolor.rs b/crates/engine/src/cmd/recolor.rs index 5d7e1ab633..fa725e03c3 100644 --- a/crates/engine/src/cmd/recolor.rs +++ b/crates/engine/src/cmd/recolor.rs @@ -34,7 +34,7 @@ pub fn specs() -> Vec { "Recolor Artwork", ["Edit", "Edit Colors"], None, - "{map: rows [{from: [colour keys (recolor.colors) or \"#rrggbb\" (every colour shown as that hex)], to: colour (hex, key, {c,m,y,k} or {l,a,b}) | null (in from, to and groupColors, #rrggbbaa and #rgba are refused), exclude?: false (the row's colours are kept), tint?: 100 (percent; with limitTo, art linked to the global or spot swatch the new color is takes this share of its tint)}] | {\"key or #rrggbb\": colour, …} (one row per colour), method?: \"exact\" (default)|\"preserveTints\"|\"scaleTints\"|\"tintsShades\"|\"hueShift\" (how a row's colours take its new colour, relative to the row's darkest, average or most saturated colour), limitTo?: swatch library id or name; or \"document\" (the document's swatches): new colours snap to its nearest colour, group?: colour group to rewrite, groupColors?: [colour] (what `group` is rewritten with; default: the rows' new colours, in order, excluded rows left out), rename?: the group's new name, includeImages?: true, includePatterns?: true, globalAdjust?: {saturation?: 0, brightness?: 0, temperature?: 0, luminosity?: 0} (Global Adjust: percent from -100 to 100, 0 changes nothing; every colour a row that isn't excluded recolours, and the group's new colours, take the same change after the row's new colour: saturation scales HSB saturation by 1 + saturation/100, brightness moves HSB brightness that share of the way to full or to black, temperature adds 0.2 × temperature/100 to red and takes it from blue, luminosity moves Lab lightness that share of the way to 100 or 0 keeping a and b; with limitTo each row's new colour takes the change before it snaps to the library)} recolour the selection (gradients, text, meshes, image pixels and pattern tiles included; each new colour keeps the model of the one it replaces (model?: \"keep\" default | \"new\" (the new colour's own model, so a CMYK colour replacing RGB art gives CMYK art) | \"document\" (the document's colour mode)), except a library swatch's with limitTo: art takes the swatch itself, linked to a global or spot colour at its tints, and the swatch joins the document's swatches; art linked to a global swatch of `group` that is rewritten with its row's new color stays linked to it, at its tint, unless the row converts the color into the art's model; other recolored art, and art in a row linked to a global swatch of `group` that is rewritten with another color, keeps its row's new color and loses its swatch link) and the group, as one undo step. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows for every label of its kind (docs/mcp.md) → {changed, swatches: [names added to the document's swatches], relinked?: with group, the other paints linked to its global swatches that took their new colors, note?: set when a colour kept a model other than its new colour's (see model), notChanged: {locked, hidden} (as edit.colors.invert), warning?: set when notChanged counts any object}", + "{map: rows [{from: [colour keys (recolor.colors) or \"#rrggbb\" (every colour shown as that hex)], to: colour (hex, key, {c,m,y,k} or {l,a,b}) | null (in from, to and groupColors, #rrggbbaa and #rgba are refused), exclude?: false (the row's colours are kept), tint?: 100 (percent; with limitTo, art linked to the global or spot swatch the new color is takes this share of its tint)}] | {\"key or #rrggbb\": colour, …} (one row per colour), method?: \"exact\" (default)|\"preserveTints\"|\"scaleTints\"|\"tintsShades\"|\"hueShift\" (how a row's colours take its new colour, relative to the row's darkest, average or most saturated colour), limitTo?: swatch library id or name; or \"document\" (the document's swatches): new colours snap to its nearest colour, group?: colour group to rewrite, groupColors?: [colour] (what `group` is rewritten with; default: the rows' new colours, in order, excluded rows left out), rename?: the group's new name, includeImages?: true, includePatterns?: true, globalAdjust?: {saturation?: 0, brightness?: 0, temperature?: 0, luminosity?: 0} (Global Adjust: percent from -100 to 100, 0 changes nothing; every colour a row that isn't excluded recolours, and the group's new colours, take the same change after the row's new colour: saturation scales HSB saturation by 1 + saturation/100, brightness moves HSB brightness that share of the way to full or to black, temperature adds 0.2 × temperature/100 to red and takes it from blue, luminosity moves Lab lightness that share of the way to 100 or 0 keeping a and b; with limitTo each row's new colour takes the change before it snaps to the library)} recolour the selection (gradients, text, meshes, image pixels and pattern tiles included; each new colour keeps the model of the one it replaces (model?: \"keep\" default | \"new\" (the new colour's own model, so a CMYK colour replacing RGB art gives CMYK art) | \"document\" (the document's colour mode)), except a library swatch's with limitTo: art takes the swatch itself, linked to a global or spot colour at its tints, and the swatch joins the document's swatches; art linked to a global swatch of `group` that is rewritten with its row's new color stays linked to it, at its tint, unless the row converts the color into the art's model; other recolored art, and art in a row linked to a global swatch of `group` that is rewritten with another color, keeps its row's new color and loses its swatch link) and the group, as one undo step. On a path directly in a graph series, the graph also stores the new paint of the topmost visible fill and stroke, and on a graph label the new paint of its characters and rows 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 (docs/mcp.md) → {changed, swatches: [names added to the document's swatches], relinked?: with group, the other paints linked to its global swatches that took their new colors, note?: set when a colour kept a model other than its new colour's (see model), notChanged: {locked, hidden} (as edit.colors.invert), warning?: set when notChanged counts any object}", has_doc, apply ), diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index 14282c5112..f9dca54298 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 → {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 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 ), @@ -31,7 +31,7 @@ pub fn specs() -> Vec { "Stroke Weight Up", [], Some("Cmd+Alt+."), - "{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn. On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row for every label of its kind (docs/mcp.md) → {objects}", + "{ids?|id?} raise each selected stroke's weight by one step of Units › Stroke (a quarter unit below one unit, then whole units; up to 1000 pt), each from its own weight: the selected objects' active or top stroke, type's stroked characters; objects without a stroke are left alone. With nothing selected (and no ids), the weight of the next object drawn. On a path directly in a graph series, the graph also stores the new weight of the topmost visible stroke, and on a graph label the new weight of its characters' stroke or its stroke row 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 (docs/mcp.md) → {objects}", has_doc, |s, p| stroke_step(s, p, true) ), diff --git a/crates/engine/src/cmd/style.rs b/crates/engine/src/cmd/style.rs index 1c41006b3f..55b0fcccf7 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, the graph stores the label's topmost visible fill and stroke rows and object opacity and blend mode for every label 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 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 ), @@ -68,7 +68,7 @@ pub fn specs() -> Vec { "Redefine Graphic Style", ["Window", "Appearance"], None, - "{name?, id?} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object (a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own: the topmost path directly in it); the objects still linked to it update, and that object becomes linked. A linked graph series group passes the style to the paths directly in it, other than the source and paths linked to the style whose look was edited, and is left cleared (as appearance.clear) and unlinked. On a linked 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 the label's topmost visible fill and stroke rows and object opacity and blend mode for every label of its kind → {name}", + "{name?, id?} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object (a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own: the topmost path directly in it); the objects still linked to it update, and that object becomes linked. A linked graph series group passes the style to the paths directly in it, other than the source and paths linked to the style whose look was edited, and is left cleared (as appearance.clear) and unlinked. On a linked 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, 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 → {name}", has_doc, style_redefine ), diff --git a/crates/engine/src/tests/swatches.rs b/crates/engine/src/tests/swatches.rs index a80769dd98..01eb90e8b9 100644 --- a/crates/engine/src/tests/swatches.rs +++ b/crates/engine/src/tests/swatches.rs @@ -262,8 +262,8 @@ fn document_color_mode_converts_effect_colors() { assert_eq!((object(&s), style(&s)), before); } -/// Document Color Mode converts the series paints and label styles a graph keeps, so a graph drawn -/// again after the switch paints its series and labels in the new mode. +/// Document Color Mode converts the series paints, label styles and line rows a graph keeps, so a +/// graph drawn again after the switch paints its series, labels and lines in the new mode. #[test] fn document_color_mode_converts_the_paints_a_graph_keeps() { let mut s = session(); @@ -284,22 +284,26 @@ fn document_color_mode_converts_the_paints_a_graph_keeps() { } // A fill row on the label, which the graph keeps with the label's rows. run(&mut s, "appearance.addFill", json!({"ids": [label.0]})); + // A stroke on an axis line, which the graph keeps for its axis lines and tick marks. + let line = part(&s, "Axes").children().unwrap().iter().find(|c| matches!(c.kind, vectorcraft_doc::NodeKind::Path { .. })).unwrap().id; + run(&mut s, "paint.setStroke", json!({"color": "#ff0000", "ids": [line.0]})); let kept = |s: &Session| -> Vec { let g = doc(s).node(id).unwrap().extras().graph.as_deref().unwrap().clone(); let rows = [&g.label_styles.values_rows, &g.label_styles.categories_rows, &g.label_styles.legend_rows]; let rows: Vec = rows.into_iter().flatten().filter_map(|r| r.paint.fill.as_ref()?.color()).collect(); + let lines = g.label_styles.axis_rows.iter().filter_map(|r| r.paint.stroke.as_ref()?.color()); let labels = [g.label_styles.values, g.label_styles.categories, g.label_styles.legend]; let labels = labels.into_iter().flatten().map(|st| st.fill.color().unwrap()); - g.series_paints.iter().filter_map(|p| p.fill.as_ref()?.color()).chain(labels).chain(rows).collect() + g.series_paints.iter().filter_map(|p| p.fill.as_ref()?.color()).chain(labels).chain(rows).chain(lines).collect() }; let before = kept(&s); - assert_eq!(before, [Color::rgb(1.0, 0.0, 0.0); 3]); + assert_eq!(before, [Color::rgb(1.0, 0.0, 0.0); 4]); let undo = s.doc().unwrap().history.undo.len(); run(&mut s, "file.documentColorMode", json!({"mode": "cmyk"})); let cmyk = first_fill(doc(&s).node(red).unwrap()); assert!(matches!(cmyk, Color::Cmyk { .. }), "{cmyk:?}"); - assert_eq!(kept(&s), [cmyk; 3]); + assert_eq!(kept(&s), [cmyk; 4]); assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1); // Drawn again from new data, the series keeps the converted color. run(&mut s, "graph.setData", json!({"id": id.0, "rows": [[2, 3], [4, 5]]})); diff --git a/docs/mcp.md b/docs/mcp.md index 4f6eb742cc..0b23ed3947 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -821,8 +821,7 @@ placement they set there. A stroke weight and dashes are stored as the label sho 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. These commands do not store the colors they give a graph's axis lines, ticks and radar rings, which are -drawn again with their default paint. +a dark wedge. What they 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 @@ -846,6 +845,23 @@ the paragraph attributes. `paint.setFill` and `paint.setStroke` store a characte the label's characters (the whole label, or all of its text highlighted with the Type tool), and the row when it goes to a row. A stored character gradient also fits each label. +On a graph's axis lines and tick marks, and separately on a radar graph's rings, `paint.setFill`, `paint.setStroke`, +`addon.color.fillToStroke`, `addon.color.strokeToFill`, the stroke, gradient and recolor commands above, `paint.swap`, +`paint.default`, the `appearance.*` commands (`appearance.copyFrom`, the Eyedropper, included), `graphicStyle.apply`, +`graphicStyle.redefine`, `transparency.set` and `object.setProps` store what a line shows for every line of its kind: +the paint, weight, opacity and blend mode of its topmost visible fill and stroke row, their order, and the line's object +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 +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 +each kind, and effects are not stored, so a dash set on a line is drawn solid again. + `effect.apply {"effect": "path.outlineObject"}` (Effect › Path › Outline Object) takes no parameters. Type that carries it is drawn, exported and expanded as its glyph outlines and stays editable type, and the effects after it reshape those outlines. On paths, compound paths and images it does not change what is drawn. On an image's own fill or stroke diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 1e41bde132..1afedccf73 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1098,7 +1098,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Blend spine Anchor Point tool (#2544):** on a selected blend, dragging a spine corner makes symmetric Smooth handles; the tool displays and picks existing spine handles when switched to, drags one independently or retracts it on click, and clicking a point with handles retracts both. The spine is edited live without moving its key objects. Windows native canvas checks and screenshots reviewed: symmetric and independent handles, corner/retraction, Shift constraints and perpendicular reshaping, tool switching, key preservation, Undo/Redo, save/reopen, hidden handles and overlapping Path/Blend priority (PR #2643). Behaviour reference: [public path-editing documentation](https://helpx.adobe.com/illustrator/using/adjust-path-segments.html). - **Blend steps of brushed strokes:** the steps interpolate the pen pressure, tilt, bearing and rotation recorded with the Paintbrush, so a Calligraphic, Scatter or Art brush that varies with the pen changes gradually from one key to the next. A key without a recording counts as half pressure, half tilt and 0°, as brushes read it, and angles turn the shorter way round. When the blend starts a key's path at another anchor (an open path run from its end, a closed one turned to another start), the key's recordings, width profile and arrowheads turn with the path. Different brushes still switch halfway (VectorCraft's own rule; strokes blend their options, as [Blended objects overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/apply-transparency-and-blending/blended-objects-overview.html) describes; `crates/doc/src/blend.rs`, `pen_pressure_tilt_and_angles_interpolate_for_brushes`, `stroke_profiles_turn_with_a_key_path_started_elsewhere`). - **Path editing (#494):** the handles shown are the handles that drag: Direct Selection drags those of a path selected as a whole (as the Pen leaves it), the Anchor Point tool and Pen+Alt no longer grab handles that Show handles when multiple anchors are selected hides, a handle shorter than the tolerance leaves its anchor to be picked, and the anchor tools pick within Selection & Anchor Display › Tolerance. A dragged segment keeps a smooth anchor at either end smooth. With Direct Selection, the Pen, the Curvature and the anchor tools, a path selected as a whole shows all its anchors selected, and the Control bar and the Properties panel offer Convert (corner, smooth) for them too; Remove and Cut wait for anchors direct-selected (#504). A handle drag gathers its snap targets once per drag (it took 21 ms per pointer move on a 20,000-path document, now 1 ms; `vectorcraft-cli perf` measures handle and segment drags on a 5,000-anchor path). Join merges the selected anchor points that lie on one another, as after Average, into one anchor (#1582, fixes #1533), and removes the merged anchors in one pass over the path, so a long run of them no longer moves the anchors after it once per merge (`cmd::path::tests::a_long_run_before_many_other_anchors_merges_in_one_pass`); Object › Path › Average & Join… (`path.averageJoin`, Cmd+Alt+Shift+J, the "Create corner or smooth join" shortcut of [Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)) moves two open path ends to their midpoint and joins them there, a corner or smooth point as its dialog's Points choice asks, in one undo step. - - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke, the paint, weight, opacity and blend mode of a mark's top visible fill or stroke row after an Appearance command or a graphic style (each given a mark or its series picked with Group Selection), the Eyedropper, Default Fill and Stroke or Swap Fill and Stroke, the paint or stroke weight a stroke weight, gradient or recolor command changes there, and a mark's object opacity and blend mode, are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. A series that draws Filled Lines bands keeps no stroke paint or weight: its bands are drawn again with their 0.25 pt black outline. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Graph Data transposes rows and columns and switches a scatter graph's x and y, and a `|` in a category or series label starts a new line. Pie graphs take Legends in Wedges, Position (Even, Ratio sized by area, Stacked on one centre) and Sort (None, All, First). Graph Type takes column and cluster widths up to 1000% (overlapping past 100%) with First Row and First Column in Front (First Row orders each series' categories; across series the series order decides, so series stay one group each for Group Selection), draws filled lines, adds drop shadows behind columns, bars, lines and wedges, and puts the legend in rows across the top. Text formatted with the Character, Paragraph, Appearance, Transparency or Graphic Styles controls or the Eyedropper, or recolored, given Swap Fill and Stroke or Default Fill and Stroke, or given stroke options or a gradient, on the whole graph or on labels picked with Group Selection, is kept per kind of label (value axis numbers, category labels, legend labels) through the graph being drawn again, the paint, weight, opacity and blend mode of a label's topmost visible fill and stroke rows and its object opacity and blend mode included. Object › Graph › Data opens a worksheet: cells picked with a click and edited above the sheet (Tab moves right, Enter down, the arrows between cells), Import Data from a tab-separated text file, Transpose, Switch x/y, Cell Style (decimals shown, column width), Revert and Apply. `graph.setData` returns and takes the data as CSV with each value written exactly, not rounded to two decimals, so applying the returned CSV changes nothing (#1485). + - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke, the paint, weight, opacity and blend mode of a mark's top visible fill or stroke row after an Appearance command or a graphic style (each given a mark or its series picked with Group Selection), the Eyedropper, Default Fill and Stroke or Swap Fill and Stroke, the paint or stroke weight a stroke weight, gradient or recolor command changes there, and a mark's object opacity and blend mode, are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. A series that draws Filled Lines bands keeps no stroke paint or weight: its bands are drawn again with their 0.25 pt black outline. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Graph Data transposes rows and columns and switches a scatter graph's x and y, and a `|` in a category or series label starts a new line. Pie graphs take Legends in Wedges, Position (Even, Ratio sized by area, Stacked on one centre) and Sort (None, All, First). Graph Type takes column and cluster widths up to 1000% (overlapping past 100%) with First Row and First Column in Front (First Row orders each series' categories; across series the series order decides, so series stay one group each for Group Selection), draws filled lines, adds drop shadows behind columns, bars, lines and wedges, and puts the legend in rows across the top. Text formatted with the Character, Paragraph, Appearance, Transparency or Graphic Styles controls or the Eyedropper, or recolored, given Swap Fill and Stroke or Default Fill and Stroke, or given stroke options or a gradient, on the whole graph or on labels picked with Group Selection, is kept per kind of label (value axis numbers, category labels, legend labels) through the graph being drawn again, the paint, weight, opacity and blend mode of a label's topmost visible fill and stroke rows and its object opacity and blend mode included. As VectorCraft's own rule, the axis lines and tick marks, and separately a radar graph's rings, keep the paint, weight, opacity and blend mode of their topmost fill and stroke rows and their object opacity and blend mode through the graph being drawn again after a paint, stroke weight, gradient, recolor, Appearance, Transparency or Graphic Styles edit, the Eyedropper, Swap Fill and Stroke or Default Fill and Stroke, the frontmost line of a kind setting what the kind keeps; their dashes, caps, joins and arrowheads are not kept. Object › Graph › Data opens a worksheet: cells picked with a click and edited above the sheet (Tab moves right, Enter down, the arrows between cells), Import Data from a tab-separated text file, Transpose, Switch x/y, Cell Style (decimals shown, column width), Revert and Apply. `graph.setData` returns and takes the data as CSV with each value written exactly, not rounded to two decimals, so applying the returned CSV changes nothing (#1485). An Eyedropper pick that includes transparency and leaves a mark's top fill or stroke row without paint, or removes that row when the source has no row of that kind, where that row had paint before, also replaces the opacity and blend mode the graph keeps for that kind of row in the series; a row that had no paint before the pick leaves them as they are. What Global Edit gives a mark from another match (in an isolated graph) is kept on the graph the same way, and so is the object opacity, with its blend mode, that Randomize Opacity and Sort Objects change on marks. - **Graph column designs:** Object › Graph › Column (`graph.column`) draws the columns, bars or stacked segments and the legend swatch of the series picked with Group Selection with a graph design: Vertically Scaled stretches it to each column's length, Uniformly Scaled scales it both ways and centers it, Repeating stacks a copy for each Each Design Represents value and chops or scales the last one (For Fractions), and Sliding keeps the part above the design's guide line in proportion and stretches the part below. The dialog lists the designs with a preview; the choice is saved with the graph and follows the design's rename and delete. From 33be0b9e58fdb5923db5274312b725ccf89e415f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 18:43:30 -0800 Subject: [PATCH 02/15] Graphs: Appearance edits given the Axes or Legend group are kept The appearance.* commands, graphicStyle.apply, graphicStyle.redefine, graphicStyle.breakLink and transparency.set with an item, given a graph's Axes group or Legend group, edited the group's own appearance stack. The graph draws those groups again with no rows of their own, so the next redraw (for example after graph.setData) removed the edit. These commands now read such a group as they read a series group: the Axes group stands for the axis lines, tick marks, radar rings and labels directly in it, and the Legend group for the legend labels. The graph keeps what the command sets for every line and label of each kind. graphicStyle.new and the other commands that read a look read the topmost member of a group that holds nothing of its own. A group with a fill or stroke row of its own, or with no line or label in it, is still edited itself, except by graphicStyle.redefine, which passes the style to the members of a linked group. The lines and labels of a new graph have different rows, so a row index given the Axes group would name a different row in each. An index or item given such a group is now an error unless `aligned` is true, which makes it a row of the backmost member's stack. Docs: docs/mcp.md, params text, docs/target-app-parity.md Graphs line. --- crates/engine/src/cmd/appearance.rs | 56 +++++++++--- crates/engine/src/cmd/graph.rs | 2 +- crates/engine/src/cmd/graph/series.rs | 29 +++++- crates/engine/src/cmd/graph/tests.rs | 123 ++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 5 +- crates/engine/src/cmd/style.rs | 8 +- docs/mcp.md | 30 +++++-- docs/target-app-parity.md | 2 +- 8 files changed, 224 insertions(+), 31 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 1b5279a799..7a7c945555 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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", 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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", has_doc, |s, p| add_item(s, p, false) ), @@ -66,7 +66,7 @@ pub fn specs() -> Vec { "Clear Appearance", ["Window", "Appearance"], None, - "{ids?|id?, target?} leave each object one empty fill and stroke (None; a group none of its own) and reset its opacity and blend mode. 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 and 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", + "{ids?|id?, target?} leave each object one empty fill and stroke (None; a group none of its own) and reset its opacity and blend mode. 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 and 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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", has_doc, clear_appearance ), @@ -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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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", 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; when their rows differ, `index` needs `aligned` and is a row of the backmost one), 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", 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; when their rows differ, the indices need `aligned` and are rows of the backmost one), 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", 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; when their rows differ, the indices need `aligned` and are rows of the backmost one), 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", 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; moving rows of such a group whose members' rows differ is an error), 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}", has_doc, move_item ), @@ -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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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}", has_doc, show_all_hidden ), @@ -165,7 +165,7 @@ pub fn specs() -> Vec { "Move Appearance", [], None, - "{source: id, target: id, copy?: bool} give `target` (a layer, group or object) the appearance (fills, strokes, effects) and transparency (opacity, blend mode, isolation, knockout) of `source`, as dragging a target circle onto another in the Layers panel does; the source is left with a cleared appearance (as appearance.clear) unless `copy` (Alt-drag). Opacity masks stay; placed gradients keep their place relative to each object's bounds. On a path directly in a graph series (a series group's id stands for those paths; as `source`, when the group has no effect, opacity, blend mode, isolation, knockout or style link of its own, the topmost one is read and a move clears them all; as `target` each takes the appearance and the group is cleared, a `source` among them keeps its look, and a `source` that is the group's only path is an error), 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, 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 → {source, target}", + "{source: id, target: id, copy?: bool} give `target` (a layer, group or object) the appearance (fills, strokes, effects) and transparency (opacity, blend mode, isolation, knockout) of `source`, as dragging a target circle onto another in the Layers panel does; the source is left with a cleared appearance (as appearance.clear) unless `copy` (Alt-drag). Opacity masks stay; placed gradients keep their place relative to each object's bounds. On a path directly in a graph series (a series group's id stands for those paths; as `source`, when the group has no effect, opacity, blend mode, isolation, knockout or style link of its own, the topmost one is read and a move clears them all; as `target` each takes the appearance and the group is cleared, a `source` among them keeps its look, and a `source` that is the group's only path is an error), 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, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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 → {source, target}", has_doc, transfer ), @@ -420,7 +420,8 @@ pub(crate) fn appearance_targets(s: &Session, p: &Value) -> Result> } /// `ids` with each graph series group that has no fill or stroke row of its own replaced by the paths directly inside -/// it ([`super::graph::series_group_marks`]). A series group with rows, as a document saved earlier can hold, stays: +/// it, and each such Axes or Legend group of a graph by the lines and labels directly inside it +/// ([`super::graph::series_group_marks`]). A series group with rows, as a document saved earlier can hold, stays: /// the Appearance panel lists those rows and edits them by index. pub(crate) fn rowless_series_marks(d: &Document, ids: &[NodeId]) -> Vec { super::graph::series_group_marks_where(d, ids, |group| group.appearance.items.is_empty()) @@ -441,8 +442,9 @@ fn holds_no_look(group: &Node) -> bool { } /// The objects whose appearance a command reads for `id`: a graph series group that holds nothing of its own -/// ([`holds_no_look`]) gives the paths directly inside it, backmost first. A series group with an effect, an opacity or -/// another attribute of its own is read itself, with that attribute. +/// ([`holds_no_look`]) gives the paths directly inside it, backmost first, and such an Axes or Legend group of a graph +/// the lines and labels directly inside it. A series group with an effect, an opacity or another attribute of its own is +/// read itself, with that attribute. fn look_holders(d: &Document, id: NodeId) -> Vec { super::graph::series_group_marks_where(d, &[id], holds_no_look) } @@ -506,6 +508,28 @@ fn require_targets(s: &Session, p: &Value, cmd: &str) -> Result> { Ok(ids) } +/// Refuse a row index given a graph's Axes or Legend group that stands for lines and labels whose stacks differ +/// ([`rowless_series_marks`]), unless the index is `aligned`, a row of the backmost one's stack: the same index names a +/// different row in each of them. +pub(crate) fn check_part_rows(s: &Session, p: &Value, aligned: bool, cmd: &str) -> Result<()> { + if aligned { + return Ok(()); + } + let d = &s.doc()?.doc; + for id in appearance_targets(s, p)? { + let Some(n) = d.node(id).filter(|n| n.appearance.items.is_empty()) else { continue }; + if let Some(members) = super::graph::graph_part_members(d, n) + && appearances_differ(d, &members) + { + return Err(bad( + cmd, + format!("the lines and labels in graph group {} have different appearance rows: pass `aligned: true` or their ids", id.0), + )); + } + } + Ok(()) +} + /// One undo step (`label`) running `f` on each of `ids` with the item a fill (`fill`) or stroke /// edit aimed at `item` changes there (`None`: the topmost one; text then edits its characters). /// What the edit changes on the topmost visible fill and stroke of graph series marks, and on the @@ -890,7 +914,7 @@ fn transfer(s: &mut Session, p: &Value) -> Result { let mut targets: Vec = marks.iter().copied().filter(|id| !within.contains(id)).collect(); if targets.is_empty() { if stands { - return Err(bad(C, "`source` is the only path in series group `target`")); + return Err(bad(C, "`source` is the only path, line or label that graph group `target` stands for")); } targets.push(target); } @@ -1011,6 +1035,7 @@ fn set_item(s: &mut Session, p: &Value) -> Result { if ids.is_empty() { return Err(bad("appearance.setItem", "select objects or give ids")); } + check_part_rows(s, p, aligned(p, "appearance.setItem")?, "appearance.setItem")?; let blend = str_param(p, "blend").and_then(BlendMode::parse); // When every object comes out as it was (for example, when none has item `index`), the document // and its undo history stay as they are. @@ -1099,6 +1124,7 @@ pub(super) fn item_indices(p: &Value, cmd: &str) -> Result> { fn remove_item(s: &mut Session, p: &Value) -> Result { let idx = item_indices(p, "appearance.removeItem")?; let ids = require_targets(s, p, "appearance.removeItem")?; + check_part_rows(s, p, aligned(p, "appearance.removeItem")?, "appearance.removeItem")?; // When no object has an item at any of the indices, the document and its undo history stay as // they are. let before = s.doc()?.doc.clone(); @@ -1137,6 +1163,7 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result { return Err(bad(C, "`contents` goes with `to`")); } let ids = require_targets(s, p, C)?; + check_part_rows(s, p, aligned(p, C)?, C)?; // Where the first target's copy landed, and where it landed on the active row's object (the // first selected one, not always the first target): copies placed at `to` land at a different // index on stacks of other lengths. @@ -1262,6 +1289,7 @@ fn move_item(s: &mut Session, p: &Value) -> Result { return move_contents(s, &ids, to); } let ids = require_targets(s, p, C)?; + check_part_rows(s, p, aligned, C)?; // Where an aligned row would go in each of several different stacks isn't one place. if aligned && appearances_differ(&s.doc()?.doc, &ids) { return Err(bad(C, "rows of objects whose appearances differ can't be reordered together")); diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 8cbf933134..16f0684d85 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -47,7 +47,7 @@ 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, - label_object_opacity_differs, labels_in, paint_targets, series_group_marks, series_group_marks_where, series_marks_in, + graph_part_members, label_object_opacity_differs, labels_in, paint_targets, series_group_marks, series_group_marks_where, series_marks_in, series_object_opacity_differs, shown_paint, }; diff --git a/crates/engine/src/cmd/graph/series.rs b/crates/engine/src/cmd/graph/series.rs index 8d5847f7d5..abd0947d6f 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -149,13 +149,32 @@ pub(crate) fn paint_targets(doc: &Document, ids: &[NodeId]) -> Vec { } /// `ids` with each graph series group replaced by the paths directly inside it, as [`paint_targets`] reads a series -/// group: the graph draws its series groups again with no rows of their own. A series group with no such path, other -/// ids and the art of a graph design pass through, and the order of `ids` is kept. +/// group: the graph draws its series groups again with no rows of their own. A graph's Axes group is replaced by the +/// lines and labels directly inside it, and its Legend group by the labels directly inside it, which the graph keeps +/// rows for ([`capture_label_rows`]). A group with no such member, other ids and the art of a graph design pass +/// through, and the order of `ids` is kept. pub(crate) fn series_group_marks(doc: &Document, ids: &[NodeId]) -> Vec { series_group_marks_where(doc, ids, |_| true) } -/// [`series_group_marks`] for the series groups `stands` accepts; the others pass through. +/// The lines and labels directly in `n` when it is the Axes group of a graph, or the labels directly in it when it is +/// the graph's Legend group, in paint order. `None` for any other object. +pub(crate) fn graph_part_members(doc: &Document, n: &Node) -> Option> { + if !matches!(n.kind, NodeKind::Group { .. }) || n.extras().series_index.is_some() { + return None; + } + let axes = match n.name.as_deref() { + Some("Axes") => true, + Some("Legend") => false, + _ => return None, + }; + let spec = doc.parent_of(n.id).and_then(|parent| doc.node(parent)).and_then(|parent| parent.extras().graph.as_deref())?; + let member = |c: &Node| matches!(c.kind, NodeKind::Text(_)) || (axes && line_in(spec, n, c).is_some()); + Some(n.children().into_iter().flatten().filter(|c| member(c)).map(|c| c.id).collect()) +} + +/// [`series_group_marks`] for the series groups, Axes groups and Legend groups `stands` accepts; the others pass +/// through. pub(crate) fn series_group_marks_where(doc: &Document, ids: &[NodeId], stands: impl Fn(&Node) -> bool) -> Vec { // A series group is a child of a graph with one of the graph's series indexes ([`series_members`]). Each id is // looked up through its parent, with no pass over the document: the panels call this while they draw. @@ -173,6 +192,10 @@ pub(crate) fn series_group_marks_where(doc: &Document, ids: &[NodeId], stands: i group.children().into_iter().flatten().filter(|m| matches!(m.kind, NodeKind::Path { .. })).map(|m| m.id).collect(); if marks.is_empty() { out.push(*id) } else { out.extend(marks) } } + Some(part) if stands(part) => match graph_part_members(doc, part) { + Some(members) if !members.is_empty() => out.extend(members), + _ => out.push(*id), + }, _ => out.push(*id), } } diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 672408d899..b7816c412d 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6093,6 +6093,129 @@ 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"); } +/// The Appearance commands and `graphicStyle.apply` given a graph's Axes group or Legend group edit the lines and labels +/// directly in it, as given a series group they edit its paths: every line and label of each kind keeps what they set +/// when the graph is drawn again, and the groups keep no rows of their own. +#[test] +fn appearance_commands_given_the_axes_or_legend_group_edit_its_lines_and_labels() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let part = |s: &Session, name: &str| group(s.doc().unwrap().doc.node(id).unwrap(), name).clone(); + s.execute("appearance.clear", &json!({"ids": [part(&s, "Axes").id.0]})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0.is_empty()), "the cleared lines have no stroke"); + let (_, blue) = blue_style(&mut s, "Blue", false); + for name in ["Axes", "Legend"] { + s.execute("graphicStyle.apply", &json!({"name": "Blue", "ids": [part(&s, name).id.0]})).unwrap(); + } + let kept = spec(&s, id).label_styles; + let fill = |rows: Option| rows.and_then(|r| r.paint.fill); + assert_eq!(fill(kept.axis_rows), Some(blue.clone()), "axis lines"); + assert_eq!(fill(kept.values_rows), Some(blue.clone()), "value labels"); + assert_eq!(fill(kept.legend_rows), Some(blue.clone()), "legend labels"); + s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap(); + for name in ["Axes", "Legend"] { + let g = part(&s, name); + assert!(g.appearance.items.is_empty(), "{name} keeps no rows of its own"); + let members: Vec = g.children().unwrap().iter().map(|c| c.appearance.fill_paint()).collect(); + assert!(!members.is_empty() && members.iter().all(|p| *p == blue), "{name}: {members:?}"); + } +} + +/// A row index given the Axes group, whose lines and labels have different rows, is refused unless it is `aligned`, a row +/// of the backmost member's stack: then the members that share that row change, the labels keep theirs, and the graph +/// keeps the change when it is drawn again. +#[test] +fn a_row_index_given_the_axes_group_is_a_row_of_its_backmost_member_with_aligned() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let axes = group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").clone(); + let back = axes.children().unwrap()[0].id; + assert!(line_nodes(&s, id).iter().any(|l| l.id == back), "the backmost member is a line"); + let stroke = top_row(&s, back, false); + for (cmd, p) in [ + ("appearance.setItem", json!({"ids": [axes.id.0], "index": stroke, "color": "#ff0000"})), + ("appearance.removeItem", json!({"ids": [axes.id.0], "index": stroke})), + ("appearance.duplicateItem", json!({"ids": [axes.id.0], "index": stroke})), + ("appearance.moveItem", json!({"ids": [axes.id.0], "from": stroke, "to": 0})), + ("transparency.set", json!({"ids": [axes.id.0], "item": stroke, "opacity": 40})), + ] { + let err = s.execute(cmd, &p).unwrap_err().to_string(); + assert!(err.contains("aligned"), "{cmd}: {err}"); + } + let labels = |s: &Session| -> Vec { + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + group(&n, "Axes").children().unwrap().iter().filter(|c| matches!(c.kind, NodeKind::Text(_))).map(|c| (*c.appearance).clone()).collect() + }; + let was = labels(&s); + s.execute("appearance.setItem", &json!({"ids": [axes.id.0], "index": stroke, "color": "#ff0000", "aligned": true})).unwrap(); + s.execute("transparency.set", &json!({"ids": [axes.id.0], "item": stroke, "opacity": 40, "aligned": true})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000"), "{looks:?}"); + let rows = spec(&s, id).label_styles.axis_rows.unwrap(); + assert_eq!(rows.paint.stroke.and_then(|p| p.color()).map(|c| c.to_hex()).as_deref(), Some("#ff0000")); + let now = labels(&s); + assert!(!now.is_empty() && now.iter().all(|a| *a == was[0]), "the labels keep their rows"); + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + let l = &group(&n, "Axes").children().unwrap()[0]; + assert!((l.appearance.items[top_row(&s, l.id, false)].opacity() - 0.4).abs() < 1e-6, "the stroke row's opacity is kept"); +} + +/// Redefine Graphic Style on an Axes group linked to the style with rows of its own (as a file can hold it) restyles and +/// links the lines and labels in it, and clears and unlinks the group; Break Link given the group unlinks them. A style +/// applied through the group links its lines and labels, and the graph keeps their look, not the link, when it is drawn +/// again. +#[test] +fn graphic_style_links_given_the_axes_group() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let axes = group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").id; + let (rect, _) = blue_style(&mut s, "Blue", false); + let style = s.doc().unwrap().doc.graphic_style("Blue").unwrap().clone(); + s.edit("Link", |d, _| { + let g = d.node_mut(axes).unwrap(); + g.appearance = style.appearance.clone().into(); + g.extras_mut().graphic_style = Some(style.id); + Ok(()) + }) + .unwrap(); + s.execute("appearance.setItem", &json!({"ids": [rect.0], "index": top_row(&s, rect, true), "color": "#00ff00", "opacity": 100})).unwrap(); + let green = s.doc().unwrap().doc.node(rect).unwrap().appearance.fill_paint(); + s.execute("graphicStyle.redefine", &json!({"name": "Blue", "id": rect.0})).unwrap(); + let axes_now = |s: &Session| group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").clone(); + let members = |s: &Session| -> Vec<(Paint, Option)> { + axes_now(s).children().unwrap().iter().map(|c| (c.appearance.fill_paint(), c.extras().graphic_style)).collect() + }; + let g = axes_now(&s); + assert!(g.appearance.items.is_empty() && g.extras().graphic_style.is_none(), "the group is cleared and unlinked"); + assert!(members(&s).iter().all(|m| *m == (green.clone(), Some(style.id))), "{:?}", members(&s)); + s.execute("graphicStyle.breakLink", &json!({"ids": [axes_now(&s).id.0]})).unwrap(); + assert!(members(&s).iter().all(|m| m.1.is_none()), "unlinked"); + s.execute("graphicStyle.apply", &json!({"name": "Blue", "ids": [axes_now(&s).id.0]})).unwrap(); + assert!(members(&s).iter().all(|m| m.1 == Some(style.id)), "linked"); + s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap(); + assert!(members(&s).iter().all(|m| *m == (green.clone(), None)), "{:?}", members(&s)); +} + +/// The Appearance commands given a radar graph's Axes group reach its spokes and rings, which keep the edit apart. +#[test] +fn a_style_given_a_radar_graphs_axes_group_is_kept_for_spokes_and_rings() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "radar"); + let axes = group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").id; + let (_, blue) = blue_style(&mut s, "Blue", false); + s.execute("graphicStyle.apply", &json!({"name": "Blue", "ids": [axes.0]})).unwrap(); + let kept = spec(&s, id).label_styles; + let fill = |rows: Option| rows.and_then(|r| r.paint.fill); + assert_eq!(fill(kept.axis_rows), Some(blue.clone()), "spokes"); + assert_eq!(fill(kept.ring_rows), Some(blue.clone()), "rings"); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0.is_empty()), "the style has no stroke: {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 850feb1c6a..d59b9f8bd9 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -81,7 +81,7 @@ pub fn specs() -> Vec { "Transparency", ["Window", "Transparency"], None, - "{ids?|id?, opacity?: 0..100, blend?: name, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, item?: appearance item index|null, 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)} for `ids`, the selection, or the object whose opacity mask is being edited; opacity and blend go to the targeted fill/stroke item (omitted: the Appearance panel's active item, else the objects; a gradient mesh point last clicked with the Mesh tool or Direct Selection takes the opacity itself). With an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, opacity and blend change that object for this instance only (isolate, knockout, knockoutShape, aligned and target are refused). On a path directly in a graph series (for a fill or stroke item, a series group's id stands for those paths), the graph also stores the opacity and blend mode of the object and 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 opacity and blend mode for every label or line of its kind, and with `item` its topmost visible fill and stroke rows too", + "{ids?|id?, opacity?: 0..100, blend?: name, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, item?: appearance item index|null, 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)} for `ids`, the selection, or the object whose opacity mask is being edited; opacity and blend go to the targeted fill/stroke item (omitted: the Appearance panel's active item, else the objects; a gradient mesh point last clicked with the Mesh tool or Direct Selection takes the opacity itself). With an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, opacity and blend change that object for this instance only (isolate, knockout, knockoutShape, aligned and target are refused). On a path directly in a graph series (for a fill or stroke item, a series group's id stands for those paths), the graph also stores the opacity and blend mode of the object and 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 (for a fill or stroke item, a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; when their rows differ, `item` needs `aligned` and is a row of the backmost one), the graph stores that object's opacity and blend mode for every label or line of its kind, and with `item` its topmost visible fill and stroke rows too", has_doc, transparency ), @@ -1105,6 +1105,9 @@ fn transparency(s: &mut Session, p: &Value) -> Result { }; // Opacity and blend belong to the targeted fill/stroke; isolate/knockout/knockoutShape stay object-level. let item_ids = if editing_mask { ids } else { row_targets(s, p)? }; + if !editing_mask { + super::appearance::check_part_rows(s, p, aligned || !explicit, C)?; + } if explicit { let d = &s.doc()?.doc; if !item_ids.iter().any(|id| d.node(*id).is_some_and(|n| index < n.appearance.items.len())) { diff --git a/crates/engine/src/cmd/style.rs b/crates/engine/src/cmd/style.rs index 55b0fcccf7..2f0ccf77ca 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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}", has_doc, style_apply ), @@ -40,7 +40,7 @@ pub fn specs() -> Vec { "New Graphic Style", ["Window", "Graphic Styles"], None, - "{name?, id?} a style from object `id` or the first selected object: its appearance, opacity, blend mode, isolate and knockout (a group without fills or strokes of its own lends its topmost object's, type its characters'; a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own stands for the topmost path directly in it; placed gradients are kept relative to its bounds); links the object. Names are made unique → {name}", + "{name?, id?} a style from object `id` or the first selected object: its appearance, opacity, blend mode, isolate and knockout (a group without fills or strokes of its own lends its topmost object's, type its characters'; a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own stands for the topmost path directly in it, and a graph's Axes or Legend group with none of these for its topmost line or label; placed gradients are kept relative to its bounds); links the object. Names are made unique → {name}", has_doc, style_new ), @@ -68,7 +68,7 @@ pub fn specs() -> Vec { "Redefine Graphic Style", ["Window", "Appearance"], None, - "{name?, id?} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object (a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own: the topmost path directly in it); the objects still linked to it update, and that object becomes linked. A linked graph series group passes the style to the paths directly in it, other than the source and paths linked to the style whose look was edited, and is left cleared (as appearance.clear) and unlinked. On a linked 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, 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 → {name}", + "{name?, id?} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object (a graph series group with no fill, stroke, effect, opacity, blend mode, isolation, knockout or style link of its own: the topmost path directly in it; a graph's Axes or Legend group: its topmost line or label); the objects still linked to it update, and that object becomes linked. A linked graph series group passes the style to the paths directly in it, a linked Axes group to its lines and labels and a linked Legend group to its labels, other than the source and paths linked to the style whose look was edited, and is left cleared (as appearance.clear) and unlinked. On a linked 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, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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 → {name}", has_doc, style_redefine ), @@ -77,7 +77,7 @@ pub fn specs() -> Vec { "Break Link to Graphic Style", ["Window", "Graphic Styles"], None, - "{ids?|id?, target?: \"object\"|\"contents\"} unlink the objects (default: the selection) from their graphic style; they keep their look. A graph series group's id stands for the group and the paths directly in it", + "{ids?|id?, target?: \"object\"|\"contents\"} unlink the objects (default: the selection) from their graphic style; they keep their look. A graph series group's id stands for the group and the paths directly in it, a graph's Axes group for the group and its lines and labels, and its Legend group for the group and its labels", has_doc, style_break_link ), diff --git a/docs/mcp.md b/docs/mcp.md index 0b23ed3947..de782981be 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -790,10 +790,25 @@ look was edited keep their look. Read as a source, by `graphicStyle.new`, `graph style link of its own gives the look and the style link of the topmost path directly in it, and a move with `appearance.transfer` clears each of those paths; a series group that has one of them is read itself. -The other commands given a series group's id edit the group itself, and the graph does not store what they set on it: -`transparency.set` and `object.setProps` with an opacity or blend mode for the object, the `effect.*` commands and -`appearance.addEffect`, and the paint, stroke and gradient commands with a fill or stroke `item`, which is a row of the -group's own stack. The Appearance panel and `appearance.setActiveItem` read the selected group's own rows. +The commands in the paragraph above read a graph's Axes group and Legend group, given by id or selected with Group +Selection, as they read a series group: the Axes group stands for the axis lines, tick marks, radar rings and labels +directly in it, and the Legend group for the legend labels directly in it. The graph stores what they set for every +line and label of each kind, as described below for a line or label given itself, and the groups keep no rows of their +own. An Axes or Legend group that has a fill or stroke row of its own, or holds no line or label, is edited itself, +except by `graphicStyle.redefine`, which passes the style to the lines and labels of a linked group whatever the group +holds. An `index`, `indices` or fill or stroke `item` given an Axes or Legend group whose lines and labels have +different rows, as the lines and labels of a new graph do, is an error unless `aligned` is true, which makes it a row +of the stack of the backmost line or label in the group, and `appearance.moveItem` does not move the rows of such a +group. The graph keeps no graphic style link on its lines and +labels: they keep the look of a style applied to them, and are unlinked when the graph is drawn again. The commands +find these groups by their names, so a renamed Axes or Legend group is edited itself. + +The other commands given a series group's id, or a graph's Axes or Legend group, edit the group itself, and the graph +does not store what they set on it: `transparency.set` and `object.setProps` with an opacity or blend mode for the +object, the `effect.*` commands and `appearance.addEffect`, and the paint, stroke and gradient commands with a fill or +stroke `item`, which is a row of the group's own stack. `paint.setFill`, `paint.setStroke` and the recolor commands +given the Axes group store the line rows, as described below. The Appearance panel and `appearance.setActiveItem` read +the selected group's own rows. The graph also stores a paint or stroke weight that one of these commands changes on the topmost visible fill or stroke of a path directly in a series: a weight set with `stroke.set`, `stroke.weightUp` or `stroke.weightDown`; a gradient @@ -852,9 +867,10 @@ On a graph's axis lines and tick marks, and separately on a radar graph's rings, the paint, weight, opacity and blend mode of its topmost visible fill and stroke row, their order, and the line's object 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 +The other commands store them when given the line itself, and the `appearance.*` and graphic style commands and +`transparency.set` with an `item` also when given the Axes group, as described above. `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 paint order sets what the kind keeps, whatever order the `ids` are in. A gradient is stored without its placement, and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 1afedccf73..64b7ace1f9 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1098,7 +1098,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Blend spine Anchor Point tool (#2544):** on a selected blend, dragging a spine corner makes symmetric Smooth handles; the tool displays and picks existing spine handles when switched to, drags one independently or retracts it on click, and clicking a point with handles retracts both. The spine is edited live without moving its key objects. Windows native canvas checks and screenshots reviewed: symmetric and independent handles, corner/retraction, Shift constraints and perpendicular reshaping, tool switching, key preservation, Undo/Redo, save/reopen, hidden handles and overlapping Path/Blend priority (PR #2643). Behaviour reference: [public path-editing documentation](https://helpx.adobe.com/illustrator/using/adjust-path-segments.html). - **Blend steps of brushed strokes:** the steps interpolate the pen pressure, tilt, bearing and rotation recorded with the Paintbrush, so a Calligraphic, Scatter or Art brush that varies with the pen changes gradually from one key to the next. A key without a recording counts as half pressure, half tilt and 0°, as brushes read it, and angles turn the shorter way round. When the blend starts a key's path at another anchor (an open path run from its end, a closed one turned to another start), the key's recordings, width profile and arrowheads turn with the path. Different brushes still switch halfway (VectorCraft's own rule; strokes blend their options, as [Blended objects overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/apply-transparency-and-blending/blended-objects-overview.html) describes; `crates/doc/src/blend.rs`, `pen_pressure_tilt_and_angles_interpolate_for_brushes`, `stroke_profiles_turn_with_a_key_path_started_elsewhere`). - **Path editing (#494):** the handles shown are the handles that drag: Direct Selection drags those of a path selected as a whole (as the Pen leaves it), the Anchor Point tool and Pen+Alt no longer grab handles that Show handles when multiple anchors are selected hides, a handle shorter than the tolerance leaves its anchor to be picked, and the anchor tools pick within Selection & Anchor Display › Tolerance. A dragged segment keeps a smooth anchor at either end smooth. With Direct Selection, the Pen, the Curvature and the anchor tools, a path selected as a whole shows all its anchors selected, and the Control bar and the Properties panel offer Convert (corner, smooth) for them too; Remove and Cut wait for anchors direct-selected (#504). A handle drag gathers its snap targets once per drag (it took 21 ms per pointer move on a 20,000-path document, now 1 ms; `vectorcraft-cli perf` measures handle and segment drags on a 5,000-anchor path). Join merges the selected anchor points that lie on one another, as after Average, into one anchor (#1582, fixes #1533), and removes the merged anchors in one pass over the path, so a long run of them no longer moves the anchors after it once per merge (`cmd::path::tests::a_long_run_before_many_other_anchors_merges_in_one_pass`); Object › Path › Average & Join… (`path.averageJoin`, Cmd+Alt+Shift+J, the "Create corner or smooth join" shortcut of [Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)) moves two open path ends to their midpoint and joins them there, a corner or smooth point as its dialog's Points choice asks, in one undo step. - - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke, the paint, weight, opacity and blend mode of a mark's top visible fill or stroke row after an Appearance command or a graphic style (each given a mark or its series picked with Group Selection), the Eyedropper, Default Fill and Stroke or Swap Fill and Stroke, the paint or stroke weight a stroke weight, gradient or recolor command changes there, and a mark's object opacity and blend mode, are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. A series that draws Filled Lines bands keeps no stroke paint or weight: its bands are drawn again with their 0.25 pt black outline. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Graph Data transposes rows and columns and switches a scatter graph's x and y, and a `|` in a category or series label starts a new line. Pie graphs take Legends in Wedges, Position (Even, Ratio sized by area, Stacked on one centre) and Sort (None, All, First). Graph Type takes column and cluster widths up to 1000% (overlapping past 100%) with First Row and First Column in Front (First Row orders each series' categories; across series the series order decides, so series stay one group each for Group Selection), draws filled lines, adds drop shadows behind columns, bars, lines and wedges, and puts the legend in rows across the top. Text formatted with the Character, Paragraph, Appearance, Transparency or Graphic Styles controls or the Eyedropper, or recolored, given Swap Fill and Stroke or Default Fill and Stroke, or given stroke options or a gradient, on the whole graph or on labels picked with Group Selection, is kept per kind of label (value axis numbers, category labels, legend labels) through the graph being drawn again, the paint, weight, opacity and blend mode of a label's topmost visible fill and stroke rows and its object opacity and blend mode included. As VectorCraft's own rule, the axis lines and tick marks, and separately a radar graph's rings, keep the paint, weight, opacity and blend mode of their topmost fill and stroke rows and their object opacity and blend mode through the graph being drawn again after a paint, stroke weight, gradient, recolor, Appearance, Transparency or Graphic Styles edit, the Eyedropper, Swap Fill and Stroke or Default Fill and Stroke, the frontmost line of a kind setting what the kind keeps; their dashes, caps, joins and arrowheads are not kept. Object › Graph › Data opens a worksheet: cells picked with a click and edited above the sheet (Tab moves right, Enter down, the arrows between cells), Import Data from a tab-separated text file, Transpose, Switch x/y, Cell Style (decimals shown, column width), Revert and Apply. `graph.setData` returns and takes the data as CSV with each value written exactly, not rounded to two decimals, so applying the returned CSV changes nothing (#1485). + - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke, the paint, weight, opacity and blend mode of a mark's top visible fill or stroke row after an Appearance command or a graphic style (each given a mark or its series picked with Group Selection), the Eyedropper, Default Fill and Stroke or Swap Fill and Stroke, the paint or stroke weight a stroke weight, gradient or recolor command changes there, and a mark's object opacity and blend mode, are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. A series that draws Filled Lines bands keeps no stroke paint or weight: its bands are drawn again with their 0.25 pt black outline. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Graph Data transposes rows and columns and switches a scatter graph's x and y, and a `|` in a category or series label starts a new line. Pie graphs take Legends in Wedges, Position (Even, Ratio sized by area, Stacked on one centre) and Sort (None, All, First). Graph Type takes column and cluster widths up to 1000% (overlapping past 100%) with First Row and First Column in Front (First Row orders each series' categories; across series the series order decides, so series stay one group each for Group Selection), draws filled lines, adds drop shadows behind columns, bars, lines and wedges, and puts the legend in rows across the top. Text formatted with the Character, Paragraph, Appearance, Transparency or Graphic Styles controls or the Eyedropper, or recolored, given Swap Fill and Stroke or Default Fill and Stroke, or given stroke options or a gradient, on the whole graph or on labels picked with Group Selection, is kept per kind of label (value axis numbers, category labels, legend labels) through the graph being drawn again, the paint, weight, opacity and blend mode of a label's topmost visible fill and stroke rows and its object opacity and blend mode included. As VectorCraft's own rule, the axis lines and tick marks, and separately a radar graph's rings, keep the paint, weight, opacity and blend mode of their topmost fill and stroke rows and their object opacity and blend mode through the graph being drawn again after a paint, stroke weight, gradient, recolor, Appearance, Transparency or Graphic Styles edit, the Eyedropper, Swap Fill and Stroke or Default Fill and Stroke, the frontmost line of a kind setting what the kind keeps; the lines' dashes, caps, joins and arrowheads are not kept. An Appearance, Transparency (with a fill or stroke row) or Graphic Styles edit given the Axes group or the Legend group reaches the lines and labels in it and is kept the same way. Object › Graph › Data opens a worksheet: cells picked with a click and edited above the sheet (Tab moves right, Enter down, the arrows between cells), Import Data from a tab-separated text file, Transpose, Switch x/y, Cell Style (decimals shown, column width), Revert and Apply. `graph.setData` returns and takes the data as CSV with each value written exactly, not rounded to two decimals, so applying the returned CSV changes nothing (#1485). An Eyedropper pick that includes transparency and leaves a mark's top fill or stroke row without paint, or removes that row when the source has no row of that kind, where that row had paint before, also replaces the opacity and blend mode the graph keeps for that kind of row in the series; a row that had no paint before the pick leaves them as they are. What Global Edit gives a mark from another match (in an isolated graph) is kept on the graph the same way, and so is the object opacity, with its blend mode, that Randomize Opacity and Sort Objects change on marks. - **Graph column designs:** Object › Graph › Column (`graph.column`) draws the columns, bars or stacked segments and the legend swatch of the series picked with Group Selection with a graph design: Vertically Scaled stretches it to each column's length, Uniformly Scaled scales it both ways and centers it, Repeating stacks a copy for each Each Design Represents value and chops or scales the last one (For Fractions), and Sliding keeps the part above the design's guide line in proportion and stretches the part below. The dialog lists the designs with a preview; the choice is saved with the graph and follows the design's rename and delete. From f0a8c750a3a6c7950272520b85f7ce40bb12243d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 20:44:06 -0800 Subject: [PATCH 03/15] 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 2fe4b96e48a804db604ba4aabd0766e56478673e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 21:38:07 -0800 Subject: [PATCH 04/15] Graphs: aligned row edits, opacity-only picks and Default Fill and Stroke keep what each kind stores An aligned appearance.setItem, removeItem or duplicateItem given the Axes group stores the rows of only the lines and labels that have that row, so a category label without it no longer replaces the rows its kind keeps. An Eyedropper pick of only the object's transparency stores only the opacity and blend mode of an axis line or radar ring, as transparency.set does. Default Fill and Stroke stores the black fill and no stroke for a label's kind, and the default rows for a line's kind, also when the label or line already showed them; a kind that keeps no style and is left at the default style still keeps none. --- crates/engine/src/cmd/appearance.rs | 40 +++++++++++--- crates/engine/src/cmd/graph/series.rs | 8 ++- crates/engine/src/cmd/graph/tests.rs | 77 +++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 10 +++- docs/mcp.md | 12 +++-- 5 files changed, 133 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 78a258ac1c..1ce0228b9d 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 → {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 (not for a pick of only the object's transparency) and object opacity and blend mode for every line of its kind → {ids}", has_doc, copy_from ), @@ -1069,6 +1069,9 @@ fn set_item(s: &mut Session, p: &Value) -> Result { let per = items_per_target(&before, &ids, &[idx], aligned(p, "appearance.setItem")?); super::overprint::edit_counted(s, "Appearance", |d| { let mut edited = Vec::new(); + // The targets that have the row: an aligned row leaves out the members of a graph's Axes or Legend group that + // lack it, and the graph keeps the rows of the labels and lines it reached only. + let mut reached = Vec::new(); for (id, at) in ids.iter().zip(&per) { let Some(&idx) = at.first() else { continue }; let Some(n) = d.node_mut(*id) else { continue }; @@ -1079,6 +1082,7 @@ fn set_item(s: &mut Session, p: &Value) -> Result { } let bounds = n.geometric_bounds(); let Some(item) = n.appearance.items.get_mut(idx) else { continue }; + reached.push(*id); let (pp, op, bl, vis, bounds) = match item { AppearanceItem::Fill(f) => (&mut f.paint, &mut f.opacity, &mut f.blend, &mut f.visible, bounds), AppearanceItem::Stroke(st) => { @@ -1121,7 +1125,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 = super::graph::capture_label_rows(d, &reached); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; if let Some(pa) = &paint { @@ -1156,8 +1160,13 @@ fn remove_item(s: &mut Session, p: &Value) -> Result { let before = s.doc()?.doc.clone(); let per = items_per_target(&before, &ids, &idx, aligned(p, "appearance.removeItem")?); super::overprint::edit_counted(s, "Remove Item", |d| { + // The targets that had a row to remove, as in `set_item`. + let mut reached = Vec::new(); for (id, idx) in ids.iter().zip(&per) { if let Some(n) = d.node_mut(*id) { + if idx.iter().any(|i| *i < n.appearance.items.len()) { + reached.push(*id); + } let mut idx = idx.clone(); idx.sort_unstable(); // From the top down, so the lower indices stay valid. @@ -1169,7 +1178,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 = super::graph::capture_label_rows(d, &reached); 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`. @@ -1207,6 +1216,8 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result { // Copies that became the topmost visible row of their kind: the series stores their paint even when the object // showed it. let mut added = Vec::new(); + // The targets that took a copy, as in `set_item`. + let mut reached = Vec::new(); for (id, idx) in ids.iter().zip(&per) { let Some(n) = d.node_mut(*id) else { continue }; let has_contents = n.contents_label().is_some(); @@ -1231,6 +1242,7 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result { ap.set_contents_at(c); } any = true; + reached.push(*id); continue; } let mut idx = idx.clone(); @@ -1245,6 +1257,9 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result { added.push((*id, kind)); } any = true; + if reached.last() != Some(id) { + reached.push(*id); + } } } } @@ -1255,7 +1270,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); + super::graph::capture_label_rows(d, &reached); Ok(()) })?; // Rows at or above each copy move up by one (by the block, for copies placed at `to`). @@ -1697,8 +1712,21 @@ 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 pick of fill or stroke attributes writes its rows. A pick of only the object's + // opacity and blend mode leaves the fill and stroke its kind keeps, as `capture_label_object_opacity` keeps them. + let to_rows = append + || fill.color + || fill.transparency + || fill.overprint + || stroke.color + || stroke.transparency + || stroke.overprint + || stroke.weight + || stroke.cap + || stroke.join + || stroke.miter + || stroke.dash; + let lines = to_rows && super::graph::capture_line_rows(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/series.rs b/crates/engine/src/cmd/graph/series.rs index 7c3dcf90e6..e9b4b15185 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -529,16 +529,20 @@ pub(crate) fn capture_label_styles(doc: &mut Document, ids: &[NodeId], change: & } /// Apply `change` to the style graph `graph` keeps for its labels of kind `role` (or the default one). Returns whether -/// the kept style changed. +/// the kept style changed. A kind that keeps no style and that `change` leaves at the default style keeps none. fn store_label_style(doc: &mut Document, graph: NodeId, role: Role, change: &dyn Fn(&mut CharStyle)) -> bool { let Some(spec) = doc.node_mut(graph).and_then(|n| n.extras_if_any().and_then(|e| e.graph.as_deref_mut())) else { return false }; - let mut style = label_style(&spec.label_styles, role); + let was = label_style(&spec.label_styles, role); + let mut style = was.clone(); change(&mut style); let slot = match role { Role::Value => &mut spec.label_styles.values, Role::Category => &mut spec.label_styles.categories, Role::Legend => &mut spec.label_styles.legend, }; + if slot.is_none() && style == was { + return false; + } let changed = slot.as_ref() != Some(&style); *slot = Some(style); changed diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 967d4dc9f2..5e4d99f7ad 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6294,6 +6294,83 @@ fn a_row_index_given_the_axes_group_is_a_row_of_its_backmost_member_with_aligned assert!((l.appearance.items[top_row(&s, l.id, false)].opacity() - 0.4).abs() < 1e-6, "the stroke row's opacity is kept"); } +/// An aligned row edit given the Axes group leaves alone what a kind of label keeps from a label without that row: the +/// category labels keep the orange fill row of one of them through an edit of the lines' stroke rows. +#[test] +fn an_aligned_row_edit_given_the_axes_group_keeps_the_rows_of_labels_it_did_not_reach() { + let cases = [("appearance.setItem", json!({"color": "#0000ff"})), ("appearance.duplicateItem", json!({})), ("appearance.removeItem", 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 c = text_id(&s, id, "Axes", "Q2"); + s.execute("appearance.addFill", &json!({"ids": [c.0]})).unwrap(); + s.execute("appearance.setItem", &json!({"ids": [c.0], "index": 0, "color": "#ff8000"})).unwrap(); + let kept = spec(&s, id).label_styles.categories_rows; + assert!(kept.is_some(), "the category labels keep the orange row"); + let axes = group(s.doc().unwrap().doc.node(id).unwrap(), "Axes").clone(); + let back = axes.children().unwrap()[0].id; + let mut p = params.clone(); + p["ids"] = json!([axes.id.0]); + p["index"] = json!(top_row(&s, back, false)); + p["aligned"] = json!(true); + s.execute(cmd, &p).unwrap(); + assert_eq!(spec(&s, id).label_styles.categories_rows, kept, "{cmd}"); + }); +} + +/// An Eyedropper pick of only the object's opacity on an axis line keeps the stroke its kind keeps from another line, +/// though the line it is given still shows the default stroke. +#[test] +fn an_eyedropper_pick_of_only_the_opacity_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("object.setProps", &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(); + 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 opacity_only = json!({"appearance": {"transparency": true, "fill": fill, "stroke": stroke}}); + s.execute("appearance.copyFrom", &json!({"source": rect.0, "ids": [lines[1].id.0], "pickUp": opacity_only})).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:?}"); +} + +/// Default Fill and Stroke on a label or an axis line that already shows the default paint is kept for its kind, in +/// place of the paint the kind keeps from another label or line. +#[test] +fn default_fill_and_stroke_on_a_label_or_line_that_shows_it_is_kept_for_its_kind() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + s.execute("paint.setFill", &json!({"ids": [text_id(&s, id, "Axes", "4").0], "color": "#ff0000"})).unwrap(); + let hex = |st: &CharStyle| st.fill.color().map(|c| c.to_hex()); + assert_eq!(hex(&label_run_style(&s, id, "Axes", "0")).as_deref(), Some("#000000"), "the other labels show black until the graph is drawn again"); + s.execute("paint.default", &json!({"ids": [text_id(&s, id, "Axes", "0").0]})).unwrap(); + label_looks(&mut s, id); + let st = label_run_style(&s, id, "Axes", "4"); + assert_eq!((hex(&st).as_deref(), st.stroke.is_none()), (Some("#000000"), true)); + 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("paint.default", &json!({"ids": [lines[0].id.0]})).unwrap(); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| *l == ("#000000".into(), 1.0, 1.0)), "the 1 pt black default stroke"); +} + +/// Default Fill and Stroke on a label of a kind that keeps no style, which already shows the default paint, is no edit. +#[test] +fn default_fill_and_stroke_on_a_label_that_shows_it_is_no_edit() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let undo = s.doc().unwrap().history.undo.len(); + s.execute("paint.default", &json!({"ids": [text_id(&s, id, "Axes", "4").0]})).unwrap(); + assert_eq!(spec(&s, id).label_styles.values, None); + assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changed"); +} + /// Redefine Graphic Style on an Axes group linked to the style with rows of its own (as a file can hold it) restyles and /// links the lines and labels in it, and clears and unlinks the group; Break Link given the group unlinks them. A style /// applied through the group links its lines and labels, and the graph keeps their look, not the link, when it is drawn diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 174d259164..db0769d718 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -955,8 +955,14 @@ 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); - Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels)) + // The graph keeps the default paint for every label and line of a kind it reached, also when one already + // showed it. + let labels = super::graph::capture_label_styles(d, &ids, &|st| { + st.fill = Paint::solid(Color::BLACK); + st.stroke = Paint::None; + }); + let lines = super::graph::capture_line_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 bcbee312fd..dbfe3f4a2a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -809,7 +809,8 @@ except by `graphicStyle.redefine`, which passes the style to the lines and label holds. An `index`, `indices` or fill or stroke `item` given an Axes or Legend group whose lines and labels have different rows, as the lines and labels of a new graph do, is an error unless `aligned` is true, which makes it a row of the stack of the backmost line or label in the group, and `appearance.moveItem` does not move the rows of such a -group. The graph keeps no graphic style link on its lines and +group. With `aligned`, the graph stores the rows of only the lines and labels that have that row; a kind of label none +of whose labels has it keeps what it stored before. The graph keeps no graphic style link on its lines and labels: they keep the look of a style applied to them, and are unlinked when the graph is drawn again. The commands find these groups by their names, so a renamed Axes or Legend group is edited itself. @@ -856,7 +857,9 @@ placement they set there. A stroke weight and dashes are stored as the label sho 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. +a dark wedge. `paint.default` stores the black fill and no stroke for the kind of each label it reaches, also when the +label already showed them. What they 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 @@ -889,8 +892,9 @@ 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, and the `appearance.*` and graphic style commands and `transparency.set` with an `item` also when given the Axes group, as described above. `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 +`item` and `object.setProps` store only the object opacity and blend mode. `appearance.copyFrom` stores the rows when it +picks up a fill or stroke attribute or adds rows with `append`; a pick of only the object's transparency stores only the +object opacity and blend mode. The recolor commands and `paint.swap` 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 paint order sets what the kind keeps, whatever order the `ids` are in. A gradient is stored without its placement, and From 13c5df3aeb4898fe22f3c505adbcf76b115aad5d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 22:07:19 -0800 Subject: [PATCH 05/15] Graphs: an edit of a hidden row leaves what a label or line kind keeps An Appearance, paint, stroke or transparency edit of a hidden fill or stroke row of a graph label or axis line no longer stores that object's unchanged visible rows for its kind, so a paint the kind keeps from another label or line stays. --- crates/engine/src/cmd/appearance.rs | 28 +++++++++++++++++++++++--- crates/engine/src/cmd/graph.rs | 4 ++-- crates/engine/src/cmd/graph/tests.rs | 30 ++++++++++++++++++++++++++++ docs/mcp.md | 5 +++-- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 1ce0228b9d..35cd93ce94 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -551,6 +551,20 @@ pub(crate) fn check_part_rows(s: &Session, p: &Value, aligned: bool, cmd: &str) Ok(()) } +/// Whether row `index` of `n` is the topmost visible row of its kind, the row a graph keeps for a label or line. +fn is_top_shown(n: &Node, index: usize) -> bool { + let items = &n.appearance.items; + items.get(index).is_some_and(|it| items.iter().rposition(|o| o.is_fill() == it.is_fill() && o.visible()) == Some(index)) +} + +/// `ids` without the objects whose topmost visible fill and stroke rows ([`super::graph::label_rows`]) an edit left as +/// they were (`before`: the document before it), unless `wrote` says the edit wrote one of those rows. An edit of a +/// hidden row of a graph label or line then leaves what the graph keeps for its kind as it is. +fn shown_rows_edited(before: &Document, d: &Document, ids: Vec, wrote: impl Fn(NodeId) -> bool) -> Vec { + let shown = |doc: &Document, id: NodeId| doc.node(id).map(super::graph::label_rows); + ids.into_iter().filter(|id| wrote(*id) || shown(before, *id) != shown(d, *id)).collect() +} + /// One undo step (`label`) running `f` on each of `ids` with the item a fill (`fill`) or stroke /// edit aimed at `item` changes there (`None`: the topmost one; text then edits its characters). /// What the edit changes on the topmost visible fill and stroke of graph series marks, and on the @@ -600,6 +614,8 @@ pub(crate) fn edit_items_then( let mut edited = Vec::new(); // The objects whose rows `f` edited: on type, no row means its characters. let mut rows = Vec::new(); + // The objects where `f` wrote the topmost visible row of its kind. + let mut wrote = Vec::new(); for (id, item) in ids.iter().zip(&per) { let Some(item) = item else { continue }; let Some(n) = d.node_mut(*id) else { continue }; @@ -609,11 +625,14 @@ pub(crate) fn edit_items_then( if index.is_some() { rows.push(*id); } + if index.is_none_or(|i| is_top_shown(n, i)) { + wrote.push(*id); + } } let more = after(&before, d, &edited)?; - let labels = super::graph::capture_label_rows(d, &rows); + let labels = super::graph::capture_label_rows(d, &shown_rows_edited(&before, d, rows, |id| wrote.contains(&id))); // 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_rows(d, &shown_rows_edited(&before, d, edited.clone(), |id| wrote.contains(&id))); Ok(count_changed(d, &before, &edited) + usize::from(more || labels || lines)) })?; Ok(()) @@ -1125,6 +1144,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 reached = shown_rows_edited(&before, d, reached, |id| edited.iter().any(|(e, _)| *e == id)); let labels = super::graph::capture_label_rows(d, &reached); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; @@ -1178,7 +1198,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, &reached); + let labels = super::graph::capture_label_rows(d, &shown_rows_edited(&before, d, reached, |_| false)); 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`. @@ -1268,8 +1288,10 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result { } super::graph::capture_series_opacity(d, &top_opacity_changed(&before, d, &ids)); let mut rows = top_paint_changed(&before, d, &ids); + let top_copies: Vec = added.iter().map(|(id, _)| *id).collect(); rows.extend(painted_rows(d, added)); super::graph::capture_series_top_paints(d, &rows); + let reached = shown_rows_edited(&before, d, reached, |id| top_copies.contains(&id)); super::graph::capture_label_rows(d, &reached); Ok(()) })?; diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 1654940e87..85ed559ae5 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -47,8 +47,8 @@ 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, - graph_part_members, 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, + graph_part_members, is_design_art, label_object_opacity_differs, label_rows, 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/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 5e4d99f7ad..99c05fb2a7 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6319,6 +6319,36 @@ fn an_aligned_row_edit_given_the_axes_group_keeps_the_rows_of_labels_it_did_not_ }); } +/// An edit of a hidden row of an axis line leaves what its kind keeps from another line: the line's visible rows did not +/// change. +#[test] +fn an_edit_of_a_hidden_row_of_an_axis_line_keeps_what_its_kind_keeps() { + let cases = [ + ("appearance.setItem", json!({"color": "#0000ff"})), + ("appearance.duplicateItem", json!({})), + ("appearance.removeItem", json!({})), + ("transparency.set", json!({"opacity": 40})), + ("paint.setStroke", json!({"color": "#0000ff"})), + ]; + 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); + let line = lines[1].id; + s.execute("appearance.addStroke", &json!({"ids": [line.0]})).unwrap(); + let hidden = top_row(&s, line, false); + s.execute("appearance.setItem", &json!({"ids": [line.0], "index": hidden, "visible": false})).unwrap(); + s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "color": "#ff0000"})).unwrap(); + let kept = spec(&s, id).label_styles.axis_rows; + let mut p = params.clone(); + p["ids"] = json!([line.0]); + p[if cmd.starts_with("appearance.") { "index" } else { "item" }] = json!(hidden); + s.execute(cmd, &p).unwrap(); + assert_eq!(spec(&s, id).label_styles.axis_rows, kept, "{cmd}"); + }); +} + /// An Eyedropper pick of only the object's opacity on an axis line keeps the stroke its kind keeps from another line, /// though the line it is given still shows the default stroke. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index dbfe3f4a2a..56d8b484a6 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -871,7 +871,7 @@ The `appearance.*` commands, `graphicStyle.apply` and `graphicStyle.redefine`, a transparency commands given an `item` (or the Appearance panel's active row) store a graph label's object rows for its kind of label: the paint, weight, opacity and blend mode of its topmost visible fill and stroke row, their order and 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 +label already showed them, but an edit of a hidden row that leaves the topmost visible rows as they were stores nothing. `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 @@ -896,7 +896,8 @@ The other commands store them when given the line itself, and the `appearance.*` picks up a fill or stroke attribute or adds rows with `append`; a pick of only the object's transparency stores only the object opacity and blend mode. The recolor commands and `paint.swap` 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 +(0.5 pt black for axis lines and tick marks, 0.25 pt gray for rings) are not saved, and an edit of a hidden row that +leaves the topmost visible rows as they were stores nothing. 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 f1a79b92cc4500beaee7f384e7bf174d9e9d5f3a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 21:36:59 -0800 Subject: [PATCH 06/15] 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 db1dd678187f767d394919e8b3440d5a2b0198c4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 13 Nov 2026 22:33:58 -0800 Subject: [PATCH 07/15] Graphs: an Eyedropper pick of stroke options leaves the rows axis lines keep A pick of only overprint, caps, joins, miter limit or dashes on an axis line or radar ring no longer stores the line's paint and weight for its kind, since the graph keeps none of those options. --- crates/engine/src/cmd/appearance.rs | 21 +++++------------ crates/engine/src/cmd/graph/tests.rs | 34 ++++++++++++++++------------ docs/mcp.md | 4 ++-- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 35cd93ce94..5cb4ebb6b4 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 (not for a pick of only the object's transparency) 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 (when the pick takes a paint, a stroke weight or a row's opacity and blend mode, or appends) and object opacity and blend mode for every line of its kind → {ids}", has_doc, copy_from ), @@ -1734,20 +1734,11 @@ 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: a pick of fill or stroke attributes writes its rows. A pick of only the object's - // opacity and blend mode leaves the fill and stroke its kind keeps, as `capture_label_object_opacity` keeps them. - let to_rows = append - || fill.color - || fill.transparency - || fill.overprint - || stroke.color - || stroke.transparency - || stroke.overprint - || stroke.weight - || stroke.cap - || stroke.join - || stroke.miter - || stroke.dash; + // A graph line is a path: a pick of a paint, a weight or a row's opacity and blend mode writes the rows its kind + // keeps. A pick of only the object's opacity and blend mode, or of row attributes the graph does not keep (overprint, + // caps, joins, miter limit, dashes), leaves the fill and stroke its kind keeps, as `capture_label_object_opacity` + // keeps them. + let to_rows = append || fill.color || fill.transparency || stroke.color || stroke.transparency || stroke.weight; let lines = to_rows && super::graph::capture_line_rows(d, &targets); Ok(count_changed(d, &before, &targets) + usize::from(kept || painted || object || rows || text || lines)) })?; diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 99c05fb2a7..1ebc6b460e 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6349,23 +6349,29 @@ fn an_edit_of_a_hidden_row_of_an_axis_line_keeps_what_its_kind_keeps() { }); } -/// An Eyedropper pick of only the object's opacity on an axis line keeps the stroke its kind keeps from another line, -/// though the line it is given still shows the default stroke. +/// An Eyedropper pick of only the object's opacity, or of only stroke options the graph does not keep, on an axis line +/// keeps the stroke its kind keeps from another line, though the line it is given still shows the default stroke. #[test] fn an_eyedropper_pick_of_only_the_opacity_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("object.setProps", &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(); 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 opacity_only = json!({"appearance": {"transparency": true, "fill": fill, "stroke": stroke}}); - s.execute("appearance.copyFrom", &json!({"source": rect.0, "ids": [lines[1].id.0], "pickUp": opacity_only})).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:?}"); + let stroke = |dash: bool| json!({"color": false, "transparency": false, "overprint": false, "weight": false, "cap": false, "join": false, "miter": false, "dash": dash}); + let cases = [ + (json!({"appearance": {"transparency": true, "fill": fill, "stroke": stroke(false)}}), 0.5), + (json!({"appearance": {"transparency": false, "fill": fill, "stroke": stroke(true)}}), 1.0), + ]; + every_case(cases, |(pick, opacity)| { + 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("object.setProps", &json!({"ids": [rect.0], "opacity": 50})).unwrap(); + s.execute("stroke.set", &json!({"ids": [rect.0], "dash": [4, 2]})).unwrap(); + let lines = line_nodes(&s, id); + s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "color": "#ff0000"})).unwrap(); + s.execute("appearance.copyFrom", &json!({"source": rect.0, "ids": [lines[1].id.0], "pickUp": pick})).unwrap(); + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.2 - *opacity).abs() < 1e-6), "{pick}: {looks:?}"); + }); } /// Default Fill and Stroke on a label or an axis line that already shows the default paint is kept for its kind, in diff --git a/docs/mcp.md b/docs/mcp.md index 56d8b484a6..96ba3f8c3a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -893,8 +893,8 @@ graph, its Axes group or a group that holds the graph, so the lines keep the pai The other commands store them when given the line itself, and the `appearance.*` and graphic style commands and `transparency.set` with an `item` also when given the Axes group, as described above. `transparency.set` without an `item` and `object.setProps` store only the object opacity and blend mode. `appearance.copyFrom` stores the rows when it -picks up a fill or stroke attribute or adds rows with `append`; a pick of only the object's transparency stores only the -object opacity and blend mode. The recolor commands and `paint.swap` store a line's rows when they change them. The +picks up a paint, a stroke weight or a row's opacity and blend mode, or adds rows with `append`; any other pick stores +only the object opacity and blend mode, when it picks them up. The recolor commands and `paint.swap` 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, and an edit of a hidden row that leaves the topmost visible rows as they were stores nothing. When one command reaches several lines of one kind, the frontmost line in From a9b5bcc65658e5154dcbd442e697d99aa8c1ef79 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 11:45:33 -0800 Subject: [PATCH 08/15] 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 09/15] 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 10/15] 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 11/15] 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 From 9d1091331c404a7ce05394335ecaab40a210fd48 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 15:07:45 -0800 Subject: [PATCH 12/15] Graphs: a reorder that changes no row keeps the line rows its kind keeps A no-op appearance.moveItem on a graph axis line or label replaced the rows its kind keeps with the line's own. The reorder now keeps rows only for the lines and labels whose rows it changed. text.setStyle keeps the default label style for a kind only when the command gives a character attribute; justify-only and empty featureChanges requests record nothing. --- crates/engine/src/cmd/appearance.rs | 4 +- crates/engine/src/cmd/graph.rs | 6 +-- crates/engine/src/cmd/graph/series.rs | 41 +++++++++++++++------ crates/engine/src/cmd/graph/tests.rs | 18 +++++++++ crates/engine/src/cmd/typecmd.rs | 20 +++++++++- crates/engine/src/cmd/typecmd/noop_tests.rs | 28 ++++++++++++++ 6 files changed, 98 insertions(+), 19 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index e5bc8fa97f..796b1ae405 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -1379,7 +1379,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 = super::graph::capture_label_changes(&before, d, &ids, true); 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. @@ -1425,7 +1425,7 @@ fn move_items(s: &mut Session, p: &Value, ids: &[NodeId], to: usize) -> Result bool { let mut changed = false; for (graph, role) in label_kinds(doc, ids) { - changed |= store_label_style(doc, graph, role, change); + changed |= store_label_style(doc, graph, role, change, true); + } + changed +} + +/// [`capture_label_styles`], except that a kind that keeps no style keeps the default style when `change` leaves it +/// unchanged, for a command that gives character attributes (a size equal to the labels' own, for example). +pub(crate) fn capture_label_styles_given(doc: &mut Document, ids: &[NodeId], change: &dyn Fn(&mut CharStyle)) -> bool { + let mut changed = false; + for (graph, role) in label_kinds(doc, ids) { + changed |= store_label_style(doc, graph, role, change, false); } changed } /// Apply `change` to the style graph `graph` keeps for its labels of kind `role` (or the default one). A `change` that /// sets the fill of legend labels marks it as set on them, so a black one stays black on dark pie wedges. Returns whether -/// the kept style or that mark changed. A kind that keeps no style and that `change` leaves at the default style keeps -/// none, unless `change` sets the legend fill. -fn store_label_style(doc: &mut Document, graph: NodeId, role: Role, change: &dyn Fn(&mut CharStyle)) -> bool { +/// the kept style or that mark changed. With `unless_default`, a kind that keeps no style and that `change` leaves at +/// the default style keeps none, unless `change` sets the legend fill. +fn store_label_style(doc: &mut Document, graph: NodeId, role: Role, change: &dyn Fn(&mut CharStyle), unless_default: bool) -> bool { let Some(spec) = doc.node_mut(graph).and_then(|n| n.extras_if_any().and_then(|e| e.graph.as_deref_mut())) else { return false }; let was = label_style(&spec.label_styles, role); let mut style = was.clone(); @@ -677,7 +688,7 @@ fn store_label_style(doc: &mut Document, graph: NodeId, role: Role, change: &dyn Role::Category => &mut styles.categories, Role::Legend => &mut styles.legend, }; - if slot.is_none() && style == was && !(sets_fill && !styles.legend_fill_set) { + if unless_default && slot.is_none() && style == was && !(sets_fill && !styles.legend_fill_set) { return false; } let mut changed = slot.as_ref() != Some(&style); @@ -1099,13 +1110,19 @@ pub(crate) fn capture_label_changes(before: &Document, doc: &mut Document, ids: } let mut changed = capture_label_rows(doc, &changed_rows) | lines; for ((graph, role), (style, entries)) in &characters { - changed |= store_label_style(doc, *graph, *role, &|st| { - for i in entries { - if let Some(copy) = RUN_PAINT.get(*i) { - copy(style, st); + changed |= store_label_style( + doc, + *graph, + *role, + &|st| { + for i in entries { + if let Some(copy) = RUN_PAINT.get(*i) { + copy(style, st); + } } - } - }); + }, + true, + ); } changed } diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index c800fb8269..51f78f70fb 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6537,6 +6537,24 @@ fn an_object_opacity_on_an_axis_line_keeps_the_stroke_its_kind_keeps() { } } +/// 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:?}"); +} + /// 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/typecmd.rs b/crates/engine/src/cmd/typecmd.rs index 05b45cc051..d6c45bb2f0 100644 --- a/crates/engine/src/cmd/typecmd.rs +++ b/crates/engine/src/cmd/typecmd.rs @@ -1026,7 +1026,17 @@ fn set_style(s: &mut Session, p: &Value) -> Result { // not in a scaled label's own units). let mut labels_changed = false; if range.is_none() { - labels_changed = super::graph::capture_label_styles(d, &ids, &|st| { + let gives_character = font.is_some() + || style.is_some() + || size.is_some() + || leading.is_some() + || tracking.is_some() + || fill.is_some() + || stroke.is_some() + || !stroke_weight.is_empty() + || features.is_some() + || feature_changes.as_ref().is_some_and(|c| !c.is_empty()); + let change = |st: &mut vectorcraft_doc::CharStyle| { if let Some(f) = &font { st.font_family = f.clone(); st.font_version = None; @@ -1067,7 +1077,13 @@ fn set_style(s: &mut Session, p: &Value) -> Result { if let Some(c) = &feature_changes { st.features = super::textedit::change_features(&st.features, c); } - }); + }; + // A command that gives character attributes keeps the style even when they equal the labels' own. + labels_changed = if gives_character { + super::graph::capture_label_styles_given(d, &ids, &change) + } else { + super::graph::capture_label_styles(d, &ids, &change) + }; } Ok(((), labels_changed)) })?; diff --git a/crates/engine/src/cmd/typecmd/noop_tests.rs b/crates/engine/src/cmd/typecmd/noop_tests.rs index 02481d8bee..b4f5cb2099 100644 --- a/crates/engine/src/cmd/typecmd/noop_tests.rs +++ b/crates/engine/src/cmd/typecmd/noop_tests.rs @@ -102,6 +102,34 @@ fn a_kept_graph_label_style_change_alone_records_one_undo_step() { records_nothing(&mut s, "text.setStyle", p); } +/// `text.setStyle` on a graph label with only `justify`, which the label already has, records no undo step and keeps no +/// character style for its kind of label. +#[test] +fn a_justify_only_style_change_on_a_graph_label_records_nothing() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let csv = ",2024,2025\nQ1,3,2\nQ2,5,4"; + let graph = NodeId( + s.execute("graph.create", &json!({"type": "column", "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv})).unwrap()["id"] + .as_u64() + .unwrap(), + ); + let doc = s.doc().unwrap().doc.clone(); + let legend = doc.node(graph).unwrap().children().unwrap().iter().find(|c| c.name.as_deref() == Some("Legend")).unwrap(); + let label = legend + .children() + .unwrap() + .iter() + .find_map(|c| match &c.kind { + NodeKind::Text(t) if t.plain_text() == "2025" => Some(c.id), + _ => None, + }) + .unwrap(); + records_nothing(&mut s, "text.setStyle", json!({"ids": [label.0], "justify": "left"})); + let kept = s.doc().unwrap().doc.node(graph).unwrap().extras().graph.as_deref().unwrap().label_styles.legend.clone(); + assert!(kept.is_none(), "the legend keeps a style"); +} + /// `text.setText` with the text the type already has records no undo step; new text records one. #[test] fn the_same_text_records_no_undo_step() { From b78aa4cc338b170fe3a522ad05be7f1dfec29861 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 16:46:07 -0800 Subject: [PATCH 13/15] Graphs: a paint written to an axis line that already shows it is kept for its kind 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. --- crates/engine/src/cmd/addons/color.rs | 3 ++- crates/engine/src/cmd/graph.rs | 6 ++--- crates/engine/src/cmd/graph/series.rs | 33 +++++++++++++++++++++++++++ crates/engine/src/cmd/graph/tests.rs | 21 +++++++++++++++++ crates/engine/src/cmd/paint.rs | 4 +++- docs/mcp.md | 4 +++- 6 files changed, 65 insertions(+), 6 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/graph.rs b/crates/engine/src/cmd/graph.rs index 6530ad364a..3bdaa4e875 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -48,9 +48,9 @@ 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_styles_given, 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, - graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, labels_in, paint_targets, series_group_marks, - series_group_marks_where, series_groups_among, series_marks_in, series_object_opacity_differs, shown_paint, + capture_line_fill_stroke_rows, capture_line_paint_writes, capture_line_rows, capture_series_object_opacity, capture_series_opacity, + capture_series_top_paints, graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, 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 c1d97b9273..e979fd13d0 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -946,6 +946,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 9b0313f2ae..6626b46051 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -7350,6 +7350,27 @@ 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:?}"); + }); +} + #[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 79f54a9487..558c76fad9 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -640,6 +640,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); @@ -650,7 +652,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 2ab7138f25..591f40334e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -931,7 +931,9 @@ The other commands store them when given the line itself, and the `appearance.*` `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. An `appearance.copyFrom` that does not apply +when the line still 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.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 even when the line already showed them, and leaves the object opacity and blend mode the kind keeps. Rows From f20fc32c3db720174003d4ffd2204f004968081b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 18:23:06 -0800 Subject: [PATCH 14/15] Graphs: a fill or stroke added to a label or axis line keeps the other kind its kind keeps graphicStyle.apply with add, and appearance.copyFrom with append, stored both the fill and stroke rows a graph label or axis line showed, so a fill-only style added to one axis line replaced the stroke the axis lines kept from another line with the line's own black stroke. They now store only the kinds of row they add; the row of the other kind keeps its paint and its place relative to the characters as the kind keeps them. appearance.moveItem of the Contents row stored the rows of every label it was given, so a move that changed nothing on a label replaced what its kind kept from another label. It now stores rows only for the labels whose rows it changed. --- crates/engine/src/cmd/appearance.rs | 18 +++--- crates/engine/src/cmd/graph.rs | 9 +-- crates/engine/src/cmd/graph/series.rs | 80 +++++++++++++++++++++--- crates/engine/src/cmd/graph/tests.rs | 90 +++++++++++++++++++++++++++ crates/engine/src/cmd/style.rs | 12 ++-- docs/mcp.md | 13 ++-- 6 files changed, 191 insertions(+), 31 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index fd4e072537..fcc0147d04 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 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: 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 of the kinds 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 (a pick of some attributes without `append`: only what it changes; with `append`: only the kinds of row it adds) → {ids}", has_doc, copy_from ), @@ -1473,8 +1473,8 @@ fn move_contents(s: &mut Session, ids: &[NodeId], to: usize) -> Result { slot.get_or_insert(n.appearance.contents_at()); } 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); + // A graph label's kind keeps where its rows paint relative to the characters, from the labels the move changed. + let labels = capture_row_edits(&before, d, &shown_rows_edited(&before, d, ids.to_vec(), |_| false)); Ok(count_changed(d, &before, ids) + usize::from(labels)) })?; Ok(json!({ "contents": slot })) @@ -1742,12 +1742,13 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { // 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. + // also when the label or line picked onto still shows other ones until the graph is drawn again. `append` keeps + // only the kinds of row it added; a row of the other kind stays as the kind keeps it. 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 rows = if append { + super::graph::capture_label_kind_rows(d, &targets, paints, transparency) + } else { + 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)?; @@ -1755,6 +1756,7 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { // changed, and the rest stay as its kind keeps them, which the line may not show yet. Row attributes the graph // does not keep (overprint, caps, joins, miter limit, dashes) leave what its kind keeps as it is. let lines = match (rows_written, transparency) { + _ if append => super::graph::capture_line_kind_rows(d, &targets, paints, 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), diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index 3bdaa4e875..c008507581 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -46,11 +46,12 @@ 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, + LabelTextChange, capture_label_anti_alias, capture_label_changes, capture_label_kind_rows, capture_label_object_opacity, capture_label_paragraphs, capture_label_rows, capture_label_styles, capture_label_styles_given, capture_label_text, capture_line_changes, - capture_line_fill_stroke_rows, capture_line_paint_writes, capture_line_rows, capture_series_object_opacity, capture_series_opacity, - capture_series_top_paints, graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, labels_in, paint_targets, - series_group_marks, series_group_marks_where, series_groups_among, series_marks_in, series_object_opacity_differs, shown_paint, + capture_line_fill_stroke_rows, capture_line_kind_rows, capture_line_paint_writes, capture_line_rows, capture_series_object_opacity, + capture_series_opacity, capture_series_top_paints, graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, + 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 e979fd13d0..42fc640809 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -864,6 +864,46 @@ enum Keep { Object, /// The fill and stroke rows; the object opacity and blend mode stay as the kind keeps them. Rows, + /// The fill row with `fill`, the stroke row with `stroke`, and the object opacity and blend mode with `object`; the + /// others stay as the kind keeps them. Each row keeps its place relative to the characters; a row taken from the + /// label or line paints above a kept row on the same side of them, unless the label or line shows it below its own row + /// of that kind. + Kinds { fill: bool, stroke: bool, object: bool }, +} + +/// The kinds (true: fill) of the rows in `rows` from the bottom up, each with whether it paints below the characters. +fn row_places(rows: &vectorcraft_doc::LabelRows) -> Vec<(bool, bool)> { + let order = if rows.stroke_under { [false, true] } else { [true, false] }; + let has = |fill: bool| if fill { rows.paint.fill.is_some() } else { rows.paint.stroke.is_some() }; + let below = usize::from(rows.below.unwrap_or(0)); + order.into_iter().filter(|k| has(*k)).enumerate().map(|(i, k)| (k, i < below)).collect() +} + +/// Where the rows paint when the row of kind `taken` (true: fill) comes from `shown` and the row of the other kind from +/// `kept`, each keeping its place relative to the characters: `below` and `stroke_under` of [`vectorcraft_doc::LabelRows`]. +fn merged_places(kept: &vectorcraft_doc::LabelRows, shown: &vectorcraft_doc::LabelRows, taken: bool) -> (Option, bool) { + let in_shown = row_places(shown); + let t = in_shown.iter().copied().find(|p| p.0 == taken); + let o = row_places(kept).into_iter().find(|p| p.0 != taken); + let order = match (t, o) { + (Some(t), Some(o)) => { + // Rows on different sides of the characters: the one below them is lower. On the same side: as the label or + // line shows them, else the taken row on top. + let at = |kind: bool| in_shown.iter().position(|p| p.0 == kind); + let o_first = if t.1 != o.1 { + o.1 + } else { + match (at(!taken), at(taken)) { + (Some(o_at), Some(t_at)) => o_at < t_at, + _ => true, + } + }; + if o_first { vec![o, t] } else { vec![t, o] } + } + (t, o) => t.into_iter().chain(o).collect(), + }; + let below = order.iter().filter(|p| p.1).fold(0u8, |k, _| k + 1); + ((below > 0).then_some(below), order.len() == 2 && !order[0].0) } /// `shown` with the parts of the rows `kept` keeps that `keep` leaves as they are. @@ -880,6 +920,27 @@ 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::Kinds { fill, stroke, object } => { + let places = match (fill, stroke) { + (true, true) => (shown.below, shown.stroke_under), + (false, false) => (kept.below, kept.stroke_under), + (taken, _) => merged_places(&kept, &shown, taken), + }; + let mut rows = shown; + (rows.below, rows.stroke_under) = places; + let (r, k) = (&mut rows.paint, kept.paint); + if !object { + (r.opacity, r.blend) = (k.opacity, k.blend); + } + if !fill { + (r.fill, r.fill_opacity, r.fill_blend, r.fill_unit_box) = (k.fill, k.fill_opacity, k.fill_blend, k.fill_unit_box); + } + if !stroke { + (r.stroke, r.stroke_width, r.stroke_opacity, r.stroke_blend, r.stroke_unit_box) = + (k.stroke, k.stroke_width, k.stroke_opacity, k.stroke_blend, k.stroke_unit_box); + } + rows + } } } @@ -1038,12 +1099,17 @@ pub(crate) fn capture_label_object_opacity(doc: &mut Document, ids: &[NodeId]) - 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) +/// Keep, for every label or line of their kind, the fill row (with `fill`) and the stroke row (with `stroke`) that graph +/// labels and graph lines `ids` show, and with `object` their object opacity and blend mode, as [`capture_label_rows`] +/// keeps them, for an edit that wrote only those: a row of the other kind stays as the kind keeps it, also when a label or +/// line still shows its own one until the graph is drawn again. Returns whether what the graph keeps changed. +pub(crate) fn capture_label_kind_rows(doc: &mut Document, ids: &[NodeId], (fill, stroke): (bool, bool), object: bool) -> bool { + store_label_rows(doc, ids, Keep::Kinds { fill, stroke, object }) +} + +/// [`capture_label_kind_rows`] for the graph lines among `ids` alone. +pub(crate) fn capture_line_kind_rows(doc: &mut Document, ids: &[NodeId], (fill, stroke): (bool, bool), object: bool) -> bool { + store_line_rows(doc, ids, Keep::Kinds { fill, stroke, object }) } /// Would [`capture_label_object_opacity`] change what a graph keeps for labels `ids`? Reads the document without copying @@ -1061,7 +1127,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_kind_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 6626b46051..4f3b05cfa1 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -6997,6 +6997,96 @@ fn a_graphic_style_added_to_a_label_or_axis_line_keeps_the_opacity_its_kind_keep } } +/// A fill-only graphic style added on top of a graph label or axis line, or a fill-only source appended to one with the +/// Eyedropper, keeps the stroke its kind keeps from another label or line, though the one it is added to still shows its +/// own. +#[test] +fn a_fill_added_to_a_label_or_axis_line_keeps_the_stroke_its_kind_keeps() { + let cases = [(false, false), (false, true), (true, false), (true, true)]; + every_case(cases, |&(label, append)| { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let (rect, _) = blue_style(&mut s, "Blue", false); + 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(); + s.execute("appearance.setItem", &json!({"ids": [first.0], "index": top_row(&s, first, false), "color": "#ff0000"})).unwrap(); + } else { + s.execute("paint.setStroke", &json!({"ids": [first.0], "color": "#ff0000"})).unwrap(); + } + if append { + let pick = json!({"source": rect.0, "ids": [second.0], "apply": every_row_attribute_without_transparency(), "append": true}); + s.execute("appearance.copyFrom", &pick).unwrap(); + } else { + s.execute("graphicStyle.apply", &json!({"name": "Blue", "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); + let shows = |fill: bool, hex: &str| rows.iter().any(|r| r.0 == fill && r.1 == hex); + assert!(shows(false, "#ff0000") && shows(true, "#0000ff"), "{q}: {rows:?}"); + } + } else { + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| l.0 == "#ff0000"), "{looks:?}"); + } + }); +} + +/// A stroke a label's kind keeps below the characters stays below them when a fill-only graphic style is added on top of +/// another label of the kind, or a fill-only source appended to it, and the new fill paints above the characters. +#[test] +fn a_fill_added_to_a_label_keeps_the_kept_stroke_below_the_characters() { + every_case([false, true], |&append| { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "column"); + let (rect, _) = blue_style(&mut s, "Blue", false); + let (q1, q2) = (text_id(&s, id, "Axes", "Q1"), text_id(&s, id, "Axes", "Q2")); + s.execute("appearance.addStroke", &json!({"ids": [q1.0]})).unwrap(); + s.execute("appearance.moveItem", &json!({"ids": [q1.0], "from": "contents", "to": 1})).unwrap(); + if append { + let pick = json!({"source": rect.0, "ids": [q2.0], "apply": every_row_attribute_without_transparency(), "append": true}); + s.execute("appearance.copyFrom", &pick).unwrap(); + } else { + s.execute("graphicStyle.apply", &json!({"name": "Blue", "ids": [q2.0], "add": true})).unwrap(); + } + redrawn_label_rows(&mut s, id); + let look = |ap: &vectorcraft_doc::Appearance| (ap.contents_at(), ap.items.iter().map(|it| it.is_fill()).collect::>()); + for q in ["Q1", "Q2", "Q3"] { + assert_eq!(look(&label_node(&s, id, "Axes", q).appearance), (1, vec![false, true]), "append {append}: {q}"); + } + }); +} + +/// A Contents (Characters) row move that leaves a graph label as it was keeps the rows its kind keeps from another label +/// and is no edit. +#[test] +fn a_contents_move_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 (q1, q2) = (text_id(&s, id, "Axes", "Q1"), text_id(&s, id, "Axes", "Q2")); + s.execute("appearance.addStroke", &json!({"ids": [q1.0]})).unwrap(); + s.execute("appearance.setItem", &json!({"ids": [q1.0], "index": top_row(&s, q1, false), "color": "#ff0000"})).unwrap(); + let at = s.doc().unwrap().doc.node(q2).unwrap().appearance.contents_at(); + let undo = s.doc().unwrap().history.undo.len(); + s.execute("appearance.moveItem", &json!({"ids": [q2.0], "from": "contents", "to": at})).unwrap(); + assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changed"); + 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 == "#ff0000"), "{q}: {rows:?}"); + } +} + /// 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 d415d6b4f1..914ad2b8bf 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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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}", + "{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 (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), the graph stores that object's topmost visible fill and stroke rows (with `add`: of the kinds of row the style shows) 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 ), @@ -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 its new rows of those kinds for its kind. The other kind, the object opacity and + // the blend mode stay as the kind keeps them. + super::graph::capture_label_kind_rows(d, &ids, kinds, false); } 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 591f40334e..049423aae3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -905,11 +905,13 @@ The `appearance.*` commands, `graphicStyle.apply` and `graphicStyle.redefine`, a transparency commands given an `item` (or the Appearance panel's active row) store a graph label's object rows for its kind of label: the paint, weight, opacity and blend mode of its topmost visible fill and stroke row, their order and 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, but an edit of a hidden row that leaves the topmost visible rows as they were stores nothing. `transparency.set` without an `item`, `object.setProps` with an opacity or blend mode, and +label already showed them, but an edit of a hidden row that leaves the topmost visible rows as they were, and an +`appearance.moveItem` of the Contents row that leaves them in place, store nothing. `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 +`appearance.copyFrom` with `append` stores the rows of the kinds it adds (fill, stroke or both), and the object opacity +and blend mode only when it also applies the object's transparency. `graphicStyle.apply` with `add` stores the rows of +the kinds the style shows. Both leave a row of the other kind as the kind keeps it, and `graphicStyle.apply` with `add` +also 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. @@ -929,7 +931,8 @@ The other commands store them when given the line itself, and the `appearance.*` `transparency.set` with an `item` also when given the Axes group, as described above. `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` +with `append`, store a line's rows even when the line already showed them; `graphicStyle.apply` with `add` and +`appearance.copyFrom` with `append` store only the kinds of row they add. 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. `paint.setFill`, `paint.setStroke`, `addon.color.fillToStroke` and `addon.color.strokeToFill` also store the paint they write on a line's topmost visible From d39334a7512b7035438e50558c88f25256e59271 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 07:09:42 -0800 Subject: [PATCH 15/15] Graphs: a row written to an axis line is kept for its kind appearance.addFill and appearance.addStroke on an axis line, tick mark or radar ring stored only the attributes the new row changed on the line, so a stroke the kind kept from another line came back when the graph was drawn again, although the line showed the new black stroke. They now store the row they add for the line's kind when it becomes the line's topmost visible row of its kind. An appearance.copyFrom of some attributes, appearance.setItem and stroke.set stored only what they changed, so a paint, stroke weight, row opacity or blend mode that the line already showed did not replace what its kind kept. What they write to the line's topmost visible rows is now stored for the kind, as paint.setStroke stores the paint it writes. Row opacity and blend mode are stored apart, so an edit of one leaves the other as the kind keeps it, and a null weight or opacity writes nothing. --- crates/engine/src/cmd/appearance.rs | 95 +++++++++++++++++-- crates/engine/src/cmd/graph.rs | 10 +- crates/engine/src/cmd/graph/series.rs | 57 ++++++++++-- crates/engine/src/cmd/graph/tests.rs | 128 ++++++++++++++++++++++++++ crates/engine/src/cmd/stroke.rs | 8 +- docs/mcp.md | 8 +- 6 files changed, 280 insertions(+), 26 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index b2df4133f1..5e3a6b79ee 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, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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?|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, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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, what the edit changes, and the row it adds when that row becomes the line's topmost visible row of its kind)", 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, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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?|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, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels), 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, what the edit changes, and the row it adds when that row becomes the line's topmost visible row of its kind)", has_doc, |s, p| add_item(s, p, false) ), @@ -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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; when their rows differ, `index` needs `aligned` and is a row of the backmost one), 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: 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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring (a graph's Axes group stands for the lines and labels directly in it, its Legend group for the labels; when their rows differ, `index` needs `aligned` and is a row of the backmost one), 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, what the edit changes, and the paint, weight, opacity and blend mode it writes to the line's topmost visible row)", has_doc, set_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, 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 of the kinds 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 (a pick of some attributes without `append`: only what it changes; with `append`: only the kinds of row it adds) → {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` its topmost visible fill and stroke rows of the kinds 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 (a pick of some attributes without `append`: what it changes, and the paint, stroke weight and row transparency it applies to the topmost visible rows; with `append`: only the kinds of row it adds) → {ids}", has_doc, copy_from ), @@ -695,6 +695,45 @@ pub(crate) fn edit_items_then( cmd: &str, label: &str, fill: bool, + f: impl FnMut(&mut Node, Option) -> Result<()>, + after: impl FnMut(&vectorcraft_doc::Document, &mut vectorcraft_doc::Document, &[NodeId]) -> Result, +) -> Result> { + edit_items_writing_then(s, ids, item, of, cmd, label, fill, super::graph::RowWrites::NONE, f, after) +} + +/// [`edit_items`] for an edit that writes the attributes `writes` says to the row of each target it edits: a graph line +/// keeps them for its kind when that row is its topmost visible one, also when the line already showed them +/// ([`super::graph::capture_line_row_writes`]). +#[allow(clippy::too_many_arguments)] +pub(crate) fn edit_items_writing( + s: &mut Session, + ids: &[NodeId], + item: ItemTarget, + of: Option, + cmd: &str, + label: &str, + fill: bool, + writes: super::graph::RowWrites, + f: impl FnMut(&mut Node, Option) -> Result<()>, +) -> Result> { + edit_items_writing_then(s, ids, item, of, cmd, label, fill, writes, f, |before, d, edited| { + let series = capture_series_changes(before, d, edited); + let labels = super::graph::capture_label_changes(before, d, edited, false, None); + Ok(series || labels) + }) +} + +/// [`edit_items_then`] with the attributes `writes` says, as [`edit_items_writing`] keeps them. +#[allow(clippy::too_many_arguments)] +fn edit_items_writing_then( + s: &mut Session, + ids: &[NodeId], + item: ItemTarget, + of: Option, + cmd: &str, + label: &str, + fill: bool, + writes: super::graph::RowWrites, mut f: impl FnMut(&mut Node, Option) -> Result<()>, mut after: impl FnMut(&vectorcraft_doc::Document, &mut vectorcraft_doc::Document, &[NodeId]) -> Result, ) -> Result> { @@ -720,6 +759,8 @@ pub(crate) fn edit_items_then( let mut rows = Vec::new(); // The objects where `f` wrote the topmost visible row of its kind. let mut wrote = Vec::new(); + // The row of each object `f` wrote: its index, else the topmost row of the kind. + let mut written = Vec::new(); for (id, item) in ids.iter().zip(&per) { let Some(item) = item else { continue }; let Some(n) = d.node_mut(*id) else { continue }; @@ -732,13 +773,18 @@ pub(crate) fn edit_items_then( if index.is_none_or(|i| is_top_shown(n, i)) { wrote.push(*id); } + written.extend(index.or_else(|| n.appearance.items.iter().rposition(|it| it.is_fill() == fill)).map(|at| (*id, at))); } 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. + // A graph line keeps only the attributes of its rows that the edit changed, and those it wrote (`writes`): 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, &shown_rows_edited(&before, d, rows, |id| wrote.contains(&id))); - let lines = super::graph::capture_line_changes(&before, d, &edited); + let mut lines = super::graph::capture_line_changes(&before, d, &edited); + if writes != super::graph::RowWrites::NONE { + let (on_fill, on_stroke) = if fill { (writes, super::graph::RowWrites::NONE) } else { (super::graph::RowWrites::NONE, writes) }; + lines |= super::graph::capture_line_row_writes(d, &written, on_fill, on_stroke); + } Ok(count_changed(d, &before, &edited) + usize::from(more || labels || lines)) })?; Ok(aimed) @@ -896,10 +942,13 @@ fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result { } } super::graph::capture_series_opacity(d, &top_opacity_changed(&before, d, &ids)); + let lines: Vec = added.iter().map(|(id, _)| *id).collect(); let mut rows = top_paint_changed(&before, d, &ids); rows.extend(painted_rows(d, added)); super::graph::capture_series_top_paints(d, &rows); capture_row_edits(&before, d, &ids); + // A graph line keeps the row it got for its kind, also when it showed that row's paint, weight and transparency. + super::graph::capture_line_kind_rows(d, &lines, (fill, !fill), false); Ok(()) })?; // A fill added above the active row becomes the active row; otherwise the rows above the new @@ -1277,7 +1326,17 @@ fn set_item(s: &mut Session, p: &Value) -> Result { let painted = super::graph::capture_series_top_paints(d, &rows); let reached = shown_rows_edited(&before, d, reached, |id| edited.iter().any(|(e, _)| *e == id)); let labels = capture_row_edits(&before, d, &reached); - Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) + // A graph line keeps what was written to its topmost visible row, also when it already showed it. + let tops: Vec<(NodeId, usize)> = ids.iter().zip(&per).filter_map(|(id, at)| Some((*id, *at.first()?))).collect(); + // Only the values the edit applied: a null weight or opacity leaves the row as it is. + let writes = super::graph::RowWrites { + paint: paint.is_some(), + weight: p.get("weight").and_then(Value::as_f64).is_some(), + opacity: p.get("opacity").and_then(Value::as_f64).is_some(), + blend: blend.is_some(), + }; + let lines = super::graph::capture_line_row_writes(d, &tops, super::graph::RowWrites { weight: false, ..writes }, writes); + Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels || lines)) })?; if let Some(pa) = &paint { s.remember_paint(pa); @@ -1886,7 +1945,25 @@ fn copy_from(s: &mut Session, p: &Value) -> Result { _ if append => super::graph::capture_line_kind_rows(d, &targets, paints, 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), + (false, _) => { + // The topmost row of each kind, which the pick wrote: what it wrote is kept also when the line showed it. + let tops: Vec<(NodeId, usize)> = targets + .iter() + .filter_map(|id| d.node(*id).map(|n| (*id, &n.appearance.items))) + .flat_map(|(id, items)| { + [true, false].into_iter().filter_map(move |kind| items.iter().rposition(|it| it.is_fill() == kind).map(|at| (id, at))) + }) + .collect(); + // A transparency pick applies the row's opacity and blend mode together. + let on_fill = super::graph::RowWrites { paint: fill.color, weight: false, opacity: opacities.0, blend: opacities.0 }; + let on_stroke = super::graph::RowWrites { + paint: stroke.color, + weight: stroke.weight && source_has(false), + opacity: opacities.1, + blend: opacities.1, + }; + super::graph::capture_line_changes(&before, d, &targets) | super::graph::capture_line_row_writes(d, &tops, on_fill, on_stroke) + } }; 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 93e79e857e..f5a07715cf 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -48,12 +48,12 @@ use generate::generate; #[cfg(test)] use series::default_series_color; pub(crate) use series::{ - LabelTextChange, capture_label_anti_alias, capture_label_changes, capture_label_kind_rows, capture_label_object_opacity, + LabelTextChange, RowWrites, capture_label_anti_alias, capture_label_changes, capture_label_kind_rows, capture_label_object_opacity, capture_label_paragraphs, capture_label_rows, capture_label_styles, capture_label_styles_given, capture_label_text, capture_line_changes, - capture_line_fill_stroke_rows, capture_line_kind_rows, capture_line_paint_writes, capture_line_rows, capture_series_object_opacity, - capture_series_opacity, capture_series_top_paints, graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, - 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_fill_stroke_rows, capture_line_kind_rows, capture_line_paint_writes, capture_line_row_writes, capture_line_rows, + capture_series_object_opacity, capture_series_opacity, capture_series_top_paints, graph_part_members, is_design_art, is_graph_line, + label_object_opacity_differs, label_rows, 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 98352fe809..3651c41a9a 100644 --- a/crates/engine/src/cmd/graph/series.rs +++ b/crates/engine/src/cmd/graph/series.rs @@ -1443,25 +1443,68 @@ pub(crate) fn capture_line_changes(before: &Document, doc: &mut Document, ids: & /// 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 paint = RowWrites { paint: true, ..RowWrites::NONE }; + capture_line_row_writes(doc, written, paint, paint) +} + +/// Which attributes of a fill or stroke row an edit wrote, for [`capture_line_row_writes`]. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(crate) struct RowWrites { + /// The paint. + pub paint: bool, + /// The weight (a stroke row only). + pub weight: bool, + /// The row's opacity. + pub opacity: bool, + /// The row's blend mode. + pub blend: bool, +} + +impl RowWrites { + /// No attribute. + pub const NONE: RowWrites = RowWrites { paint: false, weight: false, opacity: false, blend: false }; +} + +/// [`capture_line_paint_writes`] for the attributes `fill` says of a written fill row and `stroke` says of a written +/// stroke row: each is kept for every line of the kind as the line shows it, also when the line already showed it, in +/// place of what its kind keeps from another line. +pub(crate) fn capture_line_row_writes(doc: &mut Document, written: &[(NodeId, usize)], fill: RowWrites, stroke: RowWrites) -> 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 { + let wrote = |kind: bool| items.iter().rposition(|it| it.is_fill() == kind && it.visible()).is_some_and(|at| written.contains(&(id, at))); + let on_fill = if wrote(true) { fill } else { RowWrites::NONE }; + let on_stroke = if wrote(false) { stroke } else { RowWrites::NONE }; + if on_fill == RowWrites::NONE && on_stroke == RowWrites::NONE { 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; + let k = &mut rows.paint; + if on_fill.paint { + k.fill = shown.fill; } - if stroke { - rows.paint.stroke = shown.stroke; + if on_fill.opacity { + k.fill_opacity = shown.fill_opacity; + } + if on_fill.blend { + k.fill_blend = shown.fill_blend; + } + if on_stroke.paint { + k.stroke = shown.stroke; + } + if on_stroke.weight { + k.stroke_width = shown.stroke_width; + } + if on_stroke.opacity { + k.stroke_opacity = shown.stroke_opacity; + } + if on_stroke.blend { + k.stroke_blend = shown.stroke_blend; } let kept = (rows != line.default_rows()).then_some(rows); changed |= *slot != kept; diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 5775197535..7e51fd6456 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -8271,6 +8271,134 @@ fn a_stroke_written_to_an_axis_line_that_shows_it_is_kept() { }); } +/// A stroke added to an axis line whose stroke shows the paint the new one takes is kept for every axis line, in place of +/// the stroke the kind keeps from another line. +#[test] +fn a_stroke_added_to_an_axis_line_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.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"); + s.execute("appearance.addStroke", &json!({"ids": [lines[1].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 added 1 pt black stroke: {looks:?}"); +} + +/// An Eyedropper pick of the stroke color, weight or transparency alone onto an axis line that already shows what it +/// writes is kept for every axis line, in place of what the kind keeps from another line. +#[test] +fn an_eyedropper_pick_an_axis_line_already_shows_is_kept() { + let stroke_row = |n: &vectorcraft_doc::Node| n.appearance.items.iter().rposition(|it| !it.is_fill()).unwrap(); + let cases = [("color", json!({"color": "#ff0000"})), ("weight", json!({"weight": 2})), ("transparency", json!({"opacity": 40}))]; + every_case(cases, |(attr, edit)| { + 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": "#000000"})).unwrap(); + s.execute("stroke.set", &json!({"ids": [rect.0], "weight": 0.5})).unwrap(); + let lines = line_nodes(&s, id); + let mut p = edit.clone(); + p["ids"] = json!([lines[0].id.0]); + match *attr { + "color" => s.execute("paint.setStroke", &p), + "weight" => s.execute("stroke.set", &p), + _ => { + p["index"] = json!(stroke_row(&lines[0])); + s.execute("appearance.setItem", &p) + } + } + .unwrap(); + let shown = line_nodes(&s, id)[1].clone(); + assert_eq!(line_look(&shown), ("#000000".into(), 0.5, 1.0), "{attr}: the other lines show the default until the graph is drawn again"); + let fill = json!({"color": false, "transparency": false, "overprint": false}); + let mut stroke = json!({"color": false, "transparency": false, "overprint": false, "weight": false, "cap": false, "join": false, "miter": false, "dash": false}); + stroke[*attr] = json!(true); + let apply = json!({"appearance": {"transparency": false, "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 == ("#000000".into(), 0.5, 1.0)), "{attr}: {looks:?}"); + let opacities: Vec = line_nodes(&s, id).iter().map(|n| n.appearance.items[stroke_row(n)].opacity()).collect(); + assert!(opacities.iter().all(|o| *o == 1.0), "{attr}: {opacities:?}"); + }); +} + +/// A stroke color, weight or opacity set with `appearance.setItem`, or a weight set with `stroke.set`, on an axis line +/// that already shows it is kept for every axis line, in place of what the kind keeps from another line. +#[test] +fn a_row_attribute_set_on_an_axis_line_that_shows_it_is_kept() { + let stroke_row = |n: &vectorcraft_doc::Node| n.appearance.items.iter().rposition(|it| !it.is_fill()).unwrap(); + let cases = [ + ("appearance.setItem", json!({"color": "#ff0000"}), json!({"color": "#000000"})), + ("appearance.setItem", json!({"weight": 2}), json!({"weight": 0.5})), + ("appearance.setItem", json!({"opacity": 40}), json!({"opacity": 100})), + ("stroke.set", json!({"weight": 2}), json!({"weight": 0.5})), + ]; + every_case(cases, |(cmd, kept, shown)| { + 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); + for (line, values) in [(&lines[0], kept), (&lines[1], shown)] { + let mut p = values.clone(); + p["ids"] = json!([line.id.0]); + if *cmd == "appearance.setItem" { + p["index"] = json!(stroke_row(line)); + } + s.execute(cmd, &p).unwrap(); + } + let looks = redrawn_line_looks(&mut s, id); + assert!(looks.iter().all(|l| *l == ("#000000".into(), 0.5, 1.0)), "{cmd} {shown}: {looks:?}"); + let opacities: Vec = line_nodes(&s, id).iter().map(|n| n.appearance.items[stroke_row(n)].opacity()).collect(); + assert!(opacities.iter().all(|o| *o == 1.0), "{cmd} {shown}: {opacities:?}"); + }); +} + +/// `appearance.setItem` of a row's opacity alone on an axis line keeps the blend mode the kind keeps from another line, +/// and of its blend mode alone the opacity; a null weight or opacity writes nothing and adds no undo step. +#[test] +fn a_row_attribute_set_on_an_axis_line_keeps_the_others_its_kind_keeps() { + let stroke_row = |n: &vectorcraft_doc::Node| n.appearance.items.iter().rposition(|it| !it.is_fill()).unwrap(); + let row = |n: &vectorcraft_doc::Node| { + let it = &n.appearance.items[stroke_row(n)]; + (it.opacity(), it.blend()) + }; + let cases = [ + (json!({"blend": "multiply"}), json!({"opacity": 100}), (1.0, BlendMode::Multiply)), + (json!({"opacity": 40}), json!({"blend": "normal"}), (0.4, BlendMode::Normal)), + ]; + every_case(cases, |(kept, shown, want)| { + 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); + for (line, values) in [(&lines[0], kept), (&lines[1], shown)] { + let mut p = values.clone(); + p["ids"] = json!([line.id.0]); + p["index"] = json!(stroke_row(line)); + s.execute("appearance.setItem", &p).unwrap(); + } + redrawn_line_looks(&mut s, id); + let rows: Vec<(f32, BlendMode)> = line_nodes(&s, id).iter().map(row).collect(); + assert!(rows.iter().all(|r| *r == *want), "{shown}: {rows:?}"); + }); + 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(); + let steps = s.doc().unwrap().history.undo.len(); + for key in ["weight", "opacity"] { + let mut p = json!({"ids": [lines[1].id.0], "index": stroke_row(&lines[1])}); + p[key] = serde_json::Value::Null; + s.execute("appearance.setItem", &p).unwrap(); + } + assert_eq!(s.doc().unwrap().history.undo.len(), steps, "a null value adds no undo step"); + assert!(redrawn_line_looks(&mut s, id).iter().all(|l| l.0 == "#ff0000")); +} + #[test] fn pie_names_and_wedge_labels_keep_their_style() { let mut s = Session::new(); diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index 00feae339a..e16dce9495 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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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}", + "{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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, and the weight it writes to the topmost visible stroke, 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 ), @@ -304,8 +304,10 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result { } }; let of = super::appearance::reference_of(s, p, item, C)?; - // The objects counted: with a design's art, those with a row equal to the art's. - let ids = edit_items(s, &ids, item, of, C, "Stroke", false, |n, index| { + // The objects counted: with a design's art, those with a row equal to the art's. A graph line keeps the weight + // given to it, also when it already showed it. + let writes = super::graph::RowWrites { weight: change.weight.is_some(), ..super::graph::RowWrites::NONE }; + let ids = super::appearance::edit_items_writing(s, &ids, item, of, C, "Stroke", false, writes, |n, index| { if index.is_none() && let NodeKind::Text(t) = &mut n.kind { diff --git a/docs/mcp.md b/docs/mcp.md index 47d14ac50f..644ddb802b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -972,11 +972,15 @@ The other commands store them when given the line itself, and the `appearance.*` `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; `graphicStyle.apply` with `add` and -`appearance.copyFrom` with `append` store only the kinds of row they add. The other commands, an `appearance.copyFrom` +`appearance.copyFrom` with `append` store only the kinds of row they add. `appearance.addFill` and +`appearance.addStroke` store the row they add when it becomes the line's topmost visible row of its kind, also when the +line already showed its paint, weight and opacity. 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. `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.copyFrom` that does not apply +fill or stroke row when the line already showed it. `appearance.setItem` and an `appearance.copyFrom` of some +attributes store the paint, stroke weight, and row opacity and blend mode they write to that row in the same way, and +`stroke.set` stores the weight it writes there. 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 even when the line already showed them, and leaves the object opacity and blend mode the kind keeps. Rows