f8-engine 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {f8_engine-0.3.2 → f8_engine-0.4.0}/Cargo.lock +2 -2
- {f8_engine-0.3.2 → f8_engine-0.4.0}/Cargo.toml +1 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/PKG-INFO +1 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/format.rs +17 -5
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/workbook.rs +2 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/resolve.rs +8 -6
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/layout/mod.rs +103 -54
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/lowering/mod.rs +16 -9
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/ast.rs +50 -3
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/error.rs +2 -2
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/mod.rs +1 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/expr/parser.rs +47 -4
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/error.rs +8 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/format.rs +0 -2
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/theme.rs +20 -8
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/src/error.rs +1 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/audit.py +11 -5
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/SKILL.md +1 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/references/auditing-and-repair.md +1 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/references/syntax-and-grid.md +5 -5
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/types.py +1 -1
- {f8_engine-0.3.2 → f8_engine-0.4.0}/LICENSE +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/README.md +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/Cargo.toml +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/compiled/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/compiled/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/compiled/model.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/emission/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/context.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/expr.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/eval/model.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/cycle.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/dependency.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/graph/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/cell.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/expand.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/id.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/ir/symbol.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/layout/a1.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/layout/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/lowering/address.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/lowering/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/compiler/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/common.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/constructors.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/parts.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/serial.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/date/yearfrac.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/annuity.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/discounting.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/irr.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/financial/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/boolean.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/branching.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/error_handling.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/logical/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/index.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/search.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/xlookup.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/lookup/xmatch.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/aggregation.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/basic.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/conditional.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/criteria.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/product.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/math/rounding.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/registry.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/functions/traits.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/lib.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/id.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/manifest.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/model/table.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/value/error.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/value/format.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-core/src/value/mod.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/Cargo.toml +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/src/lib.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/crates/f8-python/src/model.rs +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/pyproject.toml +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/__init__.py +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/__main__.py +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/_core.pyi +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/builder.py +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/cli.py +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/py.typed +0 -0
- {f8_engine-0.3.2 → f8_engine-0.4.0}/python/f8/skills/f8-modeling/references/functions.md +0 -0
|
@@ -37,7 +37,7 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|
|
37
37
|
|
|
38
38
|
[[package]]
|
|
39
39
|
name = "f8-core"
|
|
40
|
-
version = "0.
|
|
40
|
+
version = "0.4.0"
|
|
41
41
|
dependencies = [
|
|
42
42
|
"indexmap",
|
|
43
43
|
"petgraph",
|
|
@@ -50,7 +50,7 @@ dependencies = [
|
|
|
50
50
|
|
|
51
51
|
[[package]]
|
|
52
52
|
name = "f8-python"
|
|
53
|
-
version = "0.
|
|
53
|
+
version = "0.4.0"
|
|
54
54
|
dependencies = [
|
|
55
55
|
"f8-core",
|
|
56
56
|
"pyo3",
|
|
@@ -3,7 +3,7 @@ resolver = "3"
|
|
|
3
3
|
members = ["crates/f8-core", "crates/f8-python"]
|
|
4
4
|
|
|
5
5
|
[workspace.package]
|
|
6
|
-
version = "0.
|
|
6
|
+
version = "0.4.0"
|
|
7
7
|
edition = "2024"
|
|
8
8
|
description = "Financial modeling engine with compiler verification and live Excel formulas"
|
|
9
9
|
authors = ["Michael (Chencheng) Hu, CFA"]
|
|
@@ -95,7 +95,6 @@ struct ParsedPalette {
|
|
|
95
95
|
input_text: Color,
|
|
96
96
|
formula_text: Color,
|
|
97
97
|
shade_muted_fill: Option<Color>,
|
|
98
|
-
shade_accent_fill: Option<Color>,
|
|
99
98
|
shade_alt_fill: Option<Color>,
|
|
100
99
|
highlight_fill: Option<Color>,
|
|
101
100
|
highlight_text: Color,
|
|
@@ -125,7 +124,6 @@ impl ParsedPalette {
|
|
|
125
124
|
input_text: parse_hex_color("input_text", &p.input_text)?,
|
|
126
125
|
formula_text: parse_hex_color("formula_text", &p.formula_text)?,
|
|
127
126
|
shade_muted_fill: parse_fill_color("shade_muted_fill", &p.shade_muted_fill)?,
|
|
128
|
-
shade_accent_fill: parse_fill_color("shade_accent_fill", &p.shade_accent_fill)?,
|
|
129
127
|
shade_alt_fill: parse_fill_color("shade_alt_fill", &p.shade_alt_fill)?,
|
|
130
128
|
highlight_fill: parse_fill_color("highlight_fill", &p.highlight_fill)?,
|
|
131
129
|
highlight_text: parse_hex_color("highlight_text", &p.highlight_text)?,
|
|
@@ -153,6 +151,8 @@ pub struct CellFormatKey {
|
|
|
153
151
|
pub is_descriptor: bool,
|
|
154
152
|
/// Descriptor indentation level.
|
|
155
153
|
pub indent: u8,
|
|
154
|
+
/// Whether the cell requires multi-line text wrapping.
|
|
155
|
+
pub wrap_text: bool,
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
impl CellFormatKey {
|
|
@@ -175,8 +175,16 @@ impl CellFormatKey {
|
|
|
175
175
|
is_input,
|
|
176
176
|
is_descriptor,
|
|
177
177
|
indent,
|
|
178
|
+
wrap_text: false,
|
|
178
179
|
}
|
|
179
180
|
}
|
|
181
|
+
|
|
182
|
+
/// Builder method enabling or disabling text wrapping on the cell format.
|
|
183
|
+
#[must_use]
|
|
184
|
+
pub const fn with_wrap_text(mut self, wrap_text: bool) -> Self {
|
|
185
|
+
self.wrap_text = wrap_text;
|
|
186
|
+
self
|
|
187
|
+
}
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
/// Format synthesizer and deduplication cache mapping semantic cell keys and structural headers
|
|
@@ -328,7 +336,7 @@ impl FormatCache {
|
|
|
328
336
|
format = format.set_bold();
|
|
329
337
|
}
|
|
330
338
|
|
|
331
|
-
// 2. Alignment
|
|
339
|
+
// 2. Alignment, Indentation, and Wrapping (Descriptor Left with optional indent, Measure Right, VerticalCenter)
|
|
332
340
|
format = if key.is_descriptor {
|
|
333
341
|
let mut fmt = format.set_align(FormatAlign::Left);
|
|
334
342
|
if key.indent > 0 {
|
|
@@ -337,13 +345,17 @@ impl FormatCache {
|
|
|
337
345
|
fmt
|
|
338
346
|
} else {
|
|
339
347
|
format.set_align(FormatAlign::Right)
|
|
340
|
-
}
|
|
348
|
+
}
|
|
349
|
+
.set_align(FormatAlign::VerticalCenter);
|
|
350
|
+
|
|
351
|
+
if key.wrap_text {
|
|
352
|
+
format = format.set_text_wrap();
|
|
353
|
+
}
|
|
341
354
|
|
|
342
355
|
// 3. Background Fill Precedence:
|
|
343
356
|
// is_highlight > total (or shade) > subtotal (or shade) > shade > data
|
|
344
357
|
let shade_fill = match key.role.shade {
|
|
345
358
|
Some(Shade::Muted) => self.palette.shade_muted_fill,
|
|
346
|
-
Some(Shade::Accent) => self.palette.shade_accent_fill,
|
|
347
359
|
Some(Shade::Alt) => self.palette.shade_alt_fill,
|
|
348
360
|
Some(Shade::None) | None => None,
|
|
349
361
|
};
|
|
@@ -369,9 +369,10 @@ pub fn resolve_table_ref(
|
|
|
369
369
|
.get_table(&origin.table)
|
|
370
370
|
.ok_or_else(|| ResolveError::unregistered_table(origin, origin.table.clone()))?;
|
|
371
371
|
|
|
372
|
+
let resolved_table_id = table_ref.table.resolve(&origin.table);
|
|
372
373
|
let target_table = symbol_table
|
|
373
|
-
.get_table(
|
|
374
|
-
.ok_or_else(|| ResolveError::unknown_table(origin,
|
|
374
|
+
.get_table(resolved_table_id)
|
|
375
|
+
.ok_or_else(|| ResolveError::unknown_table(origin, resolved_table_id.clone()))?;
|
|
375
376
|
|
|
376
377
|
let rows = resolve_row_selector(origin, target_table, origin_table, &table_ref.row)?;
|
|
377
378
|
let cols = resolve_col_selector(origin, target_table, origin_table, &table_ref.col)?;
|
|
@@ -382,7 +383,7 @@ pub fn resolve_table_ref(
|
|
|
382
383
|
for row in rows {
|
|
383
384
|
for col in &cols {
|
|
384
385
|
resolved.push(CellId::new(
|
|
385
|
-
|
|
386
|
+
resolved_table_id.clone(),
|
|
386
387
|
row.clone(),
|
|
387
388
|
col.clone(),
|
|
388
389
|
));
|
|
@@ -419,6 +420,7 @@ pub fn resolve_cell_dependencies(
|
|
|
419
420
|
#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
|
|
420
421
|
mod tests {
|
|
421
422
|
use super::*;
|
|
423
|
+
use crate::expr::ast::TableSelector;
|
|
422
424
|
use crate::model::id::{SheetId, TableId};
|
|
423
425
|
use crate::model::table::{ColumnSpec, RowSpec, TableSpec};
|
|
424
426
|
|
|
@@ -428,9 +430,9 @@ mod tests {
|
|
|
428
430
|
let expr = Expr::parse(formula).expect("valid formula");
|
|
429
431
|
let refs = collect_references(&expr);
|
|
430
432
|
assert_eq!(refs.len(), 3);
|
|
431
|
-
assert_eq!(refs[0].table,
|
|
432
|
-
assert_eq!(refs[1].table,
|
|
433
|
-
assert_eq!(refs[2].table,
|
|
433
|
+
assert_eq!(refs[0].table, TableSelector::from("TableA"));
|
|
434
|
+
assert_eq!(refs[1].table, TableSelector::from("TableB"));
|
|
435
|
+
assert_eq!(refs[2].table, TableSelector::from("TableC"));
|
|
434
436
|
}
|
|
435
437
|
|
|
436
438
|
#[test]
|
|
@@ -20,7 +20,7 @@ use crate::model::format::{CurrencyCode, FormatPreset, SemanticStyle, Shade};
|
|
|
20
20
|
use crate::model::id::{SheetId, TableId};
|
|
21
21
|
use crate::model::manifest::{FreezePanes, ProjectManifest};
|
|
22
22
|
use crate::model::table::{ColumnSpec, PlacementSpec, RowSpec, TableSpec, ValueLiteral};
|
|
23
|
-
use crate::model::theme::Theme;
|
|
23
|
+
use crate::model::theme::{MetricsConfig, Theme};
|
|
24
24
|
use crate::value::{CellValue, format_accounting_number};
|
|
25
25
|
|
|
26
26
|
/// Semantic styling role assigned to a physical coordinate.
|
|
@@ -72,6 +72,9 @@ pub struct PhysicalCoordinate {
|
|
|
72
72
|
pub style_role: StyleRole,
|
|
73
73
|
/// Descriptor text indentation level.
|
|
74
74
|
pub indent: u8,
|
|
75
|
+
/// Whether this cell requires multi-line text wrapping.
|
|
76
|
+
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
77
|
+
pub wrap_text: bool,
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/// Physical bounding box and structural row offsets for a table on a worksheet.
|
|
@@ -464,6 +467,7 @@ impl LayoutPlanner {
|
|
|
464
467
|
a1,
|
|
465
468
|
style_role,
|
|
466
469
|
indent,
|
|
470
|
+
wrap_text: false,
|
|
467
471
|
},
|
|
468
472
|
);
|
|
469
473
|
}
|
|
@@ -524,11 +528,11 @@ impl LayoutPlanner {
|
|
|
524
528
|
tables: &sheet_tables,
|
|
525
529
|
placements: &sheet_placements,
|
|
526
530
|
grid,
|
|
527
|
-
layout_cells: &layout_cells,
|
|
531
|
+
layout_cells: &mut layout_cells,
|
|
528
532
|
theme,
|
|
529
533
|
evaluated,
|
|
530
534
|
}
|
|
531
|
-
.arbitrate(sheet_max_end_col, &mut col_widths);
|
|
535
|
+
.arbitrate(sheet_max_end_col, &mut col_widths, &mut row_heights);
|
|
532
536
|
|
|
533
537
|
layout_sheets.insert(
|
|
534
538
|
sheet_id.clone(),
|
|
@@ -597,19 +601,24 @@ fn resolve_placement_target<'a>(
|
|
|
597
601
|
})
|
|
598
602
|
}
|
|
599
603
|
|
|
600
|
-
/// Context and
|
|
604
|
+
/// Context and inputs for arbitrating sheet-wide column widths and cell text wrapping across placed tables.
|
|
601
605
|
struct ColumnArbitrationContext<'a> {
|
|
602
606
|
tables: &'a [&'a TableSpec],
|
|
603
607
|
placements: &'a IndexMap<TableId, TablePlacement>,
|
|
604
608
|
grid: &'a CellGrid,
|
|
605
|
-
layout_cells: &'a IndexMap<CellId, PhysicalCoordinate>,
|
|
609
|
+
layout_cells: &'a mut IndexMap<CellId, PhysicalCoordinate>,
|
|
606
610
|
theme: &'a Theme,
|
|
607
611
|
evaluated: Option<&'a EvaluatedModel>,
|
|
608
612
|
}
|
|
609
613
|
|
|
610
614
|
impl ColumnArbitrationContext<'_> {
|
|
611
|
-
/// Arbitrates sheet-wide column widths across all tables sharing worksheet columns.
|
|
612
|
-
fn arbitrate(
|
|
615
|
+
/// Arbitrates sheet-wide column widths, cell text wrapping, and multi-line row heights across all tables sharing worksheet columns.
|
|
616
|
+
fn arbitrate(
|
|
617
|
+
&mut self,
|
|
618
|
+
sheet_max_end_col: u32,
|
|
619
|
+
col_widths: &mut IndexMap<u32, f64>,
|
|
620
|
+
row_heights: &mut IndexMap<u32, f64>,
|
|
621
|
+
) {
|
|
613
622
|
for physical_col in 1..=sheet_max_end_col {
|
|
614
623
|
let has_data_col = self.tables.iter().any(|t| {
|
|
615
624
|
let Some(placement) = self.placements.get(&t.id) else {
|
|
@@ -647,7 +656,7 @@ impl ColumnArbitrationContext<'_> {
|
|
|
647
656
|
let header_len = data_col.max_header_chars();
|
|
648
657
|
table_max_chars = table_max_chars.max(header_len);
|
|
649
658
|
|
|
650
|
-
// 2. Row cells text length
|
|
659
|
+
// 2. Row cells text length and multi-line wrapping
|
|
651
660
|
for row in &table.rows {
|
|
652
661
|
let RowSpec::Data(data_row) = row else {
|
|
653
662
|
continue;
|
|
@@ -660,25 +669,41 @@ impl ColumnArbitrationContext<'_> {
|
|
|
660
669
|
format.and_then(|f| self.theme.number_formats.default_decimals(f))
|
|
661
670
|
});
|
|
662
671
|
let currency = cell_node.and_then(|n| n.currency);
|
|
672
|
+
let indent = self.layout_cells.get(&cell_id).map_or(0, |c| c.indent);
|
|
663
673
|
|
|
664
|
-
let
|
|
674
|
+
let (char_len, lines) =
|
|
665
675
|
match (self.evaluated.and_then(|e| e.get_cell(&cell_id)), cell_node) {
|
|
666
|
-
(Some(val), _) =>
|
|
667
|
-
|
|
668
|
-
|
|
676
|
+
(Some(val), _) => measure_cell_value(
|
|
677
|
+
val,
|
|
678
|
+
format,
|
|
679
|
+
decimals,
|
|
680
|
+
currency,
|
|
681
|
+
indent,
|
|
682
|
+
&self.theme.metrics,
|
|
683
|
+
),
|
|
669
684
|
(None, Some(node)) => match &node.payload {
|
|
670
|
-
CellPayload::Literal(lit) =>
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
685
|
+
CellPayload::Literal(lit) => measure_literal_value(
|
|
686
|
+
lit,
|
|
687
|
+
format,
|
|
688
|
+
decimals,
|
|
689
|
+
currency,
|
|
690
|
+
indent,
|
|
691
|
+
&self.theme.metrics,
|
|
692
|
+
),
|
|
693
|
+
CellPayload::Formula(_) => (usize::from(indent) * 2, 1),
|
|
674
694
|
},
|
|
675
|
-
(None, None) =>
|
|
695
|
+
(None, None) => (usize::from(indent) * 2, 1),
|
|
676
696
|
};
|
|
677
697
|
|
|
678
|
-
if
|
|
679
|
-
&& coord
|
|
698
|
+
if lines > 1
|
|
699
|
+
&& let Some(coord) = self.layout_cells.get_mut(&cell_id)
|
|
680
700
|
{
|
|
681
|
-
|
|
701
|
+
coord.wrap_text = true;
|
|
702
|
+
record_row_height(
|
|
703
|
+
row_heights,
|
|
704
|
+
coord.row,
|
|
705
|
+
(lines as f64) * self.theme.metrics.data_row_height,
|
|
706
|
+
);
|
|
682
707
|
}
|
|
683
708
|
|
|
684
709
|
table_max_chars = table_max_chars.max(char_len);
|
|
@@ -687,11 +712,14 @@ impl ColumnArbitrationContext<'_> {
|
|
|
687
712
|
max_chars_across_tables = max_chars_across_tables.max(table_max_chars);
|
|
688
713
|
}
|
|
689
714
|
|
|
690
|
-
// Apply theme font multiplier and padding,
|
|
715
|
+
// Apply theme font multiplier and padding, clamping to [min_col_width, max_col_width]
|
|
691
716
|
let computed_width = (max_chars_across_tables as f64
|
|
692
717
|
* self.theme.metrics.char_width_multiplier
|
|
693
718
|
+ self.theme.metrics.col_padding)
|
|
694
|
-
.
|
|
719
|
+
.clamp(
|
|
720
|
+
self.theme.metrics.min_col_width,
|
|
721
|
+
self.theme.metrics.max_col_width,
|
|
722
|
+
);
|
|
695
723
|
|
|
696
724
|
let final_width = (computed_width * 100.0).round() / 100.0;
|
|
697
725
|
let existing = col_widths.get(&physical_col).copied().unwrap_or(0.0);
|
|
@@ -700,51 +728,72 @@ impl ColumnArbitrationContext<'_> {
|
|
|
700
728
|
}
|
|
701
729
|
}
|
|
702
730
|
|
|
703
|
-
fn
|
|
731
|
+
fn measure_text_segments(
|
|
732
|
+
s: &str,
|
|
733
|
+
format: Option<FormatPreset>,
|
|
734
|
+
indent: u8,
|
|
735
|
+
metrics: &MetricsConfig,
|
|
736
|
+
) -> (usize, usize) {
|
|
737
|
+
let trailing_pad = usize::from(format == Some(FormatPreset::Text));
|
|
738
|
+
let indent_chars = usize::from(indent) * 2;
|
|
739
|
+
let mut max_chars = 0;
|
|
740
|
+
let mut total_lines = 0;
|
|
741
|
+
|
|
742
|
+
for segment in s.split('\n') {
|
|
743
|
+
let seg_chars = segment.chars().count() + trailing_pad + indent_chars;
|
|
744
|
+
max_chars = max_chars.max(seg_chars);
|
|
745
|
+
let seg_lines = if seg_chars == 0 {
|
|
746
|
+
1
|
|
747
|
+
} else {
|
|
748
|
+
let seg_width =
|
|
749
|
+
(seg_chars as f64) * metrics.char_width_multiplier + metrics.col_padding;
|
|
750
|
+
((seg_width / metrics.max_col_width).ceil() as usize).max(1)
|
|
751
|
+
};
|
|
752
|
+
total_lines += seg_lines;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
(max_chars, total_lines)
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
fn measure_literal_value(
|
|
704
759
|
lit: &ValueLiteral,
|
|
705
760
|
format: Option<FormatPreset>,
|
|
706
761
|
decimals: Option<u32>,
|
|
707
762
|
currency: Option<CurrencyCode>,
|
|
708
|
-
|
|
763
|
+
indent: u8,
|
|
764
|
+
metrics: &MetricsConfig,
|
|
765
|
+
) -> (usize, usize) {
|
|
766
|
+
let indent_chars = usize::from(indent) * 2;
|
|
709
767
|
match lit {
|
|
710
|
-
ValueLiteral::String(s) =>
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
ValueLiteral::Boolean(b) => {
|
|
716
|
-
|
|
717
|
-
4
|
|
718
|
-
} else {
|
|
719
|
-
5
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
ValueLiteral::Null => 0,
|
|
768
|
+
ValueLiteral::String(s) => measure_text_segments(s, format, indent, metrics),
|
|
769
|
+
ValueLiteral::Number(n) => (
|
|
770
|
+
formatted_number_estimate(*n, format, decimals, currency) + indent_chars,
|
|
771
|
+
1,
|
|
772
|
+
),
|
|
773
|
+
ValueLiteral::Boolean(b) => ((if *b { 4 } else { 5 }) + indent_chars, 1),
|
|
774
|
+
ValueLiteral::Null => (indent_chars, 1),
|
|
723
775
|
}
|
|
724
776
|
}
|
|
725
777
|
|
|
726
|
-
/// Computes the
|
|
727
|
-
fn
|
|
778
|
+
/// Computes the horizontal character demand and wrapped line count of an evaluated `CellValue`.
|
|
779
|
+
fn measure_cell_value(
|
|
728
780
|
val: &CellValue,
|
|
729
781
|
format: Option<FormatPreset>,
|
|
730
782
|
decimals: Option<u32>,
|
|
731
783
|
currency: Option<CurrencyCode>,
|
|
732
|
-
|
|
784
|
+
indent: u8,
|
|
785
|
+
metrics: &MetricsConfig,
|
|
786
|
+
) -> (usize, usize) {
|
|
787
|
+
let indent_chars = usize::from(indent) * 2;
|
|
733
788
|
match val {
|
|
734
|
-
CellValue::Text(s) =>
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
CellValue::Boolean(b) => {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
} else {
|
|
743
|
-
5
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
CellValue::Error(e) => e.to_string().chars().count(),
|
|
747
|
-
CellValue::Empty => 0,
|
|
789
|
+
CellValue::Text(s) => measure_text_segments(s, format, indent, metrics),
|
|
790
|
+
CellValue::Number(n) => (
|
|
791
|
+
formatted_number_estimate(*n, format, decimals, currency) + indent_chars,
|
|
792
|
+
1,
|
|
793
|
+
),
|
|
794
|
+
CellValue::Boolean(b) => ((if *b { 4 } else { 5 }) + indent_chars, 1),
|
|
795
|
+
CellValue::Error(e) => (e.to_string().chars().count() + indent_chars, 1),
|
|
796
|
+
CellValue::Empty => (indent_chars, 1),
|
|
748
797
|
}
|
|
749
798
|
}
|
|
750
799
|
|
|
@@ -120,8 +120,12 @@ pub fn lower_table_ref(
|
|
|
120
120
|
crate::compiler::graph::error::ResolveError::unknown_table(origin, origin.table.clone())
|
|
121
121
|
})?;
|
|
122
122
|
|
|
123
|
-
let
|
|
124
|
-
|
|
123
|
+
let resolved_table_id = target_ref.table.resolve(&origin.table);
|
|
124
|
+
let target_table = symbol_table.get_table(resolved_table_id).ok_or_else(|| {
|
|
125
|
+
crate::compiler::graph::error::ResolveError::unknown_table(
|
|
126
|
+
origin,
|
|
127
|
+
resolved_table_id.clone(),
|
|
128
|
+
)
|
|
125
129
|
})?;
|
|
126
130
|
|
|
127
131
|
let origin_coord =
|
|
@@ -138,19 +142,19 @@ pub fn lower_table_ref(
|
|
|
138
142
|
|
|
139
143
|
let first_row = rows.first().ok_or_else(|| LoweringError::EmptyRange {
|
|
140
144
|
origin: origin.clone(),
|
|
141
|
-
target_table:
|
|
145
|
+
target_table: resolved_table_id.clone(),
|
|
142
146
|
})?;
|
|
143
147
|
let last_row = rows.last().ok_or_else(|| LoweringError::EmptyRange {
|
|
144
148
|
origin: origin.clone(),
|
|
145
|
-
target_table:
|
|
149
|
+
target_table: resolved_table_id.clone(),
|
|
146
150
|
})?;
|
|
147
151
|
let first_col = cols.first().ok_or_else(|| LoweringError::EmptyRange {
|
|
148
152
|
origin: origin.clone(),
|
|
149
|
-
target_table:
|
|
153
|
+
target_table: resolved_table_id.clone(),
|
|
150
154
|
})?;
|
|
151
155
|
let last_col = cols.last().ok_or_else(|| LoweringError::EmptyRange {
|
|
152
156
|
origin: origin.clone(),
|
|
153
|
-
target_table:
|
|
157
|
+
target_table: resolved_table_id.clone(),
|
|
154
158
|
})?;
|
|
155
159
|
|
|
156
160
|
let is_row_range = target_ref.row.is_range();
|
|
@@ -161,7 +165,7 @@ pub fn lower_table_ref(
|
|
|
161
165
|
let (start_row_dyn, end_row_dyn) = target_ref.row.dynamic_bounds();
|
|
162
166
|
|
|
163
167
|
let top_left_id = CellId::new(
|
|
164
|
-
|
|
168
|
+
resolved_table_id.clone(),
|
|
165
169
|
first_row.clone(),
|
|
166
170
|
first_col.clone(),
|
|
167
171
|
);
|
|
@@ -177,8 +181,11 @@ pub fn lower_table_ref(
|
|
|
177
181
|
let end_pinned =
|
|
178
182
|
range_endpoint_pinning(end_col_dyn, end_row_dyn, pin_static_col_on_dynamic_row);
|
|
179
183
|
|
|
180
|
-
let bottom_right_id =
|
|
181
|
-
|
|
184
|
+
let bottom_right_id = CellId::new(
|
|
185
|
+
resolved_table_id.clone(),
|
|
186
|
+
last_row.clone(),
|
|
187
|
+
last_col.clone(),
|
|
188
|
+
);
|
|
182
189
|
let bottom_right_coord =
|
|
183
190
|
layout_map
|
|
184
191
|
.cells
|
|
@@ -166,11 +166,58 @@ impl fmt::Display for UnaryOp {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/// Target table selector within a table reference.
|
|
170
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
171
|
+
pub enum TableSelector {
|
|
172
|
+
/// Active evaluation table: `@table`.
|
|
173
|
+
Active,
|
|
174
|
+
/// Explicit table identifier: `IncomeStatement`.
|
|
175
|
+
Key(TableId),
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
impl TableSelector {
|
|
179
|
+
/// Resolves the selector against the origin table ID.
|
|
180
|
+
#[must_use]
|
|
181
|
+
pub const fn resolve<'a>(&'a self, origin_table: &'a TableId) -> &'a TableId {
|
|
182
|
+
match self {
|
|
183
|
+
Self::Active => origin_table,
|
|
184
|
+
Self::Key(id) => id,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
impl From<TableId> for TableSelector {
|
|
190
|
+
fn from(id: TableId) -> Self {
|
|
191
|
+
Self::Key(id)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
impl From<&str> for TableSelector {
|
|
196
|
+
fn from(s: &str) -> Self {
|
|
197
|
+
Self::Key(TableId::from(s))
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
impl From<String> for TableSelector {
|
|
202
|
+
fn from(s: String) -> Self {
|
|
203
|
+
Self::Key(TableId::from(s))
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
impl fmt::Display for TableSelector {
|
|
208
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
209
|
+
match self {
|
|
210
|
+
Self::Active => write!(f, "@table"),
|
|
211
|
+
Self::Key(k) => write!(f, "{k}"),
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
169
216
|
/// Reference addressing target to a table.
|
|
170
217
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
171
218
|
pub struct TableRef {
|
|
172
|
-
/// Target table
|
|
173
|
-
pub table:
|
|
219
|
+
/// Target table selector.
|
|
220
|
+
pub table: TableSelector,
|
|
174
221
|
/// Row coordinate selector.
|
|
175
222
|
pub row: RowSelector,
|
|
176
223
|
/// Column coordinate selector.
|
|
@@ -179,7 +226,7 @@ pub struct TableRef {
|
|
|
179
226
|
|
|
180
227
|
impl TableRef {
|
|
181
228
|
/// Constructs a table reference: `Table[row, col]`.
|
|
182
|
-
pub fn new(table: impl Into<
|
|
229
|
+
pub fn new(table: impl Into<TableSelector>, row: RowSelector, col: ColSelector) -> Self {
|
|
183
230
|
Self {
|
|
184
231
|
table: table.into(),
|
|
185
232
|
row,
|
|
@@ -59,9 +59,9 @@ pub enum ParseError {
|
|
|
59
59
|
offset: usize,
|
|
60
60
|
},
|
|
61
61
|
|
|
62
|
-
/// Bare '@' was encountered instead of '@col' or '@
|
|
62
|
+
/// Bare '@' was encountered instead of '@col', '@row', or '@table'.
|
|
63
63
|
#[error(
|
|
64
|
-
"Bare '@' at offset {offset} is retired; specify active
|
|
64
|
+
"Bare '@' at offset {offset} is retired; specify active coordinate explicitly using '@col', '@row', or '@table'"
|
|
65
65
|
)]
|
|
66
66
|
RetiredBareAt {
|
|
67
67
|
/// Byte offset in the formula string.
|