mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 16:42:52 +00:00
Graphs: an axis value that is not a number reaches graph.setType from Graph Type
Override Calculated Values fills only the axis values that are missing, so a value that is not a number is sent as it is and the command refuses it instead of the dialog putting a calculated value in its place. The right axis page without a scale of its own is described in docs/mcp.md.
This commit is contained in:
@@ -412,12 +412,14 @@ fn settle(d: &mut Dialog) {
|
||||
continue;
|
||||
}
|
||||
let ((lo, hi), count) = (bounds(d, axis), divisions(d, axis));
|
||||
// A value that is not a number stays, and `graph.setType` refuses it.
|
||||
let missing = |d: &Dialog, key: &str| d.fields.get(key).is_none_or(Value::is_null);
|
||||
for (key, value) in [(axis.min, json!(lo)), (axis.max, json!(hi))] {
|
||||
if number(d, key).is_none() {
|
||||
if missing(d, key) {
|
||||
d.fields.insert(key.into(), value);
|
||||
}
|
||||
}
|
||||
if number(d, axis.ticks).is_none_or(|n| n < 1.0) {
|
||||
if missing(d, axis.ticks) || number(d, axis.ticks).is_some_and(|n| n < 1.0) {
|
||||
d.fields.insert(axis.ticks.into(), json!(count));
|
||||
}
|
||||
}
|
||||
@@ -1148,6 +1150,21 @@ mod tests {
|
||||
assert_eq!(problem(app.ui.dialog.as_ref().unwrap()), None);
|
||||
set(&mut app, RIGHT_SERIES, json!([1]));
|
||||
assert!(problem(app.ui.dialog.as_ref().unwrap()).is_some());
|
||||
// A value that is not a number is not replaced by a calculated one: the command refuses it.
|
||||
open(&mut app).unwrap();
|
||||
set(&mut app, "axisMax", json!("ten"));
|
||||
settle(app.ui.dialog.as_mut().unwrap());
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().fields["axisMax"], "ten");
|
||||
let before = steps(&app);
|
||||
assert!(crate::dialogs::confirm(&mut app).is_err());
|
||||
assert_eq!((steps(&app), query(&mut app)["axisMax"].as_f64()), (before, Some(20.0)));
|
||||
open(&mut app).unwrap();
|
||||
for (key, value) in [("rightOverrideValues", json!(true)), ("rightAxisMin", json!(5)), ("rightAxisMax", json!(1))] {
|
||||
set(&mut app, key, value);
|
||||
}
|
||||
set(&mut app, "valueAxis", json!("both"));
|
||||
set(&mut app, "separateScales", json!(true));
|
||||
set(&mut app, RIGHT_SERIES, json!([1]));
|
||||
// A pie graph has no value axis to refuse.
|
||||
set(&mut app, "type", json!("pie"));
|
||||
assert_eq!(problem(app.ui.dialog.as_ref().unwrap()), None);
|
||||
|
||||
+4
-2
@@ -10144,8 +10144,10 @@ the whole graph, as the command applies them; `type` or `valueAxis` is `null` wh
|
||||
OK then leaves each series as it is. OK runs `graph.setType` with the fields: `legend` for every type but pie,
|
||||
and the three pie options for a pie graph. When the selection changed while the dialog was open, it also sends `id`, and
|
||||
`seriesIndexes` while series are picked and a `type` or `valueAxis` goes to them, so it changes the graph and the series
|
||||
the dialog opened on. With Separate Scales, a value axis side that no series is on draws the other side's scale, and
|
||||
its Override Calculated Values is dimmed. With nothing changed it closes without a step of history. An overridden value
|
||||
the dialog opened on. A value axis side without a scale of its own (the right side without Separate Scales, or with
|
||||
Separate Scales a side that no series is on) shows the tick values of the scale drawn on it, and its Override Calculated
|
||||
Values is dimmed. A value of `axisMin`, `axisMax` or `ticks` (or of the right axis' three) that is not a number is sent
|
||||
as it is, and `graph.setType` refuses it. With nothing changed it closes without a step of history. An overridden value
|
||||
axis whose maximum is not more than its minimum is the error "Maximum must be more than Minimum." and the dialog stays
|
||||
open. The types the dialog dims for picked series (those that cannot go in the graph), the options it dims for a type
|
||||
and the pages it lists are VectorCraft's own rules.
|
||||
|
||||
Reference in New Issue
Block a user