From 709f2df11fdf38561b439971eb435a0935152478 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Wed, 15 Apr 2026 04:32:14 -0700 Subject: [PATCH] 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) --- src/model/types.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/model/types.rs b/src/model/types.rs index 4c44360..deca012 100644 --- a/src/model/types.rs +++ b/src/model/types.rs @@ -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");