From 92b3b10e7bdc30d5c6253e8e9a7440791cb54858 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 12:27:19 -0800 Subject: [PATCH] Graphs: legend swatches have the stroke of their series' marks A default legend swatch of a stacked column, stacked bar, area or pie series now has the thin white stroke the series' marks have, beside the plot or across the top. Before, the swatch had no stroke, so the series group painted with two strokes and a drawn stacked column or area graph was saved to .ai as plain art with a warning. Both now open again as live graphs. Stacked bar graphs are still written as art: the .ai reader has no type for them. --- crates/engine/src/cmd/graph/generate.rs | 24 ++++-- crates/engine/src/cmd/graph/tests.rs | 97 ++++++++++++++++++++++++- docs/file-format-parity.md | 4 +- docs/target-app-parity.md | 1 + 4 files changed, 119 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/graph/generate.rs b/crates/engine/src/cmd/graph/generate.rs index f589ed9ae5..59455ca4f3 100644 --- a/crates/engine/src/cmd/graph/generate.rs +++ b/crates/engine/src/cmd/graph/generate.rs @@ -393,6 +393,16 @@ impl<'a> Plot<'a> { series_marks(self.g, i, series_fill, stroke, width) } + /// The stroke paint and width series `s`'s filled marks and its legend swatch get when the series keeps no stroke + /// of its own: a white line between stacked segments, area bands and pie wedges, none on other marks. + fn mark_stroke(&self, s: usize) -> (Paint, f64) { + match self.kind(s) { + GraphKind::StackedColumn | GraphKind::StackedBar | GraphKind::Area => (Paint::solid(Color::WHITE), 0.25), + GraphKind::Pie => (Paint::solid(Color::WHITE), 0.5), + _ => (Paint::None, 0.0), + } + } + fn series_label(&self, i: usize) -> String { self.g.series.get(i).cloned().unwrap_or_default() } @@ -471,7 +481,8 @@ impl<'a> Plot<'a> { } let sweep = v / total * std::f64::consts::TAU; let bp = wedge_path(ring, a0, sweep); - let (fill, stroke, sw) = self.mark(s, true, Paint::solid(Color::WHITE), 0.5); + let (stroke, width) = self.mark_stroke(s); + let (fill, stroke, sw) = self.mark(s, true, stroke, width); let dark = is_dark(&fill); let n = self.b.path(PathData::from_bezpath(&bp), fill, stroke, sw); self.push_shadowed(s, n); @@ -887,7 +898,8 @@ impl<'a> Plot<'a> { let Some(base) = (if v >= 0.0 { pos.get_mut(ax) } else { neg.get_mut(ax) }) else { continue }; let (v0, v1) = (geo.vpos(ax, *base), geo.vpos(ax, *base + v)); *base += v; - let paint = self.mark(s, true, Paint::solid(Color::WHITE), 0.25); + let (stroke, width) = self.mark_stroke(s); + let paint = self.mark(s, true, stroke, width); let rect = bar_rect(geo.horizontal, a, w, v0, v1); // A segment of 0 has no area to shade. let n = self.bar_node(Bar { s, rect, value: v, down: v1 < v0, per_unit: geo.per_unit(ax) }, paint, v != 0.0); @@ -907,7 +919,8 @@ impl<'a> Plot<'a> { let at = |c: usize, v: &[f64]| Point::new(geo.cat_mid(c), geo.vpos(a, v.get(c).copied().unwrap_or(0.0))); let mut pts: Vec = (0..ncat).map(|c| at(c, &above)).collect(); pts.extend((0..ncat).rev().map(|c| at(c, below))); - let (fill, stroke, w) = self.mark(s, true, Paint::solid(Color::WHITE), 0.25); + let (stroke, width) = self.mark_stroke(s); + let (fill, stroke, w) = self.mark(s, true, stroke, width); let n = self.b.path(polyline(&pts, true), fill, stroke, w); self.push_series(s, n); *below = above; @@ -951,10 +964,11 @@ impl<'a> Plot<'a> { } /// The swatch of series `s` at `(x, y)`: series drawn with markers show their marker design in the legend, and - /// series drawn with a column design that design. + /// series drawn with a column design that design. A default swatch has the stroke of its series' marks. fn legend_swatch(&mut self, s: usize, (x, y): (f64, f64)) { let marked = matches!(self.g.kind, GraphKind::Scatter | GraphKind::Radar) || self.kind(s) == GraphKind::Line; - let paint = self.mark(s, true, Paint::None, 0.0); + let (stroke, width) = self.mark_stroke(s); + let paint = self.mark(s, true, stroke, width); let column = nth(self.column_looks, s).filter(|_| self.columnar(s)); let swatch = self.b.swatch(column, nth(&self.designs, s).filter(|_| marked), Rect::new(x, y, x + 8.0, y + 8.0), paint); self.push_series(s, swatch); diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index c533cb5e4e..4914eaaa91 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -8192,7 +8192,102 @@ fn a_drawn_graph_saved_as_ai_opens_as_a_graph_unless_the_save_warns() { } } } - assert!(live.contains(&"column v7.ai".to_string()) && live.contains(&"column pdf.ai".to_string()), "{live:?}"); + for ty in ["column", "stackedColumn", "area"] { + assert!(live.contains(&format!("{ty} v7.ai")) && live.contains(&format!("{ty} pdf.ai")), "{ty}: {live:?}"); + } +} + +/// A default legend swatch has the stroke paint and weight of its series' marks, beside the plot or across the top: the +/// thin white line of stacked columns and bars, areas and pie wedges, and none on columns and bars. A stroke color kept +/// on the series, with or without a weight of its own, is on the swatch too. +#[test] +fn a_legend_swatch_has_the_stroke_of_its_series_marks() { + let white = |w: f64| (Paint::solid(vectorcraft_color::Color::WHITE), w); + let cases = [ + ("stackedColumn", white(0.25)), + ("stackedBar", white(0.25)), + ("area", white(0.25)), + ("pie", white(0.5)), + ("column", (Paint::None, 0.0)), + ("bar", (Paint::None, 0.0)), + ]; + for (ty, stroke) in cases { + for across_top in [false, true] { + 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\nQ3,1,6"; + let id = NodeId( + s.execute("graph.create", &json!({"type": ty, "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv})).unwrap()["id"] + .as_u64() + .unwrap(), + ); + s.execute("graph.setType", &json!({"id": id.0, "legendAcrossTop": across_top})).unwrap(); + for i in 0..2 { + let marks = marks_of(&s, id, i); + assert!(marks.len() > 1, "{ty} {i}: marks and a swatch"); + assert!(marks.iter().all(|m| (m.1.clone(), m.2) == stroke), "{ty} across top {across_top}, series {i}: {marks:?}"); + } + // A stroke color kept on series 0 without a weight keeps the default weight, then with one. + let bar = series(s.doc().unwrap().doc.node(id).unwrap(), 0).children().unwrap()[0].clone(); + let row = bar.appearance.items.iter().rposition(|it| !it.is_fill()); + let Some(row) = row else { continue }; + s.execute("appearance.setItem", &json!({"ids": [bar.id.0], "index": row, "color": "#ff0000"})).unwrap(); + s.execute("graph.setData", &json!({"id": id.0, "csv": csv})).unwrap(); + let marks = marks_of(&s, id, 0); + assert!(marks.iter().all(|m| *m == marks[0]) && marks[0].1 != stroke.0, "{ty} across top {across_top}, red: {marks:?}"); + let bar = series(s.doc().unwrap().doc.node(id).unwrap(), 0).children().unwrap()[0].id; + s.execute("appearance.setItem", &json!({"ids": [bar.0], "index": row, "weight": 3})).unwrap(); + s.execute("graph.setData", &json!({"id": id.0, "csv": csv})).unwrap(); + let marks = marks_of(&s, id, 0); + assert!(marks.iter().all(|m| *m == marks[0]) && marks[0].2 == 3.0, "{ty} across top {across_top}, 3 pt: {marks:?}"); + } + } +} + +/// A stacked column graph the graph tools draw, saved as `.ai` in either form, opens again as the same graph without a +/// warning, and its data can be edited there. +#[test] +fn a_drawn_stacked_column_graph_saved_as_ai_opens_as_a_graph_that_takes_new_data() { + let dir = vectorcraft_testkit::temp_dir("graph-ai-stacked"); + 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\nQ3,1,6"; + let id = s.execute("graph.create", &json!({"type": "stackedColumn", "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv})).unwrap()["id"] + .as_u64() + .unwrap(); + let written = spec(&s, NodeId(id)); + for (name, version) in [("v7.ai", Some("7")), ("pdf.ai", None)] { + let path = dir.join(name); + let mut p = json!({"path": path, "format": "ai"}); + if let Some(v) = version { + p["aiVersion"] = json!(v); + } + let r = s.execute("file.saveAs", &p).unwrap(); + let notes = r["warnings"].as_array().cloned().unwrap_or_default(); + assert!(!notes.iter().any(|w| w.as_str().is_some_and(|w| w.starts_with("graphs are written as their art"))), "{name}: {r}"); + let mut again = Session::new(); + again.execute("document.open", &json!({"path": path})).unwrap(); + let mut found = vec![]; + again.doc().unwrap().doc.walk(|n| { + if n.extras().graph.is_some() { + found.push(n.id); + } + }); + assert_eq!(found.len(), 1, "{name}"); + let g = spec(&again, found[0]); + assert_eq!((g.kind, g.cells()), (written.kind, written.cells()), "{name}"); + assert_eq!((g.series.as_slice(), g.categories.as_slice()), (&written.series[..], &written.categories[..]), "{name}"); + again.execute("select.set", &json!({"ids": [found[0].0]})).unwrap(); + again.execute("graph.setData", &json!({"id": found[0].0, "csv": ",2024,2025\nQ1,8,1\nQ2,2,7"})).unwrap(); + let after = spec(&again, found[0]); + assert_eq!((after.kind, after.rows.as_slice()), (written.kind, &[vec![8.0, 1.0], vec![2.0, 7.0]][..]), "{name}"); + // Each series keeps one fill and the thin white stroke on its marks and its swatch. + for i in 0..2 { + let marks = marks_of(&again, found[0], i); + let white = Paint::solid(vectorcraft_color::Color::WHITE); + assert!(marks.len() > 1 && marks.iter().all(|m| *m == marks[0] && (&m.1, m.2) == (&white, 0.25)), "{name} series {i}: {marks:?}"); + } + } } /// A graph opened from a `.ai` keeps the bounds of its art without type, so moving one of its labels on its own diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 7a73bdc4c1..85956bb9f4 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -249,7 +249,9 @@ private editing data. VectorCraft: paint; Graph Data then edits it. Other graphs (pie and scatter graphs, graphs with designs or customizations, records of later versions) come in as plain groups, paths and type, with a note. Saving a graph to `.ai`, in either form, writes these records around its art when the reader above reads them back as the same graph, - so the file opens again with its data and settings; any other graph is written as its art, with a warning. + so the file opens again with its data and settings; any other graph is written as its art, with a warning. A + legend swatch the graph tools draw has the stroke of its series' marks, so a drawn stacked column or area graph + is written with its records. Legacy `.ai` patterns in the version 7 form (a list of `@` and `&` layers, `_ &` for the tile's background) open as pattern swatches, with a fill's offset, scale, rotation, reflection and shear applied before its matrix. Legacy `.ai` linked images in diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 10d476361a..e4c74599de 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -629,6 +629,7 @@ since 2026-10-01. - **`.ai`/EPS graphic styles that paint with a named gradient:** a graphic style library's style (or a file's listed style) whose fill, or the fill or stroke of a style of one paint, paints with one of the file's gradients by name loads with that gradient at the style's angle, fitted to the bounds of each object it is applied to (VectorCraft's own placement; the style stores only the gradient's name and angle). A style naming a gradient the file doesn't define, or painting with a pattern, is still left out. Evidence: `fileio::tests_aiimport::graphic_styles_in_a_ai_library_that_paint_with_a_named_gradient_load_with_it`, `style::tests::a_style_of_one_paint_reads_as_the_fill_and_stroke_its_xd_turns_on`. Scores unchanged. - **`.ai`/EPS type laid out closer to the file's page (#6137):** type from the text document keeps auto leading as auto, each line taking the paragraph's Auto Leading share (key 7) of the largest type on it ([Line and character spacing](https://helpx.adobe.com/illustrator/using/line-character-spacing.html)); the paragraph's hyphenation options (keys 10 to 15) are read; area type of one frame whose last lines the file sets, but which don't fit here, may get a frame taller from its bottom, by its lines' deepest descent plus 0.05 pt and only when that shows more of those lines and no more than the file has (`vectorcraft_text::fit_source_lines`), with a warning when it does: the frame can stay as it is, or show only some of them; and a line a soft return ends is justified as a wrapped line is, a paragraph's last line keeping its alignment. Evidence: `ate::tests::auto_leading_follows_the_size_of_each_line`, `ate::tests::a_paragraph_keeps_its_auto_leading`, `ate::tests::a_paragraph_keeps_its_hyphenation_options`, `ate::tests::the_last_lines_the_file_sets_in_its_frame_show`, `tests::fit_source_lines_keeps_the_last_lines_the_source_sets`, `tests::typo::soft_return_in_justified_text_spreads_like_a_wrapped_line`. Limits: frames grow only for area type of one frame, horizontal, by its lines' deepest descent plus 0.05 pt; type in a font that isn't installed, and hyphenation in a language that isn't imported, still lay out differently. Scores unchanged. - **Graphs saved to `.ai` keep their data and settings:** a grouped column, stacked column, line or area graph is written to a `.ai` file, in either form, with the records the `.ai` reader reads (`crates/eps/src/import/ai/read/graph.rs`, #7311): `%_Gs`, its plot, type, settings, axes and table, its series' groups each tagged `Go`, and `%_GS` ([the specification](https://13thmonkey.org/documentation/fonts/AI7FileFormat.pdf), §17 and appendix A). The file opens again with the same live graph. A graph with settings the reader doesn't keep, graph designs, label formatting, more than 10,000 categories or 256 series, or art the reader doesn't attach a graph to is written as its art, with a warning. `crates/eps/src/legacy_ai/tests.rs` and `crates/eps/src/ai_editing/tests.rs` write and read back each kind of graph; `a_drawn_graph_saved_as_ai_opens_as_a_graph_unless_the_save_warns` checks every graph type the graph tools draw. Scores unchanged. +- **Graph legend swatches have their series' stroke:** a default legend swatch of a stacked column, stacked bar, area or pie series has the thin white stroke of the series' marks (VectorCraft's own rule), beside the plot or across the top, and a stroke kept on the series is on the swatch too. Each series' group then paints with one stroke, so a stacked column or area graph the graph tools draw is saved to `.ai` with its data and settings and opens again as a live graph; a stacked bar graph is still written as its art, as the reader has no type for it. Evidence: `cmd::graph::tests::a_legend_swatch_has_the_stroke_of_its_series_marks`, `cmd::graph::tests::a_drawn_stacked_column_graph_saved_as_ai_opens_as_a_graph_that_takes_new_data`, `cmd::graph::tests::a_drawn_graph_saved_as_ai_opens_as_a_graph_unless_the_save_warns`. Scores unchanged. - **Selected Grid Repeat handles (#2691):** `tools/src/repeat_grid.rs` tests place the handles outside the grid at zoom 0.5, 1 and 4, preview rows, columns and spacing, leave no undo step for a drag that ends where it began, and give bounding-box handles priority; a headless canvas regression drags the row handle two tiles down in a zoomed view (3 → 5 rows, the source unchanged, one Undo back) and the column-spacing slider. Scores and hours unchanged. - **Selected Mirror Repeat handles:** a headless canvas regression creates the default mirror repeat and drags its Top bounding-box handle where the axis crosses it; the repeat grows vertically while its width stays fixed. Existing mirror-axis checks cover center movement and end-handle hit priority. The focused UI mirror tests pass. Scores and hours unchanged. - **Transform effect options (#885):** Effect › Distort & Transform › Transform… has visible Transform Objects, Transform Patterns and Scale Strokes & Effects checkboxes (`distort.transform` params `objects`, `patterns`, `strokes`; files without them draw as before). With Transform Objects off the geometry stays and makes no copies; Scale Strokes & Effects scales stroke weights, dashes and the fills' and strokes' effect distances by the mean scale, and Transform Patterns moves pattern tiles, each copy `k` by the transformation `k` times. Such objects draw, export and expand through the same per-copy art, so the canvas and Expand Appearance agree (engine `tests_transformfx`, effects `tests_transformfx`, the dialog test). A Transform effect in a fill's or stroke's own effects applies the same options to that fill or stroke: its weight and dashes and its pattern follow the transformation, and with copies each copy is an object of its own; the canvas, export, Expand Appearance and Use Preview Bounds use the same art (effects `tests_transformfx`). The effects listed after it in that fill's or stroke's list keep their own distances and apply to the transformed art and to each copy, as an object's later effects do after the object's Transform effect: a Drop Shadow after it keeps its offset, an Offset Path after it offsets by its own distance, and an SVG filter after it keeps its scale and the origin of its user space. With Transform Objects off, the effects before it keep their distances too. Before, Scale Strokes & Effects scaled a fill's or stroke's later effects by the mean scale, so existing documents with such effects draw differently. Effects apply in the order they are listed ([Appearance attributes](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-graphic-styles/appearance-attributes-in-illustrator.html)); how the two options treat the effects after a fill's or stroke's own Transform effect is VectorCraft's own rule, following that order (effects `tests::rasterfollow::a_fills_own_transform_leaves_the_shadow_after_it`, `tests::rasterfollow::a_fills_own_transform_leaves_the_offset_after_it`, `tests::rasterfollow::a_fills_own_transform_leaves_the_svg_filter_after_it`, `tests::transformfx::a_fills_own_transform_with_scale_strokes_and_effects_leaves_its_later_effects`; engine `plugins::a_transform_after_a_painted_fill_effect_leaves_the_later_shadow_on_every_paint`). Public reference: [Scale objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/scale-objects.html), [How to apply effects](https://helpx.adobe.com/illustrator/using/effects.html), [Distort and transform effects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/distort-and-transform-effects-in-illustrator.html). Scores and hours unchanged.