Graphs: a stroke painted after an axis line lost its stroke keeps a weight

When one line of a kind had its stroke set to None, the kind kept a zero
stroke weight. Painting the stroke of another line of that kind kept only
the new paint, so the next redraw drew every line of the kind with no
weight. The kind now takes the painted line's weight when it kept no
stroke paint before the edit. A zero weight set together with a stroke
color, or kept with a painted stroke, stays as set.
This commit is contained in:
dotCooCoo
2026-11-15 11:53:45 -08:00
parent f60d329363
commit 1bdc03d2ad
2 changed files with 76 additions and 2 deletions
+26 -2
View File
@@ -1359,7 +1359,11 @@ pub(crate) fn capture_line_changes(before: &Document, doc: &mut Document, 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 = line_slot(&mut spec.label_styles, line);
let mut rows = slot.clone().unwrap_or_else(|| line.default_rows());
let was_unpainted = stroke_unpainted(&rows);
merge_row_edits(&mut rows, &old, &new);
if old.paint.stroke != new.paint.stroke {
keep_painted_stroke_weight(&mut rows, was_unpainted, &new.paint);
}
let kept = (rows != line.default_rows()).then_some(rows);
changed |= *slot != kept;
*slot = kept;
@@ -1388,10 +1392,12 @@ pub(crate) fn capture_line_paint_writes(doc: &mut Document, written: &[(NodeId,
let slot = line_slot(&mut spec.label_styles, line);
let mut rows = slot.clone().unwrap_or_else(|| line.default_rows());
if fill {
rows.paint.fill = shown.fill;
rows.paint.fill = shown.fill.clone();
}
if stroke {
rows.paint.stroke = shown.stroke;
let was_unpainted = stroke_unpainted(&rows);
rows.paint.stroke = shown.stroke.clone();
keep_painted_stroke_weight(&mut rows, was_unpainted, &shown);
}
let kept = (rows != line.default_rows()).then_some(rows);
changed |= *slot != kept;
@@ -1400,6 +1406,24 @@ pub(crate) fn capture_line_paint_writes(doc: &mut Document, written: &[(NodeId,
changed
}
/// Give kept line rows whose stroke an edit painted the painted line's stroke weight (`shown`) when the kind kept no
/// stroke paint before the edit (`was_unpainted`) and keeps the zero weight a stroke set to None left. A non-zero kept
/// weight stays, and so do a zero weight kept with a painted stroke and a zero weight the painted line shows.
fn keep_painted_stroke_weight(rows: &mut vectorcraft_doc::LabelRows, was_unpainted: bool, shown: &vectorcraft_doc::SeriesPaint) {
if was_unpainted
&& !stroke_unpainted(rows)
&& rows.paint.stroke_width.is_some_and(|w| w <= 0.0)
&& let Some(w) = shown.stroke_width.filter(|w| *w > 0.0)
{
rows.paint.stroke_width = Some(w);
}
}
/// Do kept line rows keep no stroke paint?
fn stroke_unpainted(rows: &vectorcraft_doc::LabelRows) -> bool {
rows.paint.stroke.as_ref().is_none_or(Paint::is_none)
}
/// 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()
+50
View File
@@ -8077,6 +8077,56 @@ fn a_stroke_written_to_an_axis_line_that_shows_it_is_kept() {
});
}
/// A stroke painted on an axis line after another axis line's stroke was set to None is kept for every axis line with
/// the painted line's weight, not the zero weight the unpainted stroke left on its kind.
#[test]
fn a_stroke_painted_after_an_axis_line_lost_its_stroke_keeps_a_weight() {
let cases = ["paint.setStroke", "addon.color.fillToStroke", "appearance.setItem"];
every_case(cases, |cmd| {
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 weight = line_look(&lines[1]).1;
assert!(weight > 0.0, "{cmd}: the line has a stroke weight: {weight}");
s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "none": true})).unwrap();
let b = lines[1].id.0;
match *cmd {
"paint.setStroke" => s.execute(cmd, &json!({"ids": [b], "color": "#ff0000"})).unwrap(),
"addon.color.fillToStroke" => {
s.execute("paint.setFill", &json!({"ids": [b], "color": "#ff0000"})).unwrap();
s.execute(cmd, &json!({"ids": [b]})).unwrap()
}
_ => s.execute(cmd, &json!({"ids": [b], "index": top_row(&s, lines[1].id, false), "color": "#ff0000"})).unwrap(),
};
let looks = redrawn_line_looks(&mut s, id);
assert!(looks.iter().all(|l| l.0 == "#ff0000" && (l.1 - weight).abs() < 1e-9), "{cmd}: {looks:?}");
});
}
/// A zero stroke weight set together with a stroke color on an axis line is kept for every axis line as set, also when
/// a stroke is painted on another axis line before the graph is drawn again.
#[test]
fn a_zero_weight_set_with_a_stroke_color_on_an_axis_line_is_kept() {
every_case([false, true], |repaint| {
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], "none": true})).unwrap();
let at = top_row(&s, lines[1].id, false);
s.execute("appearance.setItem", &json!({"ids": [lines[1].id.0], "index": at, "color": "#ff0000", "weight": 0})).unwrap();
let color = if *repaint {
s.execute("paint.setStroke", &json!({"ids": [lines[2].id.0], "color": "#0000ff"})).unwrap();
"#0000ff"
} else {
"#ff0000"
};
let looks = redrawn_line_looks(&mut s, id);
assert!(looks.iter().all(|l| l.0 == color && l.1 == 0.0), "repaint {repaint}: {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() {