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 d171224d14..3b18820f4b 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -8449,7 +8449,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 4278489b61..b5ab18e9ae 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 f06935a307..b12d7d836a 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -635,6 +635,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. - **Graph section in the Properties panel:** with one graph selected, or series of one graph picked with Group Selection, the Properties panel shows a Graph section. Its Graph Type… button opens the dialog of Object › Graph › Type… ([Format pie graphs](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/format-pie-graphs.html)). Its Graph Data… button opens the dialog of Object › Graph › Data…; this button is VectorCraft's own. Column… shows when every series it would change draws columns or bars, and Marker… when every one draws lines, scatter points or radar lines; this is VectorCraft's own rule. Regression tests in `crates/ui-egui/src/panels/properties/tests.rs`. 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.