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 std::rc::Rc;
|
||||||
|
|
||||||
use crate::model::Model;
|
use crate::model::Model;
|
||||||
|
use crate::model::category::CategoryKind;
|
||||||
use crate::model::cell::{CellKey, CellValue};
|
use crate::model::cell::{CellKey, CellValue};
|
||||||
use crate::view::{Axis, View};
|
use crate::view::{Axis, View};
|
||||||
|
|
||||||
@ -132,22 +133,12 @@ impl GridLayout {
|
|||||||
page_coords: Vec<(String, String)>,
|
page_coords: Vec<(String, String)>,
|
||||||
none_cats: Vec<String>,
|
none_cats: Vec<String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Filter cells by page_coords
|
let mut records: Vec<(CellKey, CellValue)> = model
|
||||||
let partial: Vec<(String, String)> = page_coords.clone();
|
.data
|
||||||
let mut records: Vec<(CellKey, CellValue)> = if partial.is_empty() {
|
.matching_cells(&page_coords)
|
||||||
model
|
.into_iter()
|
||||||
.data
|
.map(|(k, v)| (k, v.clone()))
|
||||||
.iter_cells()
|
.collect();
|
||||||
.map(|(k, v)| (k, v.clone()))
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
model
|
|
||||||
.data
|
|
||||||
.matching_cells(&partial)
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k, v.clone()))
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
// Sort for deterministic ordering
|
// Sort for deterministic ordering
|
||||||
records.sort_by(|a, b| a.0.0.cmp(&b.0.0));
|
records.sort_by(|a, b| a.0.0.cmp(&b.0.0));
|
||||||
|
|
||||||
@ -157,12 +148,22 @@ impl GridLayout {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Synthesize col items: one per non-virtual category + "Value"
|
// Synthesize col items: one per non-virtual category + "Value"
|
||||||
let cat_names: Vec<String> = model
|
let mut cat_names: Vec<String> = model
|
||||||
.category_names()
|
.category_names()
|
||||||
.into_iter()
|
.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)
|
.map(String::from)
|
||||||
.collect();
|
.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
|
let mut col_items: Vec<AxisEntry> = cat_names
|
||||||
.iter()
|
.iter()
|
||||||
.map(|c| AxisEntry::DataItem(vec![c.clone()]))
|
.map(|c| AxisEntry::DataItem(vec![c.clone()]))
|
||||||
|
|||||||
Reference in New Issue
Block a user