mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 12:03:31 +00:00
Merge pull request #7412 from dotCooCoo/fix/graph-axes-group-edits-kept
Graphs: Appearance edits given the Axes or Legend group are kept
This commit is contained in:
@@ -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 {
|
||||
@@ -180,6 +180,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<LabelRows>,
|
||||
/// 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<LabelRows>,
|
||||
/// 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<LabelRows>,
|
||||
}
|
||||
|
||||
impl LabelStyles {
|
||||
|
||||
@@ -384,14 +384,14 @@ pub fn override_paints(n: &Node) -> impl Iterator<Item = &Paint> {
|
||||
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<Item = &Paint> {
|
||||
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())
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ fn graph_paints_mut(g: &mut crate::graph::GraphSpec) -> impl Iterator<Item = &mu
|
||||
let series = g.series_paints.iter_mut().flat_map(|s| [s.fill.as_mut(), s.stroke.as_mut()]).flatten();
|
||||
let l = &mut g.label_styles;
|
||||
let labels = [&mut l.values, &mut l.categories, &mut l.legend].into_iter().flatten();
|
||||
let rows = [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows].into_iter().flatten();
|
||||
let rows = [&mut l.values_rows, &mut l.categories_rows, &mut l.legend_rows, &mut l.axis_rows, &mut l.ring_rows].into_iter().flatten();
|
||||
series
|
||||
.chain(labels.flat_map(|st| [&mut st.fill, &mut st.stroke]))
|
||||
.chain(rows.flat_map(|r| [r.paint.fill.as_mut(), r.paint.stroke.as_mut()]).flatten())
|
||||
@@ -718,6 +718,14 @@ mod tests {
|
||||
paint: crate::SeriesPaint { fill: Some(red.clone()), ..Default::default() },
|
||||
..Default::default()
|
||||
}),
|
||||
axis_rows: Some(crate::LabelRows {
|
||||
paint: crate::SeriesPaint { stroke: Some(red.clone()), ..Default::default() },
|
||||
..Default::default()
|
||||
}),
|
||||
ring_rows: Some(crate::LabelRows {
|
||||
paint: crate::SeriesPaint { stroke: Some(red.clone()), ..Default::default() },
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
@@ -725,18 +733,20 @@ mod tests {
|
||||
d.node_mut(a).unwrap().extras_mut().graph = Some(Box::new(spec));
|
||||
let mut seen = 0;
|
||||
d.visit_paints(&mut |p| seen += usize::from(*p == red));
|
||||
assert_eq!(seen, 5, "the fill and the graph's series fill, series stroke, legend fill and value label fill row");
|
||||
assert_eq!(seen, 7, "the fill and the graph's series fill, series stroke, legend fill, value label fill row and axis and ring stroke rows");
|
||||
let blue = Color::rgb(0.0, 0.0, 1.0);
|
||||
let mut to_blue = |c: &mut Color, s: &mut Option<String>, _: &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));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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 (none when nothing changes); 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 (none when nothing changes); 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<CommandSpec> {
|
||||
"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<CommandSpec> {
|
||||
"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 (none when nothing changes): 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 (none when nothing changes): 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<CommandSpec> {
|
||||
"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,10 @@ fn copy_paint(s: &mut Session, p: &Value, to_stroke: bool) -> Result<Value> {
|
||||
// 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<NodeId> = written.iter().map(|(id, _)| *id).collect();
|
||||
// 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))
|
||||
})?;
|
||||
}
|
||||
// The defaults for new art change the same way, as Swap Fill and Stroke changes them.
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, 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, 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<CommandSpec> {
|
||||
"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, 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, 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)
|
||||
),
|
||||
@@ -66,7 +66,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, and the art of a graph design in a series, which is left out: 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, 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",
|
||||
has_doc,
|
||||
clear_appearance
|
||||
),
|
||||
@@ -75,7 +75,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, and the art of a graph design in a series, which is left out: 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, 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)",
|
||||
has_doc,
|
||||
reduce_basic
|
||||
),
|
||||
@@ -84,7 +84,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, 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; 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
|
||||
),
|
||||
@@ -93,7 +93,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, and the art of a graph design in a series, which is left out: 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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, 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, 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 (of a line, only what the edit changes)",
|
||||
has_doc,
|
||||
remove_item
|
||||
),
|
||||
@@ -111,7 +111,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, and the art of a graph design in a series, which is left out: 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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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, 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, 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 (of a line, only what the edit changes)",
|
||||
has_doc,
|
||||
duplicate_item
|
||||
),
|
||||
@@ -120,7 +120,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, or differ from that of a graph design's art given first)} 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, and the art of a graph design in a series, which is left out: 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, or differ from that of a graph design's art given first)} 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, 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; 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 (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<CommandSpec> {
|
||||
"Eyedropper",
|
||||
[],
|
||||
None,
|
||||
"{source: id, ids?, pickUp?, apply? (trees as eyedropper.setOptions, merged over the Eyedropper Options for this call), reverse?: bool, append?: bool, defaultsOnly?: bool} copy the attributes both picked up and applied (by default the whole appearance stack, opacity and blend mode, and from type to type the character and paragraph attributes using effective character dimensions while preserving target transforms) from `source` to ids (default: highlighted characters while editing type, after Select All in a frame of threaded text the text of the story's frames, leaving out `source`, otherwise the object selection; highlighted characters reject enabled non-neutral object transparency), the fill, stroke and weight also to the paint defaults; `defaultsOnly` updates only paint defaults and cannot be combined with ids, reverse or append; `reverse` (Alt-click) copies from the first selected object (or ids) onto `source` instead, or with nothing selected what the Eyedropper picked up last (a click without Alt); `append` (Shift+Alt-click) adds the source's fills, strokes and effects on top of each target's stack; placed gradients land at the same place relative to each target's bounds (defaults: fitted to new art); with an object of a dynamic symbol instance selected by Direct Selection and no ids, reverse, append or defaultsOnly, that object takes the source's fill and stroke (solid, none, gradient or pattern) for this instance only, as the Eyedropper Options allow, and a source that is not a path, compound path or type, or options that pick up neither color, are refused. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke and the object's opacity and blend mode (exceptions, and the art of a graph design in a series, which is left out: docs/mcp.md); on a graph label, the graph stores, for every label of its kind, the character attributes the pick gives all of its text, its object opacity and blend mode, 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, 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
|
||||
),
|
||||
@@ -147,7 +147,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, and the art of a graph design in a series, which is left out: 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, 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}",
|
||||
has_doc,
|
||||
show_all_hidden
|
||||
),
|
||||
@@ -165,7 +165,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, and the art of a graph design in a series, which is left out: 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, 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 → {source, target}",
|
||||
has_doc,
|
||||
transfer
|
||||
),
|
||||
@@ -538,7 +538,8 @@ pub(crate) fn design_art_in(d: &Document, roots: &[NodeId]) -> Vec<NodeId> {
|
||||
}
|
||||
|
||||
/// `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<NodeId> {
|
||||
super::graph::series_group_marks_where(d, ids, |group| group.appearance.items.is_empty())
|
||||
@@ -559,8 +560,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<NodeId> {
|
||||
super::graph::series_group_marks_where(d, &[id], holds_no_look)
|
||||
}
|
||||
@@ -626,11 +628,48 @@ fn require_targets(s: &Session, p: &Value, cmd: &str) -> Result<Vec<NodeId>> {
|
||||
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(())
|
||||
}
|
||||
|
||||
/// 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<NodeId>, wrote: impl Fn(NodeId) -> bool) -> Vec<NodeId> {
|
||||
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
|
||||
/// 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_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.
|
||||
///
|
||||
@@ -652,7 +691,7 @@ pub(crate) fn edit_items(
|
||||
edit_items_then(s, ids, item, of, 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)
|
||||
})
|
||||
}
|
||||
@@ -670,6 +709,45 @@ pub(crate) fn edit_items_then(
|
||||
cmd: &str,
|
||||
label: &str,
|
||||
fill: bool,
|
||||
f: impl FnMut(&mut Node, Option<usize>) -> Result<()>,
|
||||
after: impl FnMut(&vectorcraft_doc::Document, &mut vectorcraft_doc::Document, &[NodeId]) -> Result<bool>,
|
||||
) -> Result<Vec<NodeId>> {
|
||||
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<NodeId>,
|
||||
cmd: &str,
|
||||
label: &str,
|
||||
fill: bool,
|
||||
writes: super::graph::RowWrites,
|
||||
f: impl FnMut(&mut Node, Option<usize>) -> Result<()>,
|
||||
) -> Result<Vec<NodeId>> {
|
||||
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<NodeId>,
|
||||
cmd: &str,
|
||||
label: &str,
|
||||
fill: bool,
|
||||
writes: super::graph::RowWrites,
|
||||
mut f: impl FnMut(&mut Node, Option<usize>) -> Result<()>,
|
||||
mut after: impl FnMut(&vectorcraft_doc::Document, &mut vectorcraft_doc::Document, &[NodeId]) -> Result<bool>,
|
||||
) -> Result<Vec<NodeId>> {
|
||||
@@ -693,6 +771,10 @@ 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();
|
||||
// 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 };
|
||||
@@ -702,10 +784,22 @@ 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);
|
||||
}
|
||||
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)?;
|
||||
let labels = super::graph::capture_label_rows(d, &rows);
|
||||
Ok(count_changed(d, &before, &edited) + usize::from(more || labels))
|
||||
// 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 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)
|
||||
}
|
||||
@@ -716,6 +810,17 @@ pub(crate) fn first_edited(s: &Session, item: ItemTarget, of: Option<NodeId>, id
|
||||
ids.iter().zip(item.per_target_of(s, of, ids)).find_map(|(id, it)| Some((*id, it?)))
|
||||
}
|
||||
|
||||
/// 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<NodeId> = 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()
|
||||
@@ -854,10 +959,13 @@ fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
super::graph::capture_series_opacity(d, &top_opacity_changed(&before, d, &ids));
|
||||
let lines: Vec<NodeId> = 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);
|
||||
super::graph::capture_label_rows(d, &ids);
|
||||
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
|
||||
@@ -1046,7 +1154,7 @@ fn transfer(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut targets: Vec<NodeId> = 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);
|
||||
}
|
||||
@@ -1091,8 +1199,9 @@ fn transfer(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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<NodeId> = from.iter().chain(&targets).chain(&group).copied().collect();
|
||||
Ok(count_changed(d, &before, &all) + usize::from(kept || painted || object || labels || forgot))
|
||||
})?;
|
||||
@@ -1150,7 +1259,7 @@ fn reduce_basic(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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;
|
||||
@@ -1167,6 +1276,7 @@ fn set_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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.
|
||||
@@ -1175,6 +1285,9 @@ fn set_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let per = rows_per_target(&before, of, &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 };
|
||||
@@ -1185,6 +1298,7 @@ fn set_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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) => {
|
||||
@@ -1227,8 +1341,19 @@ fn set_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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);
|
||||
Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels))
|
||||
let reached = shown_rows_edited(&before, d, reached, |id| edited.iter().any(|(e, _)| *e == id));
|
||||
let labels = capture_row_edits(&before, d, &reached);
|
||||
// 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);
|
||||
@@ -1256,14 +1381,20 @@ pub(super) fn item_indices(p: &Value, cmd: &str) -> Result<Vec<usize>> {
|
||||
fn remove_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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();
|
||||
let of = design_reference(s, p, "appearance.removeItem")?;
|
||||
let per = rows_per_target(&before, of, &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.
|
||||
@@ -1275,7 +1406,7 @@ fn remove_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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, &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`.
|
||||
@@ -1295,6 +1426,7 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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.
|
||||
@@ -1319,6 +1451,8 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// 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();
|
||||
@@ -1343,6 +1477,7 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
ap.set_contents_at(c);
|
||||
}
|
||||
any = true;
|
||||
reached.push(*id);
|
||||
continue;
|
||||
}
|
||||
let mut idx = idx.clone();
|
||||
@@ -1357,6 +1492,9 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
added.push((*id, kind));
|
||||
}
|
||||
any = true;
|
||||
if reached.last() != Some(id) {
|
||||
reached.push(*id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1365,9 +1503,10 @@ fn duplicate_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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<NodeId> = added.iter().map(|(id, _)| *id).collect();
|
||||
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, &shown_rows_edited(&before, d, reached, |id| top_copies.contains(&id)));
|
||||
Ok(())
|
||||
})?;
|
||||
// Rows at or above each copy move up by one (by the block, for copies placed at `to`).
|
||||
@@ -1407,7 +1546,7 @@ fn show_all_hidden(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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::<Vec<_>>() }))
|
||||
@@ -1431,6 +1570,7 @@ fn move_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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, &with_reference(design_reference(s, p, C)?, &ids)) {
|
||||
return Err(bad(C, "rows of objects whose appearances differ can't be reordered together"));
|
||||
@@ -1457,7 +1597,7 @@ fn move_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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, None);
|
||||
Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels))
|
||||
})?;
|
||||
// The moved row stays the active one; the rows it passed shift by one.
|
||||
@@ -1503,7 +1643,7 @@ fn move_items(s: &mut Session, p: &Value, ids: &[NodeId], to: usize) -> Result<V
|
||||
}
|
||||
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, None);
|
||||
Ok(count_changed(d, &before, ids) + usize::from(kept || painted || labels))
|
||||
})?;
|
||||
let m = idx.len();
|
||||
@@ -1536,8 +1676,8 @@ fn move_contents(s: &mut Session, ids: &[NodeId], to: usize) -> Result<Value> {
|
||||
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 = super::graph::capture_label_rows(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 }))
|
||||
@@ -1804,15 +1944,45 @@ fn copy_from(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let object = super::graph::capture_series_object_opacity(d, &objects);
|
||||
// Graph labels keep their new rows, characters and paragraphs per kind of label.
|
||||
// On type, only `append` adds rows and a transparency pick changes the object's opacity and blend mode; the other
|
||||
// attributes go to the characters.
|
||||
// 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. `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 = if append {
|
||||
super::graph::capture_label_rows(d, &targets)
|
||||
super::graph::capture_label_kind_rows(d, &targets, paints, transparency)
|
||||
} else {
|
||||
attrs.appearance.transparency && super::graph::capture_label_object_opacity(d, &targets)
|
||||
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)?;
|
||||
Ok(count_changed(d, &before, &targets) + usize::from(kept || painted || object || rows || text))
|
||||
// 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. 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, _) => {
|
||||
// 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))
|
||||
})?;
|
||||
Ok(finish(s, &targets))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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 (none when nothing changes). 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 (none when nothing changes). 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)
|
||||
),
|
||||
@@ -533,7 +533,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)
|
||||
}
|
||||
|
||||
@@ -803,8 +803,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() {
|
||||
@@ -823,7 +823,10 @@ fn map_graph_colors(g: &mut vectorcraft_doc::GraphSpec, f: &mut dyn FnMut(&Color
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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), aligned?: bool (as paint.editGradient), 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), aligned?: bool (as paint.editGradient), 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
|
||||
),
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), 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), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), 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<CommandSpec> {
|
||||
"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), aligned?: bool (as paint.editGradient), 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 relative to the path's box when it is on the topmost visible fill or stroke, and every path of the series takes it at the same place on its own box (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), aligned?: bool (as paint.editGradient), 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 relative to the path's box when it is on the topmost visible fill or stroke, and every path of the series takes it at the same place on its own box (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
|
||||
),
|
||||
|
||||
@@ -48,9 +48,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_series_object_opacity, capture_series_opacity, capture_series_top_paints, follow_wedge_shades,
|
||||
is_design_art, label_object_opacity_differs, labels_in, paint_targets, plain_labels, series_group_marks, series_group_marks_where,
|
||||
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_row_writes, capture_line_rows,
|
||||
capture_series_object_opacity, capture_series_opacity, capture_series_top_paints, follow_wedge_shades, 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, wedge_shades,
|
||||
};
|
||||
|
||||
|
||||
@@ -543,7 +543,7 @@ impl<'a> Plot<'a> {
|
||||
}
|
||||
for v in tick_values(lo, hi, step).into_iter().skip(1) {
|
||||
let ring: Vec<Point> = (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);
|
||||
|
||||
@@ -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<vectorcraft_doc::LabelRows> {
|
||||
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<Node> {
|
||||
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<Node> {
|
||||
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<Node> {
|
||||
let t = self.text_object(role, at, s, justify);
|
||||
|
||||
@@ -4,7 +4,7 @@ use vectorcraft_geom::Shape;
|
||||
|
||||
use super::axis::radar_axis;
|
||||
use super::generate::is_dark;
|
||||
use super::labels::{Role, filled_lines_on, label_para, label_size, label_style};
|
||||
use super::labels::{Line, Role, filled_lines_on, kept_line_rows, label_para, label_size, label_style, line_slot};
|
||||
use super::{
|
||||
Affine, Arc, CharStyle, Color, Document, GraphKind, GraphSpec, HashMap, Node, NodeId, NodeKind, Paint, Rect, Result, Session, Value, bad,
|
||||
refresh_bounds,
|
||||
@@ -155,13 +155,32 @@ pub(crate) fn paint_targets(doc: &Document, ids: &[NodeId]) -> Vec<NodeId> {
|
||||
}
|
||||
|
||||
/// `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<NodeId> {
|
||||
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<Vec<NodeId>> {
|
||||
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<NodeId> {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut out = Vec::new();
|
||||
@@ -172,6 +191,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),
|
||||
}
|
||||
}
|
||||
@@ -1185,21 +1208,34 @@ pub(crate) fn capture_label_anti_alias(doc: &mut Document, ids: &[NodeId], metho
|
||||
/// Keep a formatting change made to graph labels `ids` (Character or Appearance, on the whole graph or on labels
|
||||
/// picked with Group Selection) for every label of their kind: `change` is applied to the kind's kept style (or
|
||||
/// the default one), so the labels look the same when the graph is drawn again. Called inside the same edit, so
|
||||
/// they undo together. Returns whether a kept style changed.
|
||||
/// they undo together. A kind that keeps no style and that `change` leaves at the default style keeps none, unless
|
||||
/// `change` sets the legend fill. Returns whether a kept style changed.
|
||||
pub(crate) fn capture_label_styles(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);
|
||||
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.
|
||||
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 mut style = label_style(&spec.label_styles, role);
|
||||
let was = label_style(&spec.label_styles, role);
|
||||
let mut style = was.clone();
|
||||
// The kept fill can already be the one `change` sets (black, the default): `change` sets the fill when it gives one
|
||||
// of two different fills something else.
|
||||
let sets_fill = role == Role::Legend
|
||||
@@ -1215,6 +1251,9 @@ fn store_label_style(doc: &mut Document, graph: NodeId, role: Role, change: &dyn
|
||||
Role::Category => &mut styles.categories,
|
||||
Role::Legend => &mut styles.legend,
|
||||
};
|
||||
if unless_default && slot.is_none() && style == was && !(sets_fill && !styles.legend_fill_set) {
|
||||
return false;
|
||||
}
|
||||
let mut changed = slot.as_ref() != Some(&style);
|
||||
*slot = Some(style);
|
||||
if sets_fill && !styles.legend_fill_set {
|
||||
@@ -1277,37 +1316,356 @@ pub(crate) fn label_rows(n: &Node) -> Option<vectorcraft_doc::LabelRows> {
|
||||
(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<Line> {
|
||||
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
|
||||
}
|
||||
|
||||
/// 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,
|
||||
/// 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<u8>, 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.
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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<vectorcraft_doc::LabelRows> {
|
||||
let shown = label_rows(n).unwrap_or_default();
|
||||
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), 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, 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;
|
||||
*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, 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
|
||||
/// 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
|
||||
}
|
||||
|
||||
/// 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 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<NodeId> = 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 = |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());
|
||||
let k = &mut rows.paint;
|
||||
if on_fill.paint {
|
||||
k.fill = shown.fill;
|
||||
}
|
||||
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;
|
||||
*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<T: PartialEq + Clone>(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 [`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<vectorcraft_doc::LabelRows>)> = 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, 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())
|
||||
})
|
||||
}
|
||||
|
||||
/// 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)
|
||||
store_label_rows(doc, ids, Keep::All)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
store_label_rows(doc, ids, Keep::Object)
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// 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, 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 = false;
|
||||
/// [`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) {
|
||||
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 {
|
||||
@@ -1315,26 +1673,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<vectorcraft_doc::LabelRows>,
|
||||
rows: Option<vectorcraft_doc::LabelRows>,
|
||||
object_only: bool,
|
||||
keep: Keep,
|
||||
) -> Option<vectorcraft_doc::LabelRows> {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -1454,23 +1809,38 @@ pub(super) fn picks_legend_fill(g: &GraphSpec) -> bool {
|
||||
g.picks_legend_fill()
|
||||
}
|
||||
|
||||
/// 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<NodeId> {
|
||||
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();
|
||||
@@ -1482,10 +1852,14 @@ pub(crate) fn labels_in(doc: &Document, roots: &[NodeId]) -> Vec<NodeId> {
|
||||
/// 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.
|
||||
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 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);
|
||||
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<NodeId> = ids.iter().copied().filter(|id| labels.contains_key(id)).collect();
|
||||
@@ -1510,18 +1884,25 @@ 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);
|
||||
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
|
||||
}
|
||||
|
||||
@@ -7762,6 +7762,936 @@ 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<vectorcraft_doc::Node> {
|
||||
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<u64> = 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");
|
||||
}
|
||||
|
||||
/// 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() {
|
||||
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<String> = 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:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 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:?}");
|
||||
}
|
||||
|
||||
/// 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:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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::<Vec<_>>());
|
||||
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]
|
||||
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]
|
||||
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<String> =
|
||||
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() {
|
||||
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<String> = 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");
|
||||
}
|
||||
|
||||
/// 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<vectorcraft_doc::LabelRows>| 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<Paint> = 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<vectorcraft_doc::Appearance> {
|
||||
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");
|
||||
}
|
||||
|
||||
/// 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 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, 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 fill = json!({"color": false, "transparency": false, "overprint": false});
|
||||
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
|
||||
/// 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
|
||||
/// 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<u32>)> {
|
||||
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<vectorcraft_doc::LabelRows>| 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:?}");
|
||||
}
|
||||
|
||||
/// 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:?}");
|
||||
}
|
||||
|
||||
/// A stroke paint written to an axis line that already shows it is kept for every axis line, in place of the stroke the
|
||||
/// kind keeps from another line.
|
||||
#[test]
|
||||
fn a_stroke_written_to_an_axis_line_that_shows_it_is_kept() {
|
||||
let cases = [("paint.setStroke", json!({"color": "#000000"})), ("addon.color.fillToStroke", json!({}))];
|
||||
every_case(cases, |(cmd, params)| {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
|
||||
let id = graph(&mut s, "column");
|
||||
let lines = line_nodes(&s, id);
|
||||
s.execute("paint.setFill", &json!({"ids": [lines[1].id.0], "color": "#000000"})).unwrap();
|
||||
s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "color": "#ff0000"})).unwrap();
|
||||
assert_eq!(line_look(&line_nodes(&s, id)[1]).0, "#000000", "{cmd}: the other lines show black until the graph is drawn again");
|
||||
let mut p = params.clone();
|
||||
p["ids"] = json!([lines[1].id.0]);
|
||||
s.execute(cmd, &p).unwrap();
|
||||
let looks = redrawn_line_looks(&mut s, id);
|
||||
assert!(looks.iter().all(|l| l.0 == "#000000"), "{cmd}: {looks:?}");
|
||||
});
|
||||
}
|
||||
|
||||
/// A 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<f32> = 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<f32> = 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();
|
||||
|
||||
@@ -251,7 +251,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, and on a series group the group's opacity, blend mode, isolate, knockout and knockoutShape (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, and on a series group the group's opacity, blend mode, isolate, knockout and knockoutShape (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
|
||||
),
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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), 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), 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 color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); 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), 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), 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 color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); 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<CommandSpec> {
|
||||
"Swap Fill and Stroke",
|
||||
[],
|
||||
Some("Shift+X"),
|
||||
"{ids?|id?} swap the fill and stroke of the selection (type too) and of the defaults. On a path directly in a graph series, the graph also stores the swapped paints and the stroke weight, and on a graph label the swapped paints of its characters for every label of its kind (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<CommandSpec> {
|
||||
"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<CommandSpec> {
|
||||
"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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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; when every target is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso, those points take the opacity themselves). 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, and on a series group without an item, the group's own opacity, blend mode, isolate, knockout and knockoutShape (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; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md)} 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; when every target is a gradient mesh with points picked by the Mesh tool, Direct Selection or the Lasso, those points take the opacity themselves). 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, and on a series group without an item, the group's own opacity, blend mode, isolate, knockout and knockoutShape (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
|
||||
),
|
||||
@@ -96,7 +96,7 @@ pub fn proxy_specs() -> Vec<CommandSpec> {
|
||||
"Invert",
|
||||
[],
|
||||
None,
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path) 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); no undo step when no color changes → {changed}",
|
||||
"{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, aligned?: bool (as paint.setFill), target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path) 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); no undo step when no color changes → {changed}",
|
||||
has_doc,
|
||||
|s, p| proxy_recolor(s, p, "paint.invert", "Invert", &super::colorcmds::invert)
|
||||
),
|
||||
@@ -655,6 +655,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);
|
||||
@@ -665,7 +667,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.
|
||||
@@ -1011,7 +1013,7 @@ fn swap(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
// The swap writes the paint of the topmost fill and stroke, not their opacity.
|
||||
let kept = super::appearance::capture_series_writes(&before, d, &ids, (true, true), (false, false), true, false);
|
||||
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))
|
||||
})?;
|
||||
}
|
||||
@@ -1047,8 +1049,15 @@ fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
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 of a kind it reached, and the default fill and stroke rows
|
||||
// for every line of a kind it reached, also when one already showed them; the object opacity a line kind keeps
|
||||
// stays.
|
||||
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_fill_stroke_rows(d, &ids);
|
||||
Ok(super::appearance::count_changed(d, &before, &ids) + usize::from(kept || labels || lines))
|
||||
})?;
|
||||
}
|
||||
super::newart::reset(s);
|
||||
@@ -1269,6 +1278,9 @@ fn transparency(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
// 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, C)? };
|
||||
if !editing_mask {
|
||||
super::appearance::check_part_rows(s, p, aligned || !explicit, C)?;
|
||||
}
|
||||
// The art of a graph design whose stack an explicit aligned item is a row of goes first: appearance.setItem leaves
|
||||
// it as it is and matches the other objects' rows against it.
|
||||
let of = if editing_mask || !explicit { None } else { super::appearance::design_reference(s, p, C)? };
|
||||
|
||||
@@ -34,7 +34,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Recolor Artwork",
|
||||
["Edit", "Edit Colors"],
|
||||
None,
|
||||
"{map: rows [{from: [colour keys (recolor.colors) or \"#rrggbb\" (every colour shown as that hex); may be empty: an empty row recolours nothing, adds no library swatch and gives `group` no colour], 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 and empty 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 (none when nothing changes). 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); may be empty: an empty row recolours nothing, adds no library swatch and gives `group` no colour], 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 and empty 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 (none when nothing changes). 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
|
||||
),
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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 → {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
|
||||
),
|
||||
@@ -31,7 +31,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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)
|
||||
),
|
||||
@@ -307,8 +307,10 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
};
|
||||
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
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, and the art of a graph design in a series, which is left out: 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, 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 (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
|
||||
),
|
||||
@@ -40,7 +40,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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, unless it is the art of a graph design in a series. 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, unless it is the art of a graph design in a series. Names are made unique → {name}",
|
||||
has_doc,
|
||||
style_new
|
||||
),
|
||||
@@ -68,7 +68,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"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. The art of a graph design in a series keeps its look and is unlinked, as the source or as a linked object. 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; a graph's Axes or Legend group: its topmost line or label); the objects still linked to it update, and that object becomes linked. The art of a graph design in a series keeps its look and is unlinked, as the source or as a linked object. 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<CommandSpec> {
|
||||
"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
|
||||
),
|
||||
@@ -364,6 +364,9 @@ fn style_apply(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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,9 +376,9 @@ fn style_apply(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
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.
|
||||
super::graph::capture_label_rows(d, &ids);
|
||||
}
|
||||
// A label keeps its new rows for its kind of label.
|
||||
super::graph::capture_label_rows(d, &ids);
|
||||
Ok(())
|
||||
})?;
|
||||
ok()
|
||||
|
||||
@@ -1038,7 +1038,17 @@ fn set_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// 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;
|
||||
@@ -1079,7 +1089,13 @@ fn set_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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))
|
||||
})?;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<Color> {
|
||||
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<Color> = 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]]}));
|
||||
|
||||
+64
-11
@@ -835,6 +835,20 @@ 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 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. 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.
|
||||
|
||||
`transparency.set` and `object.setProps` with an opacity, blend mode, isolation, knockout or knockout shape for the
|
||||
object, given a series group's id or the selected series group, set them on the group itself, and the graph stores them
|
||||
for that series. The series group has them again when the graph is drawn again, and they apply to the group as a whole
|
||||
@@ -843,10 +857,12 @@ in addition to each path's own opacity and blend mode. `addon.arrange.randomizeO
|
||||
what they change on the group the same way. Each of the commands above that clears the group's own opacity, blend mode, isolation
|
||||
and knockout also removes what the graph stores for it.
|
||||
|
||||
The other commands given a series group's id edit the group itself, and the graph does not store what they set on it:
|
||||
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 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: 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. `transparency.set` and
|
||||
`object.setProps` with an opacity or blend mode for the object, given an Axes or Legend group, edit the group itself the
|
||||
same way. `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.
|
||||
|
||||
When a graph is drawn again (a change to its data, its type, or its column or marker designs), it draws the art of a
|
||||
column or marker design in a series again from the design, and an edit made to that art is lost. The art is any object
|
||||
@@ -909,9 +925,11 @@ 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, a fill a command sets on the legend labels is drawn on every wedge, black included, until
|
||||
that command is undone; a size, font or stroke change does not set one. Before that, their 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.
|
||||
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. `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 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
|
||||
@@ -935,11 +953,14 @@ 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, 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. 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 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.
|
||||
`appearance.copyFrom` onto the whole text of a label also stores the character attributes it applies and, from type,
|
||||
@@ -947,6 +968,38 @@ 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, 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.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. `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. `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
|
||||
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
|
||||
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
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user