mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-14 19:26:56 -04:00
Graph Type: Add Drop Shadow and Add Legend Across Top
Graph Type's Add Drop Shadow, as https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/add-drop-shadows.html describes, and Add Legend Across Top, as https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/change-the-position-of-legends.html describes. - dropShadow: a shadow behind each column, bar, stacked segment, line (line, scatter and radar) and pie wedge, just behind the series of its layer, so areas and columns drawn in front don't hide the shadows of the layer behind them. - legendAcrossTop: the legend's swatches and labels left to right from the plot's left edge, wrapping at the plot's width, the last row just above the plot and anything drawn over it (radar and stacked-pie labels). Own choices, as the pages don't say: a shadow is a black copy 2 pt down and right at 35% opacity; markers, areas and legend swatches cast none, nor do stacked segments of 0; a graph with more than 200,000 shadowed marks draws none. New fields are written only when set. Graphs with default options draw the same art as before.
This commit is contained in:
1 parent
5e4a282f90
commit
fe33dec0bb
4 files changed
+239
-7
No files matched your search
@@ -293,6 +293,12 @@ pub struct GraphSpec {
|
||||
pub right_axis_min: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub right_axis_max: Option<f64>,
|
||||
/// Graph Type › Add Drop Shadow (behind columns, bars, lines and pie wedges) and Add Legend Across Top (the
|
||||
/// legend in rows above the plot instead of a column on its right).
|
||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||
pub drop_shadow: bool,
|
||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||
pub legend_across_top: bool,
|
||||
/// Pie graphs: Legends in Wedges (the series labels inside their wedges instead of a legend beside the pies),
|
||||
/// Position and Sort.
|
||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||
@@ -408,6 +414,8 @@ impl Default for GraphSpec {
|
||||
right_axis_min: None,
|
||||
right_axis_max: None,
|
||||
series_markers: vec![],
|
||||
drop_shadow: false,
|
||||
legend_across_top: false,
|
||||
pie_legend_in_wedges: false,
|
||||
pie_position: PiePosition::Even,
|
||||
pie_sort: PieSort::None,
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Type…",
|
||||
["Object", "Graph"],
|
||||
None,
|
||||
"{id?, type?, seriesIndexes?: [index], 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?, valueAxis?: left|right|both (the bar graphs' value axis stays along the bottom), separateScales?: bool, rightTicks?: n, rightAxisMin?, rightAxisMax?, tickLength?: none|short|full, tickMarks?: n per division, rightTickLength?, rightTickMarks?, categoryTickLength?: none|short|full, categoryTickMarks?: n, ticksBetweenLabels?: bool, prefix?, suffix?, rightPrefix?, rightSuffix?: text around the value axis numbers, pieLegend?: none|standard|wedges (Legends in Wedges: the series labels inside their wedges), piePosition?: ratio|even|stacked (several pies sized by their totals, at one size (the default), or stacked), pieSort?: all|first|none (wedges largest first in each pie, in the first pie's order, or in data order (the default)); the query lists the pie options for pie graphs} change the graph type and options; with `seriesIndexes`, or (no `id`) with only series selected with Group Selection, `type` goes to those series only and `valueAxis` (left|right; both is refused) puts them on that value axis, while the other options still apply to the whole graph (Combine different graph types: column, stacked column, line and area mix, and so do bar and stacked bar; a series given the graph's type follows the graph again) (axisMin and axisMax together override the calculated value axis: exactly that range in `ticks` divisions, 5 when 0; with the value axis on both sides, separateScales gives the series on the right axis a scale of their own, set the same way with rightTicks, rightAxisMin and rightAxisMax); no options → the current ones",
|
||||
"{id?, type?, seriesIndexes?: [index], 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?, valueAxis?: left|right|both (the bar graphs' value axis stays along the bottom), separateScales?: bool, rightTicks?: n, rightAxisMin?, rightAxisMax?, tickLength?: none|short|full, tickMarks?: n per division, rightTickLength?, rightTickMarks?, categoryTickLength?: none|short|full, categoryTickMarks?: n, ticksBetweenLabels?: bool, prefix?, suffix?, rightPrefix?, rightSuffix?: text around the value axis numbers, dropShadow?: bool (Add Drop Shadow: a translucent black shadow down and right of the columns, bars, lines and pie wedges), legendAcrossTop?: bool (Add Legend Across Top: the legend in rows above the plot), pieLegend?: none|standard|wedges (Legends in Wedges: the series labels inside their wedges), piePosition?: ratio|even|stacked (several pies sized by their totals, at one size (the default), or stacked), pieSort?: all|first|none (wedges largest first in each pie, in the first pie's order, or in data order (the default)); the query lists the pie options for pie graphs} change the graph type and options; with `seriesIndexes`, or (no `id`) with only series selected with Group Selection, `type` goes to those series only and `valueAxis` (left|right; both is refused) puts them on that value axis, while the other options still apply to the whole graph (Combine different graph types: column, stacked column, line and area mix, and so do bar and stacked bar; a series given the graph's type follows the graph again) (axisMin and axisMax together override the calculated value axis: exactly that range in `ticks` divisions, 5 when 0; with the value axis on both sides, separateScales gives the series on the right axis a scale of their own, set the same way with rightTicks, rightAxisMin and rightAxisMax); no options → the current ones",
|
||||
has_selection,
|
||||
set_type
|
||||
),
|
||||
@@ -340,6 +340,31 @@ impl Gen<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Add Drop Shadow: how far the shadow sits down and right of its mark, and how dark it is.
|
||||
const SHADOW_OFFSET: f64 = 2.0;
|
||||
const SHADOW_OPACITY: f32 = 0.35;
|
||||
/// Most marks a graph draws shadows for (each is a copy).
|
||||
const SHADOW_BUDGET: usize = 200_000;
|
||||
|
||||
/// Mark `n`'s shadow: a black copy moved down and right, its fill and stroke (whichever it has) black.
|
||||
fn shadow_of(d: &mut Document, n: &Node) -> Arc<Node> {
|
||||
// Generated marks carry only paint and a stroke width, so that's all a shadow keeps.
|
||||
let mut c = n.clone();
|
||||
c.transform(Affine::translate((SHADOW_OFFSET, SHADOW_OFFSET)), false);
|
||||
let fill = if c.appearance.fill_paint().is_none() { Paint::None } else { Paint::solid(Color::BLACK) };
|
||||
let stroke = if c.appearance.stroke_paint().is_none() { Paint::None } else { Paint::solid(Color::BLACK) };
|
||||
c.appearance = Appearance::basic(fill, stroke, c.appearance.stroke_width()).into();
|
||||
Arc::new(d.reid(&c))
|
||||
}
|
||||
|
||||
/// How wide label `s` is set (its widest line), without adding it to a document.
|
||||
fn label_width(s: &str) -> f64 {
|
||||
let style = CharStyle { size: LABEL_SIZE, fill: Paint::solid(Color::BLACK), ..CharStyle::default() };
|
||||
let mut t = TextObject::point(Point::ZERO, &s.replace('|', "\n"), style);
|
||||
refresh_bounds(&mut t);
|
||||
Node::new(NodeId(0), NodeKind::Text(Box::new(t))).geometric_bounds().map_or(0.0, |b| b.width())
|
||||
}
|
||||
|
||||
/// A label with nothing to show (empty, or only `|` line breaks).
|
||||
fn blank_label(s: &str) -> bool {
|
||||
s.chars().all(|c| c == '|')
|
||||
@@ -443,6 +468,8 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
// Labels drawn over the series: a pie's Legends in Wedges (in the Legend group) and stacked pies' names.
|
||||
let mut wedge_labels = vec![];
|
||||
let mut on_top = vec![];
|
||||
// Add Drop Shadow: the columns, bars, lines and wedges to cast one.
|
||||
let mut shadowed: Vec<(usize, Arc<Node>)> = vec![];
|
||||
match g.kind {
|
||||
GraphKind::Pie => {
|
||||
// One pie per row, a wedge per series, clockwise from 12 o'clock. Position: side by side at one size
|
||||
@@ -517,6 +544,7 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
0.2126 * r + 0.7152 * g + 0.0722 * b < 0.5
|
||||
});
|
||||
let n = b.path(PathData::from_bezpath(&bp), fill, stroke, sw);
|
||||
shadowed.push((s, n.clone()));
|
||||
if let Some(items) = series.get_mut(s) {
|
||||
items.push(n);
|
||||
}
|
||||
@@ -573,7 +601,9 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
let pts: Vec<Point> = (0..ncat).map(|c| at(c, val(c, s))).collect();
|
||||
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));
|
||||
let n = b.path(polyline(&pts, true), fill, stroke, w);
|
||||
shadowed.push((s, n.clone()));
|
||||
items.push(n);
|
||||
}
|
||||
if g.mark_points {
|
||||
for p in pts {
|
||||
@@ -813,7 +843,9 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
if g.connect_points {
|
||||
for run in runs(&pts) {
|
||||
let (fill, stroke, w) = mark(si, false, default_series_paint(si), 1.0);
|
||||
series[si].push(b.path(polyline(&run, false), fill, stroke, w));
|
||||
let n = b.path(polyline(&run, false), fill, stroke, w);
|
||||
shadowed.push((si, n.clone()));
|
||||
series[si].push(n);
|
||||
}
|
||||
}
|
||||
if g.mark_points {
|
||||
@@ -848,6 +880,7 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
let a = c0 + slot * i as f64 + (slot - bar) / 2.0;
|
||||
let (fill, stroke, w) = mark(s, true, Paint::None, 0.0);
|
||||
let n = b.path(shapes::rectangle(bar_rect(a, bar, zero(axis(s)), vpos(axis(s), v))), fill, stroke, w);
|
||||
shadowed.push((s, n.clone()));
|
||||
if let Some(items) = series.get_mut(s) {
|
||||
items.push(n);
|
||||
}
|
||||
@@ -872,6 +905,10 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
*base += v;
|
||||
let (fill, stroke, sw) = mark(s, true, Paint::solid(Color::WHITE), 0.25);
|
||||
let n = b.path(shapes::rectangle(bar_rect(a, w, v0, v1)), fill, stroke, sw);
|
||||
// A segment of 0 has no area to shade.
|
||||
if v != 0.0 {
|
||||
shadowed.push((s, n.clone()));
|
||||
}
|
||||
if let Some(items) = series.get_mut(s) {
|
||||
items.push(n);
|
||||
}
|
||||
@@ -901,6 +938,7 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
for run in runs(&pts) {
|
||||
let (fill, stroke, w) = mark(s, false, default_series_paint(s), 1.0);
|
||||
let n = b.path(polyline(&run, false), fill, stroke, w);
|
||||
shadowed.push((s, n.clone()));
|
||||
if let Some(items) = series.get_mut(s) {
|
||||
items.push(n);
|
||||
}
|
||||
@@ -921,7 +959,47 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
// Legend: a swatch + label per series, right of the plot; the swatch joins its series group.
|
||||
let legend_series = if g.kind == GraphKind::Scatter { nser.div_ceil(2) } else { nser };
|
||||
let mut labels = vec![];
|
||||
if g.legend && !g.series.is_empty() && !(g.kind == GraphKind::Pie && g.pie_legend_in_wedges) {
|
||||
let legend_on = g.legend && !g.series.is_empty() && !(g.kind == GraphKind::Pie && g.pie_legend_in_wedges);
|
||||
if legend_on && g.legend_across_top {
|
||||
// Add Legend Across Top: swatch and label after swatch and label, in rows as wide as the plot, the last row
|
||||
// just above it.
|
||||
let entries: Vec<(usize, String)> = (0..legend_series)
|
||||
.map(|s| (s, if g.kind == GraphKind::Scatter { series_label(s * 2) } else { series_label(s) }))
|
||||
.filter(|(_, l)| !blank_label(l))
|
||||
.collect();
|
||||
let mut rows: Vec<Vec<(usize, String, f64)>> = vec![vec![]];
|
||||
let mut used = 0.0;
|
||||
for (s, label) in entries {
|
||||
let w = 12.0 + label_width(&label) + 12.0;
|
||||
// The gap after an entry may run past the plot's edge.
|
||||
if used + w - 12.0 > r.width() && rows.last().is_some_and(|row| !row.is_empty()) {
|
||||
rows.push(vec![]);
|
||||
used = 0.0;
|
||||
}
|
||||
used += w;
|
||||
if let Some(row) = rows.last_mut() {
|
||||
row.push((s, label, w));
|
||||
}
|
||||
}
|
||||
let height = |row: &[(usize, String, f64)]| LABEL_SIZE * 1.8 * row.iter().map(|(_, l, _)| l.split('|').count()).max().unwrap_or(1) as f64;
|
||||
// Above the plot and anything drawn over it (radar and stacked-pie labels).
|
||||
let top = b.out.iter().chain(on_top.iter()).filter_map(|n| n.geometric_bounds()).map(|bb| bb.y0).fold(r.y0, f64::min);
|
||||
let mut y = top - 8.0 - rows.iter().map(|row| height(row)).sum::<f64>();
|
||||
for row in &rows {
|
||||
let mut x = r.x0;
|
||||
for (s, label, w) in row {
|
||||
let marked = matches!(g.kind, GraphKind::Scatter | GraphKind::Radar) || kind(*s) == GraphKind::Line;
|
||||
let paint = mark(*s, true, Paint::None, 0.0);
|
||||
let swatch = b.marker(design(*s).filter(|_| marked), Rect::new(x, y, x + 8.0, y + 8.0), paint);
|
||||
if let Some(items) = series.get_mut(*s) {
|
||||
items.push(swatch);
|
||||
}
|
||||
labels.push(b.label(Point::new(x + 12.0, y + 7.5), label, Justify::Left, false));
|
||||
x += w;
|
||||
}
|
||||
y += height(row);
|
||||
}
|
||||
} else if legend_on {
|
||||
let x = right_edge + 14.0;
|
||||
// Each row as tall as its label's lines (a `|` in a label starts a new line).
|
||||
let mut y = r.y0;
|
||||
@@ -947,12 +1025,29 @@ fn generate(d: &mut Document, g: &GraphSpec) -> Vec<Arc<Node>> {
|
||||
GraphKind::Line => 2,
|
||||
_ => 1,
|
||||
};
|
||||
// Add Drop Shadow: a translucent black copy of each column, bar, line and wedge, a little down and right, just
|
||||
// behind the series of its layer (areas, columns, lines), so a layer in front doesn't hide the shadows of the one
|
||||
// behind. Left out past SHADOW_BUDGET marks.
|
||||
if !g.drop_shadow || shadowed.len() > SHADOW_BUDGET {
|
||||
shadowed.clear();
|
||||
}
|
||||
let mut series: Vec<(usize, Vec<Arc<Node>>)> = series.into_iter().enumerate().collect();
|
||||
series.sort_by_key(|(s, _)| depth(*s));
|
||||
let mut layer = None;
|
||||
for (s, items) in series {
|
||||
if items.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if layer != Some(depth(s)) {
|
||||
layer = Some(depth(s));
|
||||
let copies: Vec<Arc<Node>> = shadowed.iter().filter(|(t, _)| depth(*t) == depth(s)).map(|(_, n)| shadow_of(b.d, n)).collect();
|
||||
if !copies.is_empty() {
|
||||
let mut grp = Node::group(b.d.alloc_id(), copies);
|
||||
grp.name = Some("Drop Shadow".into());
|
||||
grp.opacity = SHADOW_OPACITY;
|
||||
b.out.push(Arc::new(grp));
|
||||
}
|
||||
}
|
||||
let name = g.series.get(s).cloned().filter(|n| !n.is_empty()).unwrap_or_else(|| format!("Series {}", s + 1));
|
||||
let grp = b.series(&name, s, items);
|
||||
b.out.push(grp);
|
||||
@@ -1473,6 +1568,8 @@ fn set_type(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
"suffix",
|
||||
"rightPrefix",
|
||||
"rightSuffix",
|
||||
"dropShadow",
|
||||
"legendAcrossTop",
|
||||
"pieLegend",
|
||||
"piePosition",
|
||||
"pieSort",
|
||||
@@ -1497,7 +1594,7 @@ fn set_type(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
"rightTickMarks": spec.right_tick_marks.clamp(1, MAX_TICK_MARKS), "categoryTickLength": spec.category_tick_length.id(),
|
||||
"categoryTickMarks": spec.category_tick_marks.clamp(1, MAX_TICK_MARKS), "ticksBetweenLabels": spec.ticks_between_labels,
|
||||
"prefix": one_line(&spec.prefix), "suffix": one_line(&spec.suffix), "rightPrefix": one_line(&spec.right_prefix),
|
||||
"rightSuffix": one_line(&spec.right_suffix),
|
||||
"rightSuffix": one_line(&spec.right_suffix), "dropShadow": spec.drop_shadow, "legendAcrossTop": spec.legend_across_top,
|
||||
});
|
||||
// Pie graphs: Legend, Position and Sort (their Legend stands for the legend checkbox).
|
||||
if let Some(o) = fields.as_object_mut().filter(|_| spec.kind == GraphKind::Pie) {
|
||||
@@ -1595,6 +1692,8 @@ fn set_type(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
spec.column_width = f64_or(p, "columnWidth", spec.column_width).clamp(1.0, 1000.0);
|
||||
spec.cluster_width = f64_or(p, "clusterWidth", spec.cluster_width).clamp(1.0, 100.0);
|
||||
spec.legend = bool_or(p, "legend", spec.legend);
|
||||
spec.drop_shadow = bool_or(p, "dropShadow", spec.drop_shadow);
|
||||
spec.legend_across_top = bool_or(p, "legendAcrossTop", spec.legend_across_top);
|
||||
// After `legend`, which the Graph Type dialog sends too.
|
||||
if let Some(v) = str_param(p, "pieLegend") {
|
||||
(spec.legend, spec.pie_legend_in_wedges) = match v.to_ascii_lowercase().as_str() {
|
||||
@@ -3264,4 +3363,127 @@ mod tests {
|
||||
assert!(axis_texts(&s, g).contains(&"One\nTwo\nThree".to_string()), "{ty}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_shadows_sit_behind_the_columns_lines_and_wedges() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
|
||||
let id = graph(&mut s, "column");
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
let kids = n.children().unwrap();
|
||||
let at = kids.iter().position(|c| c.name.as_deref() == Some("Drop Shadow")).unwrap();
|
||||
assert!(kids.iter().position(|c| c.series_index.is_some()).unwrap() > at, "behind the series");
|
||||
let shadow = &kids[at];
|
||||
assert!((shadow.opacity - 0.35).abs() < 1e-6);
|
||||
let copies: Vec<_> = shadow.children().unwrap().iter().filter_map(|c| c.geometric_bounds()).collect();
|
||||
let cols: Vec<_> = (0..2).flat_map(|i| marks(&s, id, i)).collect();
|
||||
assert_eq!(copies.len(), cols.len(), "one per column, none for the swatches");
|
||||
for c in &cols {
|
||||
assert!(copies.iter().any(|b| (b.x0 - c.x0 - 2.0).abs() < 1e-6 && (b.y0 - c.y0 - 2.0).abs() < 1e-6), "{c:?}");
|
||||
}
|
||||
let black = shadow.children().unwrap().iter().all(|c| c.appearance.fill_paint().color().map(|c| c.to_hex()) == Some("#000000".into()));
|
||||
assert!(black);
|
||||
// Lines cast one too (not their markers); pies one per wedge.
|
||||
let line = graph(&mut s, "line");
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(line).unwrap().clone();
|
||||
assert_eq!(group(&n, "Drop Shadow").children().unwrap().len(), 2, "one per series line");
|
||||
let pie = graph(&mut s, "pie");
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(pie).unwrap().clone();
|
||||
assert_eq!(group(&n, "Drop Shadow").children().unwrap().len(), 5, "the wedges with a value above 0");
|
||||
assert_eq!(s.execute("graph.setType", &json!({})).unwrap()["dropShadow"], true);
|
||||
s.execute("graph.setType", &json!({"dropShadow": false})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(pie).unwrap().clone();
|
||||
assert!(n.children().unwrap().iter().all(|c| c.name.as_deref() != Some("Drop Shadow")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legend_across_top_runs_in_rows_above_the_plot() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
|
||||
let id = graph(&mut s, "column");
|
||||
s.execute("graph.setType", &json!({"legendAcrossTop": true})).unwrap();
|
||||
let swatch = |s: &Session, i: u32| series_parts(s, id, i).last().unwrap().geometric_bounds().unwrap();
|
||||
let (a, b) = (swatch(&s, 0), swatch(&s, 1));
|
||||
assert!(a.y1 <= 100.0 - 8.0 + 1e-6 && (a.y0 - b.y0).abs() < 1e-6 && b.x0 > a.x1 && (a.x0 - 100.0).abs() < 1e-6, "{a:?} {b:?}");
|
||||
assert_eq!(s.execute("graph.setType", &json!({})).unwrap()["legendAcrossTop"], true);
|
||||
// Long labels wrap into rows within the plot's width, the last row just above it.
|
||||
let labels: Vec<String> = (0..6).map(|i| format!("A rather long series name {i}")).collect();
|
||||
let csv = format!(",{}\nQ1,1,2,3,4,5,6", labels.join(","));
|
||||
s.execute("graph.setData", &json!({"id": id.0, "csv": csv})).unwrap();
|
||||
let ys: Vec<f64> = (0..6).map(|i| swatch(&s, i).y0).collect();
|
||||
assert!(ys.windows(2).any(|w| w[1] > w[0]), "a second row: {ys:?}");
|
||||
assert!(ys.iter().all(|y| *y + 8.0 <= 100.0 - 8.0 + 1e-6), "{ys:?}");
|
||||
let xs: Vec<f64> = (0..6).map(|i| swatch(&s, i).x1).collect();
|
||||
assert!(xs.iter().all(|x| *x <= 400.0), "{xs:?}");
|
||||
let path = vectorcraft_testkit::temp_dir("graph-top").join("top.vectorcraft");
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
s.execute("document.save", &json!({"path": path})).unwrap();
|
||||
s.execute("document.open", &json!({"path": path})).unwrap();
|
||||
let g = spec(&s, id);
|
||||
assert!(g.legend_across_top && g.drop_shadow);
|
||||
let v = serde_json::to_value(GraphSpec::default()).unwrap();
|
||||
assert!(v.get("dropShadow").is_none() && v.get("legendAcrossTop").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_layer_keeps_its_shadows_just_behind_it() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
|
||||
let id = make(&mut s, "column", ",a,b,c\nQ1,3,2,1\nQ2,5,,2\nQ3,4,6,3");
|
||||
s.execute("graph.setType", &json!({"seriesIndexes": [0], "type": "area"})).unwrap();
|
||||
s.execute("graph.setType", &json!({"seriesIndexes": [2], "type": "line", "dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
let order: Vec<String> =
|
||||
n.children().unwrap().iter().map(|c| c.series_index.map_or_else(|| c.name.clone().unwrap_or_default(), |i| format!("s{i}"))).collect();
|
||||
// Areas cast none; the columns' shadows sit between the area and the columns, the line's between the columns
|
||||
// and the line.
|
||||
let at = |k: &str| order.iter().position(|o| o == k).unwrap();
|
||||
let shadows: Vec<usize> = order.iter().enumerate().filter(|(_, o)| *o == "Drop Shadow").map(|(i, _)| i).collect();
|
||||
assert_eq!(shadows.len(), 2, "{order:?}");
|
||||
assert!(at("s0") < shadows[0] && shadows[0] < at("s1") && at("s1") < shadows[1] && shadows[1] < at("s2"), "{order:?}");
|
||||
// b's blank leaves two columns; a line with a blank casts a shadow per run.
|
||||
let line = make(&mut s, "line", ",a\nQ1,1\nQ2,\nQ3,3\nQ4,4");
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(line).unwrap().clone();
|
||||
assert_eq!(group(&n, "Drop Shadow").children().unwrap().len(), 1, "Q1 alone draws no line; Q3–Q4 one");
|
||||
// Scatter and radar lines cast one too; a stacked segment of 0 doesn't.
|
||||
for (ty, want) in [("scatter", 1), ("radar", 2)] {
|
||||
let g = graph(&mut s, ty);
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(g).unwrap().clone();
|
||||
assert_eq!(group(&n, "Drop Shadow").children().unwrap().len(), want, "{ty}");
|
||||
}
|
||||
let st = make(&mut s, "stackedColumn", ",a,b\nQ1,0,2");
|
||||
s.execute("graph.setType", &json!({"dropShadow": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(st).unwrap().clone();
|
||||
assert_eq!(group(&n, "Drop Shadow").children().unwrap().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legend_across_top_keeps_above_labels_over_the_plot() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
|
||||
let id = make(&mut s, "radar", ",a,b\nTop|of|chart,1,2\nQ2,2,3\nQ3,3,1");
|
||||
s.execute("graph.setType", &json!({"legendAcrossTop": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
let axes_top = group(&n, "Axes").children().unwrap().iter().filter_map(|c| c.geometric_bounds()).map(|b| b.y0).fold(f64::MAX, f64::min);
|
||||
let legend_bottom =
|
||||
group(&n, "Legend").children().unwrap().iter().filter_map(|c| c.geometric_bounds()).map(|b| b.y1).fold(f64::MIN, f64::max);
|
||||
assert!(legend_bottom < axes_top, "{legend_bottom} above {axes_top}");
|
||||
// No legend: nothing across the top either.
|
||||
s.execute("graph.setType", &json!({"legend": false})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
assert!(n.children().unwrap().iter().all(|c| c.name.as_deref() != Some("Legend")));
|
||||
// Labels of a row other than the last stay within the plot's width.
|
||||
let labels: Vec<String> = (0..6).map(|i| format!("A rather long series name {i}")).collect();
|
||||
let col = make(&mut s, "column", &format!(",{}\nQ1,1,2,3,4,5,6", labels.join(",")));
|
||||
s.execute("graph.setType", &json!({"legendAcrossTop": true})).unwrap();
|
||||
let n = s.doc().unwrap().doc.node(col).unwrap().clone();
|
||||
let texts: Vec<_> = group(&n, "Legend").children().unwrap().iter().filter_map(|c| c.geometric_bounds()).collect();
|
||||
let last_row = texts.iter().map(|b| b.y0).fold(f64::MIN, f64::max);
|
||||
assert!(texts.iter().filter(|b| b.y0 < last_row - 1e-6).all(|b| b.x1 <= 400.0 + 1e-6), "{texts:?}");
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -59,7 +59,7 @@ Checked 2026-10-10 from the code, tests and open issues; no workflow fails, so V
|
||||
| M9 | Live effects (+ 3D & Materials) | 🟡 2D effects done incl. Effect → Pathfinder, Color Adjustments and Document Raster Effects Settings; PDF export warns when the pixel cap lowers raster-effect resolution; initial Revolve only; SVG Filters, remaining raster effects and 3D pending | 81–130 |
|
||||
| M10 | Brushes, symbols, patterns, Repeat | 🟡 pattern swatches (5 tile types, Pattern Options, editing mode, SVG `<pattern>`/PDF export) and live Repeat (radial/grid/mirror) done; brushes/symbols in progress | 23–37 |
|
||||
| M11 | Artboards & views (artboard panel/tool with Move Artwork for X/Y fields and Artboard Options, Trim View, middle-button pan, print tiling and the status bar's artboard navigator done; multiple windows, presentation polish) | 🟡 | 15–25 |
|
||||
| M12 | Advanced color & art (CMYK/ICC, separations, Gradient Mesh, Live Paint, Image Trace, Graphs) | 🟡 Gradient Mesh, Live Paint, Image Trace (13 presets, 18 ms/1k² image; the Flat Logo mode places edges to a fraction of a pixel, restores sharp corners, snaps lines and circles, and refuses gradients), Recolor Artwork, colour management (ICC, soft proofing, separations preview), Graphs (all 9 tools, Graph Data/Type, group-selected series colours persist through regenerate/save/open) done; Graph Design and Marker designs, Transpose and Switch x/y, `|` label line breaks and the pie options done; graph Column designs, Import Data and the data sheet's cell style pending | 6–10 |
|
||||
| M12 | Advanced color & art (CMYK/ICC, separations, Gradient Mesh, Live Paint, Image Trace, Graphs) | 🟡 Gradient Mesh, Live Paint, Image Trace (13 presets, 18 ms/1k² image; the Flat Logo mode places edges to a fraction of a pixel, restores sharp corners, snaps lines and circles, and refuses gradients), Recolor Artwork, colour management (ICC, soft proofing, separations preview), Graphs (all 9 tools, Graph Data/Type, group-selected series colours persist through regenerate/save/open) done; Graph Design and Marker designs, Transpose and Switch x/y, `|` label line breaks, the pie options, drop shadows and the legend across the top done; graph Column designs, Import Data and the data sheet's cell style pending | 6–10 |
|
||||
| M13 | Automation (Actions ✅ record/playback, persisted; variables, scripting, batch) | 🟡 | 18–27 |
|
||||
| M14 | 1.0 polish (preferences, shortcut editor, workspaces, accessibility, packaging for all OSes) | 🟡 Preferences, shortcut editor (chords with Shift and a punctuation key fire as typed), workspaces, a custom title bar on Windows/Linux with a Home button, content-sized dialogs, menus that scroll when longer than the window and macOS native menu dismissal done (M14.8), and native macOS save sheets with a Format menu (#866); an experimental, unsupported Windows 7 x64 portable OpenGL build (not verified by maintainers); accessibility and broader Windows/Linux packaging/QA pending | 18–28 |
|
||||
| — | Interaction fidelity pass (every tool's modifiers, Properties panel per context, isolation, nuance) | ⬜ | 60–90 |
|
||||
@@ -79,6 +79,7 @@ After placed documents (File › Place of a `.vectorcraft` file, linked), M4.14
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-11 | minor | M12: Graph Type's Add Drop Shadow and Add Legend Across Top. Scores/hours unchanged. |
|
||||
| 2026-10-11 | minor | M12: Graph Data's Transpose and Switch x/y, `|` line breaks in graph labels, pie Legend/Position/Sort. Scores/hours unchanged. |
|
||||
| 2026-10-11 | minor | M12: Object › Graph › Design… and Marker… (graph designs, marker designs); column designs remain. Scores/hours unchanged. |
|
||||
| 2026-10-12 | minor | M14: native macOS save Format menu (#866); filename regression tests, actual SVG save and PDF selection/cancel verified; estimates unchanged |
|
||||
|
||||
@@ -414,7 +414,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **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 sides meet at an angle at an anchor that isn't smooth: curved sides too, trimmed to what the cut leaves of them (#1144). 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). Line graphs take Edge-to-Edge Lines (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Graph Data transposes rows and columns and switches a scatter graph's x and y, and a `|` in a category or series label starts a new line. Pie graphs take Legends in Wedges, Position (Even, Ratio sized by area, Stacked on one centre) and Sort (None, All, First). Column designs, Import Data and the Graph Data sheet's cell style 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 (off by default: the points sit at the centres of their categories; graphs saved before the option keep their edge-to-edge lines), and radar graphs follow Mark Data Points and Connect Data Points. Blank cells (an empty CSV cell or `null`) are values left out, not zeros: columns, bars and stacked segments skip them, lines and scatter lines break around them and the value axis ignores them, while area, pie and radar draw them as 0; a number in straight quotes is a label, and the data window writes it back quoted. Graph types combine: Graph Type on series picked with Group Selection (or `series` indexes) draws them as their own type, with column, stacked column, line and area mixing on the vertical value axis and bar and stacked bar on the horizontal one; stacked columns take one slot of the cluster, lines draw in front of columns and areas behind. The value axis goes on the left, the right or both sides (column, stacked column, line, area and scatter graphs; bar graphs keep theirs along the bottom), and Separate Scales gives the series assigned to the right axis a scale of their own with its own tick values. Each value axis takes tick marks of no, short or full (across the plot) length and a count per division, and a prefix and suffix for its numbers; the category axis takes tick marks too (none by default), at or between its labels. Graph designs: Object › Graph › Design lists the designs with a preview of the selected one, and New Design (the selected art), Rename, Delete Design, Paste Design (a copy back to edit) and Select Unused, and Marker draws the data points and legend swatches of line, scatter and radar series with a design, scaled so its backmost object fills the default marker's square. Graph Data transposes rows and columns and switches a scatter graph's x and y, and a `|` in a category or series label starts a new line. Pie graphs take Legends in Wedges, Position (Even, Ratio sized by area, Stacked on one centre) and Sort (None, All, First). Graph Type adds drop shadows behind columns, bars, lines and wedges, and puts the legend in rows across the top. Column designs, Import Data and the Graph Data sheet's cell style 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.
|
||||
@@ -467,6 +467,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-11 | minor | Graph Type's Add Drop Shadow and Add Legend Across Top. Scores unchanged within rounding |
|
||||
| 2026-10-11 | minor | Graph Data's Transpose and Switch x/y, `|` line breaks in graph labels, and the pie graph options (Legends in Wedges, Position, Sort). Scores unchanged within rounding |
|
||||
| 2026-10-11 | minor | Graph designs and marker designs (Object › Graph › Design… and Marker…): menu stubs 27 → 25; the graphs row's missing items are column designs and Image Trace depth. Scores unchanged within rounding |
|
||||
| 2026-10-12 | minor | UI chrome: native macOS save sheets gain a Format menu (#866), with extension regression tests and actual save/cancel verification; score and hours unchanged (estimated) |
|
||||
|
||||
Reference in new issue
Block a user