refactor(records): use CategoryKind for column filtering, stabilize _Measure position
- Filter records-mode columns by CategoryKind instead of string names - Simplify cell fetching: matching_cells already handles empty filters - Sort _Measure to always appear right before Value column Made-with: Cursor
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::model::Model;
|
||||
use crate::model::category::CategoryKind;
|
||||
use crate::model::cell::{CellKey, CellValue};
|
||||
use crate::view::{Axis, View};
|
||||
|
||||
@ -132,22 +133,12 @@ impl GridLayout {
|
||||
page_coords: Vec<(String, String)>,
|
||||
none_cats: Vec<String>,
|
||||
) -> Self {
|
||||
// Filter cells by page_coords
|
||||
let partial: Vec<(String, String)> = page_coords.clone();
|
||||
let mut records: Vec<(CellKey, CellValue)> = if partial.is_empty() {
|
||||
model
|
||||
.data
|
||||
.iter_cells()
|
||||
.map(|(k, v)| (k, v.clone()))
|
||||
.collect()
|
||||
} else {
|
||||
model
|
||||
.data
|
||||
.matching_cells(&partial)
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.clone()))
|
||||
.collect()
|
||||
};
|
||||
let mut records: Vec<(CellKey, CellValue)> = model
|
||||
.data
|
||||
.matching_cells(&page_coords)
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.clone()))
|
||||
.collect();
|
||||
// Sort for deterministic ordering
|
||||
records.sort_by(|a, b| a.0.0.cmp(&b.0.0));
|
||||
|
||||
@ -157,12 +148,22 @@ impl GridLayout {
|
||||
.collect();
|
||||
|
||||
// Synthesize col items: one per non-virtual category + "Value"
|
||||
let cat_names: Vec<String> = model
|
||||
let mut cat_names: Vec<String> = model
|
||||
.category_names()
|
||||
.into_iter()
|
||||
.filter(|c| *c != "_Index" && *c != "_Dim")
|
||||
.filter(|c| {
|
||||
let kind = model.category(c).map(|cat| cat.kind);
|
||||
!matches!(kind, Some(CategoryKind::VirtualIndex | CategoryKind::VirtualDim))
|
||||
})
|
||||
.map(String::from)
|
||||
.collect();
|
||||
// _Measure goes last among category columns (right before Value)
|
||||
cat_names.sort_by_key(|c| {
|
||||
matches!(
|
||||
model.category(c).map(|cat| cat.kind),
|
||||
Some(CategoryKind::VirtualMeasure)
|
||||
)
|
||||
});
|
||||
let mut col_items: Vec<AxisEntry> = cat_names
|
||||
.iter()
|
||||
.map(|c| AxisEntry::DataItem(vec![c.clone()]))
|
||||
|
||||
Reference in New Issue
Block a user