Graph Type: the graph kind is a dropdown of the nine types (fixes #2175)

This commit is contained in:
Marco Arnulfo
2026-10-16 14:57:18 +07:00
committed by bflatastic
parent e9edc49977
commit 3b00334c41
+26
View File
@@ -1,6 +1,8 @@
//! The generic parameter dialog (`ui.paramDialog`): edits a command's parameters (`__command`,
//! headed `__label`) and runs it on OK, with the fixed ones in `__params` (not shown) added.
use std::sync::LazyLock;
use serde_json::Value;
use super::{DialogSpec, form};
@@ -40,6 +42,7 @@ fn choices(command: &str, key: &str) -> Option<form::Choices> {
("text.areaOptions", "fit") => Some(AREA_FIT),
("text.areaOptions", "firstBaseline") => Some(FIRST_BASELINE),
("text.areaOptions", "verticalAlign") => Some(VERTICAL_ALIGN),
("graph.setType", "type") => Some(GRAPH_KINDS.as_slice()),
("graph.setType", "valueAxis") => Some(GRAPH_VALUE_AXIS),
("graph.setType", "tickLength" | "rightTickLength" | "categoryTickLength") => Some(GRAPH_TICK_LENGTH),
("graph.setType", "pieLegend") => Some(PIE_LEGEND),
@@ -62,6 +65,10 @@ const FIRST_BASELINE: form::Choices =
/// Area Type Options › Align (vertical alignment of the lines in each row/column).
const VERTICAL_ALIGN: form::Choices = &[("Top", "top"), ("Center", "center"), ("Bottom", "bottom"), ("Justify", "justify")];
/// Graph Type › Type: the nine graph kinds, in the Graph tool group's order.
static GRAPH_KINDS: LazyLock<Vec<(&'static str, &'static str)>> =
LazyLock::new(|| vectorcraft_doc::GraphKind::ALL.iter().map(|k| (k.label(), k.id())).collect());
/// Graph Type › Value Axis (series picked on both axes show none, and OK leaves each where it is).
const GRAPH_VALUE_AXIS: form::Choices = &[("On Left Side", "left"), ("On Right Side", "right"), ("On Both Sides", "both")];
@@ -146,4 +153,23 @@ mod tests {
crate::dialogs::confirm(&mut app).unwrap();
assert_eq!(app.session.execute("graph.setType", &json!({})).unwrap()["valueAxis"], "both");
}
/// Graph Type › Type is a dropdown of the nine graph kinds (#2175), and OK changes the graph's
/// type and keeps its data.
#[test]
fn graph_type_is_a_dropdown_of_the_graph_kinds() {
let kinds: Vec<(&str, &str)> = vectorcraft_doc::GraphKind::ALL.iter().map(|k| (k.label(), k.id())).collect();
assert_eq!(choices("graph.setType", "type").unwrap().to_vec(), kinds);
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
app.run("graph.create", json!({"type": "column", "x": 0, "y": 0, "width": 200, "height": 150, "csv": ",a,b\nQ1,1,2\nQ2,3,4"})).unwrap();
let data = app.session.execute("graph.setData", &json!({})).unwrap();
assert_eq!(data["rows"], json!([[1.0, 2.0], [3.0, 4.0]]));
crate::menus::graph_dialog(&mut app, "graph.setType").unwrap();
assert_eq!(app.ui.dialog.as_ref().unwrap().str("type"), "column");
app.ui.dialog.as_mut().unwrap().fields.insert("type".into(), json!("stackedBar"));
crate::dialogs::confirm(&mut app).unwrap();
assert_eq!(app.session.execute("graph.setType", &json!({})).unwrap()["type"], "stackedBar");
assert_eq!(app.session.execute("graph.setData", &json!({})).unwrap(), data);
}
}