diff --git a/ROADMAP.md b/ROADMAP.md index 70fa2ce4..ba50a762 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -138,7 +138,7 @@ grade by behaviour against `plan/illustrator/`, not by whether a menu item exist - **Live Corners:** drag a live rectangle's corner widgets (Selection or Direct Selection) to round all corners, with a radius readout; with Direct Selection, select corner anchors to show and round just those corners (#381). Each corner keeps its own radius and kind (Round, Inverted Round, Chamfer): Alt-click a widget to cycle the kind, double-click it for the Corners dialog, and the Properties and Transform radius fields set the selected corners (`object.setLiveShape {corners, radius, kind}`). Corners stay circular when the rectangle is scaled unevenly or along its own sides when rotated (the radius keeps its size, or scales by the mean scale with Scale Corners on); only a shear distorts them. On a rectangle that isn't square every corner is the same circle: a radius past half the shorter side stops there for all of them, the widgets sit on the corners as drawn and turn the edited corners red at that limit, CSS export writes the drawn radii, and rectangles saved stretched by older versions get circular corners when their corners are next set (#442). Live Corners work on any path's corners too, as on a rectangle's (#511): a star's, a live polygon's (which also shows them to the Selection tool, has a Corner Radius field in the Properties and Transform panels and keeps its radius as its sides change) and a pen path's, wherever two straight sides meet at an anchor. Direct Selection shows the widgets of every corner, or of the corners holding selected anchors; each corner is a circle tangent to both sides, drawn no larger than takes its cut halfway along its shorter side; a path keeps its uncut outline so its corners stay editable, and the same command, dialog, angle preference and View › Hide Corner Widget apply. - **Pen:** Alt pressed in the middle of dragging out an anchor splits its handles and keeps the curve already shaped into it (only the outgoing handle follows the pointer); Space held while dragging out an anchor moves it, handles and all. A press on the first anchor of the path being drawn closes it whatever the drag then does: the drag shapes the closing curve (symmetric handles, Alt breaks them) and the release closes the path wherever it ends (#501). Clicking the last anchor of the path being drawn retracts its outgoing handle (convert cursor), and dragging from it pulls out a new one on its own. Auto Add/Delete: over a selected path, a click on a segment adds an anchor and a click on an anchor deletes it (add and delete cursors); Shift held, or Preferences › General › Disable Auto Add/Delete, starts a new path instead. Alt held over a handle end or an anchor of a selected path (the one being drawn too) works as the Anchor Point tool, with its convert cursor: dragging a handle moves it alone, clicking a smooth anchor makes it a corner, dragging an anchor pulls out new symmetric handles, dragging a segment reshapes it; drawing then goes on. Cmd (Ctrl) held drags with the selection tool chosen last, Direct Selection until one is (handles, anchors and segments of the path being drawn or another), and the Pen then goes on drawing its path while that stays selected; the pointer shows that tool's while Cmd is held. The same holds for agents (`pointer_gesture` with `mods.cmd`), as the borrowing now lives in the engine (#494). - **Path editing (#494):** the handles shown are the handles that drag: Direct Selection drags those of a path selected as a whole (as the Pen leaves it), the Anchor Point tool and Pen+Alt no longer grab handles that Show handles when multiple anchors are selected hides, a handle shorter than the tolerance leaves its anchor to be picked, and the anchor tools pick within Selection & Anchor Display › Tolerance. A dragged segment keeps a smooth anchor at either end smooth. With Direct Selection, the Pen, the Curvature and the anchor tools, a path selected as a whole shows all its anchors selected, and the Control bar and the Properties panel offer Convert (corner, smooth) for them too; Remove and Cut wait for anchors direct-selected (#504). A handle drag gathers its snap targets once per drag (it took 21 ms per pointer move on a 20,000-path document, now 1 ms; `vectorcraft-cli perf` measures handle and segment drags on a 5,000-anchor path). - - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Graph Design, Column and Marker artwork remain open. + - **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type. A series starts in greyscale; Group Selection's fill and stroke are kept separately on the graph and reapplied when its data, type or size changes, and through save, open and undo. Graph Type's Override Calculated Values (both `axisMin` and `axisMax`) uses exactly that value-axis range, split into the tick count (5 when automatic). Line graphs take Edge-to-Edge Lines (on by default, as before; off, the points sit at the centres of their categories), and radar graphs follow Mark Data Points and Connect Data Points. Graph Design, Column and Marker artwork remain open. - **Other:** Eyedropper, Gradient annotator, Artboard (Alt-drag duplicates an artboard, and its art with Move/Copy Artwork with Artboard on; Copy, Cut and Paste take the artboard with its art, Paste right of the last artboard, Paste in Place where it was, into this or another document, #446; Object › Artboards › Rearrange All Artboards lays them out in a grid by row or by column, in one row or one column, left to right or right to left, from the menu, the Artboards panel or Properties' Rearrange All, #681; Scale Artwork with Artboard, in the Control bar and Properties beside Move Artwork with Artboard, resizes the artboard proportionally with the art fully inside it and its guides, strokes and corners per the Scale preferences, #602), Measure, Type, Hand, Zoom, Rotate View. - **Editing type:** double-clicking type with a selection tool switches to the Type tool with the caret where it was clicked. - **Temporary tools:** Cmd with any other tool drags with the selection tool used last (Selection, Direct Selection or Group Selection). Held Space pans and Cmd+Space zooms (Cmd+Alt+Space out) whatever the tool. diff --git a/crates/doc/src/graph.rs b/crates/doc/src/graph.rs index 0ef760f9..41bfba12 100644 --- a/crates/doc/src/graph.rs +++ b/crates/doc/src/graph.rs @@ -103,9 +103,12 @@ pub struct GraphSpec { pub ticks: usize, pub axis_min: Option, pub axis_max: Option, - /// Line graphs: mark data points, connect them, fill (area-like) the lines. + /// Line, scatter and radar graphs: mark data points, connect them. pub mark_points: bool, pub connect_points: bool, + /// Line graphs: run the lines from edge to edge of the plot (on, as before the option existed); off, the points + /// sit at the centres of their categories, like the columns of a column graph. + pub edge_to_edge: bool, /// Bounds of the art when it was last generated (detects moves/scales of the graph group). #[serde(skip_serializing_if = "Option::is_none")] pub placed: Option, @@ -128,6 +131,7 @@ impl Default for GraphSpec { axis_max: None, mark_points: true, connect_points: true, + edge_to_edge: true, placed: None, } } diff --git a/crates/engine/src/cmd/graph.rs b/crates/engine/src/cmd/graph.rs index a65f94c9..7cf24cbc 100644 --- a/crates/engine/src/cmd/graph.rs +++ b/crates/engine/src/cmd/graph.rs @@ -41,7 +41,7 @@ pub fn specs() -> Vec { "Type…", ["Object", "Graph"], None, - "{id?, type?, columnWidth?: %, clusterWidth?: %, legend?: bool, markPoints?: bool, connectPoints?: bool, ticks?: n, axisMin?, axisMax?} change the graph type and options (axisMin and axisMax together override the calculated value axis: exactly that range in `ticks` divisions, 5 when 0); no options → the current ones", + "{id?, type?, columnWidth?: %, clusterWidth?: %, legend?: bool, markPoints?: bool, connectPoints?: bool, edgeToEdge?: bool (line graphs: true runs the lines across the whole plot, false puts the points at the centres of their categories), ticks?: n, axisMin?, axisMax?} change the graph type and options (axisMin and axisMax together override the calculated value axis: exactly that range in `ticks` divisions, 5 when 0); no options → the current ones", has_selection, set_type ), @@ -322,11 +322,15 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec> { b.out.push(ax); for (s, items) in series.iter_mut().enumerate() { let pts: Vec = (0..ncat).map(|c| at(c, val(c, s))).collect(); - let (fill, stroke, w) = mark(s, false, default_series_paint(s), 1.0); - items.push(b.path(polyline(&pts, true), fill, stroke, w)); - for p in pts { - let (fill, stroke, w) = mark(s, true, Paint::None, 0.0); - items.push(b.path(marker(p, 4.0), fill, stroke, w)); + if g.connect_points && pts.len() > 1 { + let (fill, stroke, w) = mark(s, false, default_series_paint(s), 1.0); + items.push(b.path(polyline(&pts, true), fill, stroke, w)); + } + if g.mark_points { + for p in pts { + let (fill, stroke, w) = mark(s, true, Paint::None, 0.0); + items.push(b.path(marker(p, 4.0), fill, stroke, w)); + } } } } @@ -384,7 +388,8 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec> { let span = if horizontal { r.height() } else { r.width() }; let cat_w = span / ncat as f64; let cat_start = |c: usize| if horizontal { r.y0 + c as f64 * cat_w } else { r.x0 + c as f64 * cat_w }; - let points_mode = matches!(g.kind, GraphKind::Line | GraphKind::Area); + // Area bands always span the plot; line graphs only with Edge-to-Edge Lines. + let points_mode = g.kind == GraphKind::Area || (g.kind == GraphKind::Line && g.edge_to_edge); let cat_mid = |c: usize| { if points_mode && ncat > 1 { r.x0 + r.width() * c as f64 / (ncat - 1) as f64 } else { cat_start(c) + cat_w / 2.0 } }; @@ -702,11 +707,11 @@ fn set_type(s: &mut Session, p: &Value) -> Result { const C: &str = "graph.setType"; let id = target(s, p, C)?; let mut spec = spec_of(s, id)?; - let keys = ["type", "columnWidth", "clusterWidth", "legend", "markPoints", "connectPoints", "ticks", "axisMin", "axisMax"]; + let keys = ["type", "columnWidth", "clusterWidth", "legend", "markPoints", "connectPoints", "edgeToEdge", "ticks", "axisMin", "axisMax"]; if !keys.iter().any(|k| p.get(*k).is_some()) { return Ok(json!({ "type": spec.kind.id(), "columnWidth": spec.column_width, "clusterWidth": spec.cluster_width, "legend": spec.legend, - "markPoints": spec.mark_points, "connectPoints": spec.connect_points, "ticks": spec.ticks, + "markPoints": spec.mark_points, "connectPoints": spec.connect_points, "edgeToEdge": spec.edge_to_edge, "ticks": spec.ticks, "axisMin": spec.axis_min, "axisMax": spec.axis_max, })); } @@ -718,6 +723,7 @@ fn set_type(s: &mut Session, p: &Value) -> Result { spec.legend = bool_or(p, "legend", spec.legend); spec.mark_points = bool_or(p, "markPoints", spec.mark_points); spec.connect_points = bool_or(p, "connectPoints", spec.connect_points); + spec.edge_to_edge = bool_or(p, "edgeToEdge", spec.edge_to_edge); spec.ticks = p.get("ticks").and_then(Value::as_u64).map_or(spec.ticks, |t| t.min(100) as usize); if let Some(v) = p.get("axisMin") { spec.axis_min = v.as_f64(); @@ -817,6 +823,50 @@ mod tests { assert!(matches!(n.kind, NodeKind::Group { .. })); } + /// The x of every marker of series `index`, left to right. + fn marker_xs(s: &Session, id: NodeId, index: u32) -> Vec { + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + let mut xs: Vec = series(&n, index) + .children() + .unwrap() + .iter() + .map(|c| c.geometric_bounds().unwrap()) + .filter(|b| (b.width() - 5.0).abs() < 1e-6) + .map(|b| b.center().x) + .collect(); + xs.sort_by(f64::total_cmp); + xs + } + + #[test] + fn edge_to_edge_lines_off_puts_line_points_at_category_centres() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + // 300 pt wide, three categories: edges at 100 and 400; centres at 150, 250, 350. + let id = graph(&mut s, "line"); + assert_eq!(marker_xs(&s, id, 0), vec![100.0, 250.0, 400.0]); + assert_eq!(s.execute("graph.setType", &json!({})).unwrap()["edgeToEdge"], json!(true)); + s.execute("graph.setType", &json!({"edgeToEdge": false})).unwrap(); + assert_eq!(marker_xs(&s, id, 0), vec![150.0, 250.0, 350.0]); + // A graph saved before the option existed keeps its edge-to-edge lines. + let old: GraphSpec = serde_json::from_value(json!({"kind": "line"})).unwrap(); + assert!(old.edge_to_edge); + } + + #[test] + fn radar_graphs_follow_mark_and_connect_data_points() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let id = graph(&mut s, "radar"); + let parts = |s: &Session| series(&s.doc().unwrap().doc.node(id).unwrap().clone(), 0).children().unwrap().len(); + // The ring, three markers and the legend swatch. + assert_eq!(parts(&s), 5); + s.execute("graph.setType", &json!({"markPoints": false})).unwrap(); + assert_eq!(parts(&s), 2); + s.execute("graph.setType", &json!({"markPoints": true, "connectPoints": false})).unwrap(); + assert_eq!(parts(&s), 4); + } + #[test] fn an_overridden_value_axis_is_used_exactly() { let mut s = Session::new();