mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 05:35:52 +00:00
Graphs: a paint written to an axis line that already shows it is kept for its kind
paint.setFill, paint.setStroke, addon.color.fillToStroke and addon.color.strokeToFill on an axis line, tick mark or radar ring that already showed the paint they write stored nothing, so a paint its kind kept from another line came back when the graph was drawn again. The paint written to the line's topmost visible fill or stroke row is now stored for its kind; its other attributes stay as the kind keeps them.
This commit is contained in:
@@ -260,7 +260,8 @@ fn copy_paint(s: &mut Session, p: &Value, to_stroke: bool) -> Result<Value> {
|
||||
let series = super::super::appearance::capture_series_paint_writes(&before, d, &ids, &written);
|
||||
let labels = super::super::graph::capture_label_styles(d, &ids, ©_run);
|
||||
let painted: Vec<NodeId> = written.iter().map(|(id, _)| *id).collect();
|
||||
let lines = super::super::graph::capture_line_changes(&before, d, &painted);
|
||||
// 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))
|
||||
})?;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ use series::default_series_color;
|
||||
pub(crate) use series::{
|
||||
LabelTextChange, capture_label_anti_alias, capture_label_changes, capture_label_fill_stroke_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_rows, capture_series_object_opacity, capture_series_opacity, capture_series_top_paints,
|
||||
graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, labels_in, paint_targets, series_group_marks,
|
||||
series_group_marks_where, series_groups_among, series_marks_in, series_object_opacity_differs, shown_paint,
|
||||
capture_line_fill_stroke_rows, capture_line_paint_writes, capture_line_rows, capture_series_object_opacity, capture_series_opacity,
|
||||
capture_series_top_paints, graph_part_members, is_design_art, is_graph_line, label_object_opacity_differs, label_rows, labels_in, paint_targets,
|
||||
series_group_marks, series_group_marks_where, series_groups_among, series_marks_in, series_object_opacity_differs, shown_paint,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -946,6 +946,39 @@ pub(crate) fn capture_line_changes(before: &Document, doc: &mut Document, ids: &
|
||||
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 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 = |fill: bool| items.iter().rposition(|it| it.is_fill() == fill && it.visible()).is_some_and(|at| written.contains(&(id, at)));
|
||||
let (fill, stroke) = (wrote(true), wrote(false));
|
||||
if !fill && !stroke {
|
||||
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());
|
||||
if fill {
|
||||
rows.paint.fill = shown.fill;
|
||||
}
|
||||
if stroke {
|
||||
rows.paint.stroke = shown.stroke;
|
||||
}
|
||||
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()
|
||||
|
||||
@@ -7350,6 +7350,27 @@ fn default_fill_and_stroke_on_an_axis_line_that_shows_it_is_kept() {
|
||||
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:?}");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pie_names_and_wedge_labels_keep_their_style() {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -640,6 +640,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);
|
||||
@@ -650,7 +652,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.
|
||||
|
||||
+3
-1
@@ -931,7 +931,9 @@ The other commands store them when given the line itself, and the `appearance.*`
|
||||
`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. 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. An `appearance.copyFrom` that does not apply
|
||||
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. 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
|
||||
|
||||
Reference in New Issue
Block a user