fix(model): initialize virtual categories with Axis::None
Ensure that virtual categories (_Index, _Dim, _Measure) are registered in the default view with Axis::None. This prevents potential panics when calling axis_of on these categories and allows users to move them to a specific axis manually. Co-Authored-By: fiddlerwoaroof/git-smart-commit (gemma-4-31B-it-UD-Q4_K_XL.gguf)
This commit is contained in:
@ -61,15 +61,10 @@ impl Model {
|
||||
measure_agg: HashMap::new(),
|
||||
formula_cache: HashMap::new(),
|
||||
};
|
||||
// Add virtuals to existing views (default view).
|
||||
// Start in records mode; on_category_added will reclaim Row/Column
|
||||
// for the first two regular categories.
|
||||
for view in m.views.values_mut() {
|
||||
view.on_category_added("_Index");
|
||||
view.on_category_added("_Dim");
|
||||
view.on_category_added("_Measure");
|
||||
view.set_axis("_Index", crate::view::Axis::Row);
|
||||
view.set_axis("_Dim", crate::view::Axis::Column);
|
||||
}
|
||||
m
|
||||
}
|
||||
@ -866,6 +861,17 @@ mod model_tests {
|
||||
let _ = m.active_view();
|
||||
}
|
||||
|
||||
/// improvise-kos: virtual categories must be registered in the default view
|
||||
/// at Axis::None so they don't panic on axis_of and can be moved by the user.
|
||||
#[test]
|
||||
fn new_model_registers_virtuals_in_default_view() {
|
||||
let m = Model::new("Test");
|
||||
let v = m.active_view();
|
||||
assert_eq!(v.axis_of("_Index"), Axis::None);
|
||||
assert_eq!(v.axis_of("_Dim"), Axis::None);
|
||||
assert_eq!(v.axis_of("_Measure"), Axis::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_category_creates_entry() {
|
||||
let mut m = Model::new("Test");
|
||||
|
||||
Reference in New Issue
Block a user