* PivotTables: Distinct Count as a value summary (#3336)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Pivot: refuse Distinct Count for calculated fields
A calculated field is evaluated on the report totals, so there are no
per-record values to count. pivot.addField and pivot.valueSettings now reject
the combination.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* PivotTables: do not offer Distinct Count for a calculated field in the field menu
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* fix(xlsx): keep pivot Distinct Count through a save (#3336)
SpreadsheetML has no distinct-count subtotal, so a Distinct Count value
field is still written as subtotal="count", now with a GridCraft dataField
extension that reads back as Distinct Count. A field with Rank as well
gets both extensions. The cache of such a PivotTable is written without
refreshOnLoad, so Excel opens it showing the computed distinct counts on
the sheet; a manual Refresh in Excel recomputes the field as Count.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* PivotTables: tell the user on .xlsx export that Distinct Count is read only by GridCraft (#3336)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* PivotTables: disclose a new Distinct Count field on an ordinary Save too (#3336)
The notice no longer depends on the save path being new: the document remembers which
Distinct Count value fields an .xlsx save already reported.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* i18n: translate the Distinct Count strings in every catalog (#3336)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: skylartaylor <skylartaylor@users.noreply.github.com>
* Searchable validation dropdown lists
* double dropdown bug solved
* performance improvements for dropdown list filtering
* docstrings and documentation added
* precisions regarding accented characters for dropdown list search
* Latin extended characters added to accent list in dropdown list search
* formula bar check button handled as enter for highlighted entry
* capping list at 10,000 entries
* Bound the searched validation list's source work
A searched list (data.validationList, and the edit that typing into a list
cell opens) read its whole source first: a whole-column list evaluated every
cell into an array and folded each entry, so a search with few or no matches
could still stall the UI. The search now reads at most LIST_SOURCE_BUDGET
(200,000) cells of the source: a range is walked cell by cell instead of
evaluated, a computed source gets the budget as its formula work, and
`truncated` reports when the source was cut short. The popup says when
entries aren't shown. The validation membership check still reads the
whole list.
* Bound the dropdown arrow's validation list
The full list that the dropdown arrow or Alt+Down opens called list_items
every frame while it was open and drew a button for every entry, so a list
over a huge column reread its source and laid out all of it on each repaint.
It now reads the list once with list_search_source (within
LIST_SOURCE_BUDGET), keeps it while the popup stays open on the same cell of
the same workbook version, and draws only the rows in view, saying when
entries aren't shown. Rows are measured at their real button height, so the
popup shows the eight rows it was meant to (it showed six).
* Dropdown list fixes
1. Row height: the search popup now measures its rows at the real button height, through a helper shared with the arrow picker. It shows eight rows, the highlight stays in view and the end of a long list is reachable.
2. Duplicate call: the second e.update_list() in control.rs is gone.
3. Stale cache: list_picker_items is cleared wherever list_picker is cleared for an edit (start_edit and the editor branch of list_picker).
4. Translation: "More entries not shown" is one constant and goes through lang.tr(...) in both popups. I did not add catalog entries, so it still shows in English in every language until translations are written.
5. Flip above: the search popup opens above the cell when it would run past the bottom of the window, using the same rule as the arrow picker.
6. Width: the popup width is measured once per search and cached in ListSearch::text_width; update_list resets it.
* Validation lists: fixed-height rows, translated cut-short note
The rows of both validation list popups are drawn in slots of exactly the
height the popup scrolls by. A button sizes itself to its laid-out text,
which can be a pixel taller than the font's nominal line height, so the
last visible row ran under the "More entries not shown" note with the
pinned test fonts (the CI gate failure).
The note is translated in all 18 interface catalogs, with a test that no
catalog falls back to English.
The validation-list UI tests move into the shared integration binary and
use the pinned font harness, so they no longer depend on host fonts.
* Validation list note: use each catalog's word for list items
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: skylartaylor <skylartaylor@users.noreply.github.com>
* engine, model: one workbook-wide reference rewrite; rule formulas follow their ranges
Workbook::rewrite_references(&dyn Fn(RefHost, Expr) -> Expr) is the single
walker over every place a workbook holds a reference: cell formulas (keeping
array range and spill kind), defined names, conditional formats, validation,
in-workbook links, chart series and sources, sparklines and PivotTable
sources. Sheet rename and delete, defined-name and table rename, row/column
and cell insert/delete and cut-paste all go through it instead of their own
lists of holders, so a rename now also reaches pivot sources, rules and
validations; inserting rows above a rule moves its formulas; deleting a sheet
makes rule/validation references #REF! and no longer turns legacy arrays into
spills; table rename keeps legacy arrays. A copied sheet's charts plot the copy.
Conditional-format and validation formulas are re-hosted by how their ranges
moved (rehost_rule, CfRule::relative_formulas_mut/formulas_mut,
Validation::formulas_mut): deleting a rule's first row no longer makes it
#REF!, ranges moved whole or left in place keep their formulas, thresholds are
read as written. A cut takes rules with its cells (Rule trait,
remove_rule_cells, moved_rule_parts) and moves their references once.
A sheet-qualified name splits at its last '!' when a sheet is renamed.
* engine, model: review fixes for the workbook-wide reference rewrite
- rehost_rule takes the rule's top-left from all its ranges before the edit,
so removing the range that held it (deleting its rows or cells) re-hosts
the formulas instead of leaving #REF!.
- Internal hyperlink targets are no longer rewritten: they keep the place they
name as typed, as main and Excel do.
- A cut can't be transposed or tiled by Paste Special (as in Excel); its rules
and references followed the block unturned.
- rewrite_references copies a sheet only when something on it changes, so
untouched sheets stay shared with undo snapshots.
- docs/architecture.md: revision row moved under Revision history; section
updated.
* engine, model: re-review touch-ups for the reference rewrite
- The multi-area rehost test checks deleting the first area's cells both
shifting up and shifting left (the comment said up, the test did left).
- rewrite_references checks rules, validations, charts, sparklines and pivots
on the borrowed sheet and copies a list only when something in it changes
(CfRule::formulas, Validation::formulas, read-only). A chart source already
holding #REF! is dropped by any rewrite again.
* engine, model: round-2 review fixes for the reference rewrite
- A cut to another sheet names the source sheet in all of a conditional format's formulas,
thresholds included: a colour scale's, data bar's or icon set's threshold formula kept
reading the destination sheet's cells.
- A chart series name that is a bare word and not a defined name is a label, as the chart
reads it: renaming a table of that name no longer rewrites it. Renaming a defined name
rewrites formulas before the old name is dropped, so a series named by it still follows.
- The walker's doc no longer lists deleting names among the edits that go through it; a test
comment says what it checks.
* engine, model: round-3 review fixes for the reference rewrite
- A chart series name is left as written unless the chart reads it as a reference: it starts
with `=`, names a sheet, or is a defined name its own sheet sees. A name scoped to another
sheet, or a label shaped like a cell (`Q1`), is no longer rewritten (corrects round 2's
check, which looked at names in every scope and only exempted bare words).
- A chart source block is dropped as gone only when its formula holds `#REF!`, not its text:
a sheet may be named `#REF!`.
- Defined names are handed to the rewrite on `NAME_HOST` (`[]`), which no sheet name can be,
instead of a NUL that a sheet could be renamed to.
- The walker's doc and docs/architecture.md list a PivotChart's link and a slicer's table
among what it does not visit.
* engine: Move Columns takes its columns' rules along as a cut does
A conditional format or validation wider than the moved columns was left in place by the
move step while its formulas were moved as references into the block, so the cells left
behind checked the wrong column and the moved column lost the rule. Move Columns now moves
the rules' parts in the moved columns as Cut and Paste does (`move_cut_rules`), and the rest
of the rule re-hosts from its new top-left cell.
* engine: round-5 review fixes for the reference rewrite
- Move Columns moves its rules before the columns' features shift (corrects round 4): moved
left, a rule whose whole range was in the moved columns was shifted, re-hosted and then
re-hosted again from mixed positions, so the parts left behind checked the wrong column.
- Copying a sheet keeps a chart's series and source text as written unless it names the
copied sheet: a series name `=A1` lost its `=` and was read as the label "A1".
- Docs and comments say what the code does: `move_cut_rules` serves Move Columns too,
`rewrite_all_formulas` and `rename_name_in_formulas` point at the walker, and
docs/architecture.md names Move Columns; `sheet_rename_renames_a_pivot_source` is named for
what it checks.
* docs: architecture: a rule's one formula across a partial shift of its cells
A conditional format or validation keeps one formula for all its cells, so an insert or
delete inside its range, or Move Columns across it, leaves relative references at the
cells on the far side of the shift reading where the top-left cell's reference puts them.
* engine: review fixes for the reference rewrite (CodeRabbit)
A cut moves the rules its cells hold when it is pasted, not the clipboard
snapshot's: a rule cleared after the cut came back at the destination.
A table rename leaves a bare name in a workbook name alone when a
workbook-level defined name of that name exists, as it does in cells.
* engine: a cut is not pasted skipping blanks
A cut's rules replace the destination's under the whole block, so a
Skip Blanks paste of it dropped validation under the cells it left
alone. Paste Special now refuses Skip Blanks for a cut, as it already
refuses Transpose and tiling (Excel offers none of them for a cut).
* table.rename: a PivotTable table source follows even when a defined name shadows it
A bare pivot source binds to the table before a defined name, so the
shadowing that keeps formula names on the defined name does not apply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* model: rewrite_references keeps a chart source that was already broken
Only a source the edit breaks is dropped. A source already #REF! (from a
file or an earlier edit) stays as it was through an unrelated edit, such
as renaming a defined name it does not use.
* paste: a cut moves on its sheet as it is named now
A cut whose source sheet is renamed before the paste rebased its moved
rules, and the references to its cells, against the name the clipboard
saw, which no longer exists. A cut in the same workbook now uses the
live sheet name.
* formulas: renaming a defined name leaves LET and LAMBDA locals alone
The rename walk now tracks the locals in scope: a LET or LAMBDA local of
the old name is not the defined name and keeps its name, and a rename
that a local of the new name would capture is refused and changes
nothing. It is the one walk for cells, names, rules and Python cells.
* formulas: a name rename renames calls to it and is refused where a sheet name would take it
A call to a defined LAMBDA by name (`FnOld(4)`) now follows a rename of
the name; a called LET or LAMBDA local of the old name stays as it is.
A workbook name renamed to a name a sheet defines for itself would be
read as that sheet's name there, so that rename is refused.
* paste: a cut is refused as Paste Link or into filtered-out rows before its source is cleared
Paste Link would write links to the cells the cut empties, and a
destination in rows the filter hides would skip every cell the cut
writes; both lost the cut cells.
* sheets: a pending cut ends when a sheet edit puts another sheet in its place
A cut names its sheet by its place among the tabs, so after inserting,
deleting or moving a sheet before it, a paste took cells and rules from
whichever sheet had that place. The cut now ends when its place holds
another sheet (or none); a cut whose sheet kept its place stays, and a
copy reads its own snapshot and stays.
* model: a sheet-level name's references are rewritten on its own sheet
Unqualified references in a sheet-level name are read on its scope
sheet, so rewrite_references now hosts them there: inserting a row
above one moves it, as it moves a cell formula on that sheet.
Workbook-level names keep NAME_HOST.
* model: a PivotTable source that names a table is left out of a name's rewrite
A bare source that is a table's name reads the table before a defined
name of that name, so renaming the defined name no longer moves the
PivotTable off its table.
* sheet: a rule follows its top-left cell through a partial cell delete or insert
Deleting cells in only the first column of a rule's range keeps the
range's size, so it was treated as moved whole and its formulas stayed
written for the deleted cell (=A1>0 became =#REF!>0). When the cell the
shift puts at the top-left was one of the rule's own cells, the
formulas now follow it.
* sheet.moveColumns: a moved column's part of a rule reads what the column read
The moved part was taken after the columns were made room for, when the
rule's formula (written for its top-left) no longer said what the moved
cells read: a rule on B1:D1 testing =A1>0, with D moved before B, left
the moved cell testing old B instead of old C. The parts are now taken
from the sheet before the insert and follow it as the cells' formulas
do. move_cut_rules' placing half is place_moved_rules, shared.
* tests: the broken-chart-source test rewrites the chart it checks
A series now reads the renamed name, so the rename takes the branch that
rewrites the chart, and the test checks the series changed while the
broken source stayed.
* Revert "sheets: a pending cut ends when a sheet edit puts another sheet in its place"
This reverts commit 1569394173.
* Revert "paste: a cut is refused as Paste Link or into filtered-out rows before its source is cleared"
This reverts commit 80e7525d29.
* Revert "formulas: a name rename renames calls to it and is refused where a sheet name would take it"
This reverts commit c2ff358b58.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Charts: series drawn and saved by their own kind; XLSX groups per drawn kind
Chart::series_kind is the one rule for the kind each series is drawn as: in a
combo its own kind (the first a column and the rest lines by default; bars
stand upright as columns), elsewhere the chart's kind, keeping a line's own
markers or a scatter's own lines (same_family). The renderer, legend, data
table and trendline eligibility all ask it; chart.set drops the series kinds a
new type doesn't draw.
The XLSX writer writes one group per drawn kind on each axis (areas, stacked
columns kept), axes of the kind those groups need, a one-kind chart's
secondary series on their own axes, and a stock group only for 3 or 4 series.
The reader keeps each series' markers and lines, treats groups of one family
as one chart, takes the primary axes from the value axis on the left or
bottom, and orders series by c:order.
* XLSX charts: one pie group, one group per type per axis pair, scatter markers kept
Review fixes for the per-kind chart groups:
- Pies and doughnuts have no axes: series marked secondary stay in the one
group, so a combo turned into a doughnut no longer writes two doughnuts.
- One group per type on a pair of axes, as Excel keeps them: clustered and
stacked columns (lines and stacked lines, areas and stacked areas) share the
first one's grouping instead of writing two groups on the same axes.
- A markers-only scatter (or bubble) series drawn among lines keeps its markers.
- chart-parity.md: the revision row moves under Revision history.
* Charts: one grouping per type and axis pair, drawn as saved; combo pies as columns
Second review round for the per-kind chart groups:
- Chart::series_kind gives the series of one type (columns, lines, areas) on
one pair of axes in a combo the first one's grouping, as the XLSX writer
saves them, so a stacked column beside clustered ones no longer un-stacks
after save and reopen. Chart::series_kinds computes them in one pass.
- A combo's pies and doughnuts are drawn as columns (as the renderer does);
only a chart without axes ignores secondary flags, so a combo with a
secondary pie keeps its primary axes and writes the pie where it is drawn,
and a pie + doughnut combo is one column group.
- Groups that fit the axes come before groups moved onto them, and each
group writes its series in their own order.
- The unreachable bubble arm in series_xml is gone.
* Charts: combos drawn and saved on category axes; data tables by series_kinds
Third review round for the per-kind chart groups:
- A combination chart is drawn on category axes, so Chart::series_kind gives
its scatter and radar series as lines (a markers-only scatter with markers)
and its bubbles as columns, as the renderer draws them; the XLSX writer uses
category axes for every combo, so a scatter or bubble series first no longer
turns the other series into scatter series.
- supports_data_table uses series_kinds (one pass, it runs every frame).
- A same-family kind left in an older JSON workbook is drawn, tested and
documented rather than migrated: it can't be told from a file's own.
* Charts: combo chartex series as columns; empty charts survive XLSX; a new type applies to every series
- `combo_series_kind` draws a combo's histogram, waterfall, funnel, treemap, sunburst and box &
whisker series as clustered columns, as the XLSX writer already saved them: their grouping,
combo-ness and data-table support no longer change on reopening.
- The XLSX writer writes one empty group of the chart's kind (a line group for stock) when a
chart has no series, so the chart is read back rather than dropped.
- The XLSX reader looks the value axes' positions up in a map built once; a file with many
chart groups took quadratic time to read.
- `chart.set` with a new type (other than a combo) clears every series' own kind, so choosing a
type applies it to every series again (a file's markers no longer outlive a type change);
setting the type a chart already has drops only the kinds it does not draw.
- docs/chart-parity.md: combo scatter series are lines with markers, and only stock series
beside stacked lines are still saved stacked but drawn unstacked.
* Charts: one model rule reads per-series kinds back; empty charts keep their kind in XLSX
- `Chart::set_drawn_kinds` sets a chart's kind and its series' own kinds from the kinds a file
draws each series as (one family: the first's kind, a series keeping its own only where it
differs; otherwise a combo). The XLSX reader now uses it, so an ODS reader can share the rule
instead of copying it.
- An empty line group writes `c:marker val="0"` when the chart has no markers, and an empty
scatter group `scatterStyle val="marker"`: an empty Line chart no longer reopens with markers,
an empty Scatter chart no longer with lines, an empty stock chart as a Line chart. The test
now checks the kind read back; the previous commit's test listed Waterfall, which goes
through the column writer there and proved nothing (empty chartex charts are still not kept,
as before this branch; documented).
- `drop_foreign_series_kinds` is removed: since the previous commit, `chart.set` clears every
series' kind on a change of type, and the helper only ran when the same type was set again,
where `series_kind` already ignores kinds outside the chart's family.
- `series_kind`'s doc states the combo conversions and the same-family rule; the combo row in
docs/chart-parity.md lists every conversion.
* XLSX charts: an empty group sets neither the chart's kind nor its axes
The reader took the chart's first kind and its primary axes from the first group even when that
group held no series, so a file with an empty bar group before a scatter group read as a scatter
chart whose only series was secondary, with the bar group's axis titles. Empty groups are now
left out when any group has series, and the axis titles come from the primary pair's axes
(found by id, in any order), else the first axis of their kind as before.
* XLSX charts: axis titles from shown axes, by the primary pair's kind
Corrects the previous commit's axis lookup. When a file's only series sit on a pair whose
category axis is deleted, beside an empty group on shown, titled axes, the x title came from the
deleted axis (none) instead of the shown one: a shown axis of a kind is now taken before a
deleted one. And whether the axes are a scatter's two value axes is now decided by the group on
the primary pair, not the first group with series, so a secondary line group listed before a
primary scatter no longer gives the y axis the scatter's x title.
* Charts: the stacked hairline-bar budget test draws stacked columns
Resolved series carry the kind they are drawn as (Chart::series_kind), and the test's data
defaulted every series to clustered columns, so after the merge with main it no longer drew a
stacked chart and passed without testing stacked spans. Its series are now stacked columns.
* Charts: SeriesData::kind says render draws every series by it
* XLSX charts: the many-groups test reaches the axis lookup and is timed
* chart.addElement: trendlines for every series check their kinds in one pass
A combo series' kind looks back for the first series of its group, so
asking it per series was quadratic in a chart with many series. The
all-series path now uses Chart::series_kinds() once.
Test: trendlines_for_every_series_are_checked_in_linear_time (120,000
series: 0.06 s with the fix, 17.8 s without in a debug build).
* xlsx: a lone stock series joins the line group on its axes, keeping its grouping
A stock series too few for a stock group falls back to a line. It used to
be kept in order with the other groups, so when it came first its plain
line group took in the stacked lines after it and saved them unstacked.
The fallback now joins after the other groups, so an existing line group
keeps its grouping; with none, it is still a plain line.
Test: a_lone_stock_series_does_not_unstack_the_lines_beside_it.
* model: set_drawn_kinds stores each combo series's kind as it is drawn
Series of one type on one pair of axes share the first one's grouping
(series_kinds draws and every format saves them so), but set_drawn_kinds
stored the file's kinds as given: a stacked column after a clustered one
on the same axes was kept as stacked while drawn and saved clustered. It
now stores the drawn kind; on the other axes a series keeps its own.
Test: drawn_kinds_of_one_type_share_a_grouping_per_pair_of_axes.
* tests: linear-time chart checks count their work at two sizes instead of timing it
`many_groups_are_read_in_linear_time` and
`trendlines_for_every_series_are_checked_in_linear_time` asserted a four-second
wall-clock bound, which fails on a busy machine and doesn't show how cost grows.
Each now counts the steps its code takes, with a counter that exists only in
tests, at n and 8n, and asserts the larger run did less than 16 times the
smaller one's work (linear is about 8 times, quadratic about 64). The output
checks stay.
- xlsx: a cfg(test) counter of value axes visited while finding the primary
axes.
- model: a `work` counter of series a combo chart's kind lookups visit, behind
a new `test-support` feature (as gridcraft-xlsx has) so engine tests can read
it; engine's dev-dependency enables it. Shipped builds don't have it.
Against the quadratic versions (value axes scanned per group; series_kind
asked per series) the tests fail with 2,886,000 visits against 45,750 and
2,566,398 against 40,798.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Fixes#4655.
Since #3178, the scheduled FreeBSD 15 x86_64 job has failed io::tests::full_sync_tolerates_apple_enotsup with "45 on other Unix". The test assumed errno 45 is never ErrorKind::Unsupported unless the Apple flag is set. That is true on Linux (EL2NSYNC) but not on FreeBSD, where 45 is ENOTSUP and equals EOPNOTSUPP.
Production full_sync_unsupported is already correct on FreeBSD via kind(). This change makes those two unit-test cases follow the host mapping, so Linux still requires a failed save and BSD hosts match production. No production code change.
The FreeBSD aarch64 job only cross-compiles tests; it does not run them, so a green aarch64 leg is not a test pass.
* Shapes: rotation in the model, XLSX and object.move
Shape gains `rotation` (degrees clockwise about its centre, serde
default 0 so older workbooks load). XLSX reads and writes it as the
shape's `a:xfrm rot`. `object.move` takes `rotation` for shapes and
refuses it for charts, pictures and slicers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* UI: select, resize and rotate shapes with a full frame
A selected shape showed no frame, so clicking it looked like nothing
happened; only text boxes drew one. Every selected object now draws
the frame with eight resize handles (corners only on small frames),
and shapes add a rotation handle above the top edge.
- Each handle resizes from its own side; the opposite side stays put.
Shift keeps the aspect ratio on a corner.
- The rotation handle turns the shape; Shift snaps to 15 degrees.
- A turned shape paints, hit-tests and resizes along its own axes.
- Each handle shows the cursor for its direction; the body shows Move.
- Arrow keys nudge the selected object 6 pt (Ctrl/Alt: 1 pt), Escape
deselects it, Enter/F2 edits a text box.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Shape text test: the new rotation field starts at zero
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Shapes: keep flat lines flat, Ctrl+arrow nudges, finite rotation, ink does not rotate
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Shapes: no resize handles on ink, handles act only over cells, arrows follow the screen on right-to-left sheets
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Merge upstream main into fix/shape-select-rotate
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Print rotated shapes and shape text
* Fix rotated PDF regression assertion
* Fix protected rotation and flat-line resizing
* Format shape rotation regression changes
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Fluorine <joseph.anglada92@gmail.com>
#4389, #4390: drag a selected chart's data outline to change its range
A selected chart now outlines its data as Excel does: series names in red,
category labels in purple and the values as one blue block. The values
block has a handle on each corner. Dragging one previews the new block,
and the release points the chart at it as one undo step. Esc cancels.
The new engine command chart.setValuesRange does the move. Each series
keeps its formatting, a wider block adds series and a narrower one drops
them, and names, category labels and bubble sizes that line up with the
block follow it. PivotCharts and series that are not one block are
refused.
#4389: chart data drag review fixes
- Category labels are compared as blocks, so a reference written with a
leading = still counts as the same labels.
- A resize keeps the orientation the series were read in, so a chart
shrunk to one cell per series stays resizable.
- The preview stays while edge scrolling moves the chart off screen.
- A values corner hidden under frozen panes is not a handle.
- The release takes the block from the pointer's last position, even when
it moved in the release frame.
- Esc cancels the drag with Ctrl or Cmd held too.
Each fix has a test that fails without it.
#4389: read a corner drag from the grabbed corner's own cell
A values corner lies on a cell boundary, which belongs to the next row
and column, so a press on the bottom-right corner of A1:A5 read as B6:
releasing where the press was, or dragging straight down the edge of
column A, changed the other axis too. The drag now records the offset
from the press point to the centre of the corner's cell and reads the
pointer through it, so the press point stays in its cell and each whole
cell of movement moves the corner by one.
#4389: snap a dragged chart data edge to the nearest gridline
Reading the pointer from the middle of the grabbed corner's cell let the
grabbed row's height decide when the block moved: with a tall row 5 and
a short row 6, the pointer reached the bottom of row 6 while the block
stayed at A1:A5. Each edge the corner moves now snaps to the gridline
nearest the pointer, so every row and column changes over at its own
middle. A release where the press was still changes nothing, since the
corner lies on its own gridlines, and an edge dropped on its fixed edge
keeps one row or column.
#4389: drop a chart data drag when the chart's data changes under it
A command run between frames (the control channel, a macro) could change
the chart's values block while the button was held, and the release then
put the dragged block over that change. The drag now checks, from the
session, that the chart still plots the block it started from: a move
drops a stale drag, and the release skips it.
XLSX: read, evaluate and write Excel 2010 conditional formats
Excel 2010+ keeps conditional format rules whose formulas refer to
other sheets only in the worksheet's x14:conditionalFormattings
extension, with xm:f formulas and an inline x14:dxf in place of a
dxfId. GridCraft skipped the whole extension with a warning.
Read: x14 cellIs (every operator, one or two formulas), expression,
blanks, errors, duplicate/unique, top 10, above average and time
period rules become ordinary rules, with the inline differential
format (font, fill, border, number format) and priorities that
interleave with the main section's. A data bar's linked extension
(the x14:id of a main-section rule) adds no second rule. Other x14
kinds (data bar settings, x14 icon sets) are skipped with a warning
naming the kind.
Evaluate: cross-sheet references in rule formulas already resolve;
an engine test pins cellIs and expression rules against cells on
another sheet.
Write: a cell-value or formula rule referring to another sheet is
written in the x14 extension ({78C0D931-6437-407d-A8EE-F0AAD7539E65})
with an inline x14:dxf and a unique id; other rules stay in the main
section. The extension shares one extLst with the sparklines (CF
first). Inline number formats get ids styles.xml declares.
XLSX: say which x14 conditional format rules stay in the main section
Colour scale, data bar and icon set rules are always written in the main
section, even when their cfvo formulas refer to other sheets; the parity
docs now say so. (This commit first dropped the
reader's own x14:id linking; after the rebase onto main, main's data bar
linking from #550 is the one path, so only the docs part remains.)
XLSX: correct the x14 conditional format provenance and list skipped kinds
The file that motivated the x14 conditional format work
(watchdog-report.xlsx) was saved by LibreOffice 25.2, not Excel, so
nothing observed in Excel backs the earlier commit's statement that
Excel 2010+ keeps cross-sheet rules only in the extension. MS-XLSX
2.6.27 (CT_CfRule) allows single-sheet references in xm:f but says
nothing about where Excel places such rules; the comments and docs now
say the placement follows the LibreOffice-saved file and Excel's own
is unverified.
MS-XLSX 2.6.27 forbids sheet-range-reference (3-D spans) in xm:f, so a
rule with a 3-D span now stays in the main section.
The parity docs and gaps list name the x14 kinds read (cellIs,
expression, blanks, errors, duplicate/unique, top10, aboveAverage,
timePeriod) and those skipped with a warning and lost on save (data
bars, icon sets, colour scales, containsText, notContainsText,
beginsWith, endsWith).
Styles: differential formats keep their cell protection on save
dxf_xml, which writes both styles.xml dxfs and inline x14:dxf elements, wrote font, number format, fill, alignment and border but never protection, although read_dxf reads it. A rule whose format unlocked or hid cells lost that on save. It now writes protection after border, the order CT_Dxf requires.
XLSX: solid data bars are saved with negatives in the bar colour and no axis, as GridCraft draws them
docs: order parity revision history
docs: record verified x14 conditional format placement
docs: fold the Excel check into the PR's own changelog row instead of a new dated row
docs: the Excel check covered cross-sheet expression rules, not cell-value rules
Fix differential format serialization
Preserve default dxf protection
* Fuzzer: undo checks follow the bounded undo history
The undo history drops its oldest steps past 100 entries or 128 MB of snapshots (#1263). The
command-sequence fuzzer still compared "undo everything" with the episode's starting workbook,
so any episode whose snapshots passed the budget failed with "undoing all N steps doesn't give
back the starting workbook" although undo worked (seeds 104, 110 and 163 at 80 steps: a column
inserted next to whole-column borders, or rows deleted after filling whole columns, each made a
100 MB step).
The harness notices when an undoable command changed the workbook without the history growing,
and then compares with the state before the oldest step still in the history.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fuzzer: undo and redo checks follow the reachable history boundary
Review of #2332. The harness now tracks the oldest state the undo history
can reach instead of a trimmed flag: whenever the history's oldest entry
changes without it emptying in between, the history dropped a step, and
undoing everything stops at the new oldest entry. That boundary is kept
when an edit.undo in the sequence uses up the retained history before the
episode ends, which used to fall back to the episode's start and report a
false undo mismatch.
The redo round trip no longer assumes n undos leave n redo entries: the
redo history is bounded too, so when it dropped the first step undone,
redo is expected to stop at the oldest entry it kept.
---------
Co-authored-by: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Flush a saved workbook to disk before the rename
write_file renamed the temporary file over the workbook without sync_all, so a power loss right after a save could leave an empty or truncated file under the workbook's name. Sync the file before the rename and, on unix, sync the folder after it (best effort).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Tolerate file systems that cannot flush when saving
On Apple targets std's sync_all asks for F_FULLFSYNC, which network mounts refuse with ENOTTY or ENOTSUP. Treat exactly those errors (and ErrorKind::Unsupported) from the temp file's sync as 'cannot flush here' and carry on with the rename, as before the flush was added. All other errors still fail the save.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Treat raw error 25 as unsupported-flush only on Unix
On Windows 25 is ERROR_SEEK, a real failure that must not be skipped.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Save: treat Apple's ENOTSUP from F_FULLFSYNC as unsupported flush
On Apple targets ENOTSUP is 45 and std leaves it uncategorized (only
EOPNOTSUPP, 102, and ENOSYS map to ErrorKind::Unsupported), so a volume
refusing F_FULLFSYNC with ENOTSUP failed the save and deleted the
temporary file. The raw code is now matched on Apple targets only;
elsewhere 45 is a different errno and stays a failed save. The check is
split into a platform-parameterised helper so each platform's codes are
tested on any host, plus an Apple-only test on the real helper.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
* Sort: Custom Sort dialog redesign
* Sort: keep the dialog on its worksheet and open when sorting fails
* Improve custom sort dialog and localisation
Localise sort controls and adapt their layout to translations. Track worksheets by identity, restore selections across sheet changes, and allow additional levels to reuse columns.
* Fix sort dialog worksheet and input handling
Open Sort on the requested worksheet, reject invalid ranges, and close any open filter menu so Enter confirms the sort. Add regression tests for each case.
* Functions: GETPIVOTDATA (#284)
The engine records each PivotTable report value cell (value field,
row/column items, value) on refresh and when a workbook is opened;
GETPIVOTDATA is an evaluator special form that looks the value up by
value field and field/item pairs, #REF! when the report doesn't show it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* GETPIVOTDATA: shared lazy index, report values, hash lookup (review of #290)
- PivotTable::data_index is an Arc-shared PivotLookup (serde-skipped), so the
per-command workbook clone no longer copies the index; refresh sets it, clear resets it.
- No index work on open: the first GETPIVOTDATA on a pivot without one builds it from the
source via the engine-registered PIVOT_INDEXER; a failure is #REF!, not an empty index.
- The result is the value the sheet shows at the cell's report position, so formula and
report cell agree (test with a source edited after the last refresh).
- Lookup by a pre-lowercased hash key; numbers/booleans fall back to a scan on a miss.
- GETPIVOTDATA is no longer volatile: it depends on its pivot's whole report area.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* GETPIVOTDATA: keep the index of the stored report; collision-free keys; align estimates
The lookup index describes the report as last refreshed and is saved with
the pivot. A pivot loaded without one (XLSX) only builds it when the
recomputed layout matches the stored labels. Lookup keys are length-prefixed
and distinguish Boolean from text items. Function-parity estimates match.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* pivot: import PivotDataCell, PivotItemRef and PivotLookup explicitly after upstream dropped the glob import
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* pivot: add an ignored measurement of edits on a sheet with a large report
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* pivot: keep a failed lazy GETPIVOTDATA build retryable, never save an empty index
A failed lazy index build stored unwrap_or_default() into the shared,
first-set-wins PivotLookup, so a valid state coming later (undo, a
source fix, a reopen) could never rebuild it, and the empty list was
saved as a restored index. Cache only validated builds, treat an empty
list as no index in serialization, reject reports with more value
cells than the index cap instead of truncating, register the pivot
indexer in gridcraft-cli check, and add two regression tests.
* GETPIVOTDATA: move cached offsets with edits inside the report; exact numeric items first
Inserting or deleting rows or columns inside a report remapped the cells
and last_range but kept the cached value-cell offsets, so a lookup could
read another item's cell. shift_sheet_features now maps each indexed
cell through the edit into a new index (the shared one stays with the
undo snapshots); a value cell deleted with its line drops out (#REF!).
A numeric item was accepted on a formatted-label hash hit, so 0.6 and 1
both shown as "1" returned the first. A number now prefers the cell
whose item has exactly that value, before any label match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fix pivot chart test for the new Output.data field
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Native JSON workbook: golden bytes before the move to craft-libs
A workbook with text, numbers, a formula, bold, a number format and a macro is
saved as native JSON. Its bytes, the bytes saved after a newer-format macro is
kept, and the error for a non-workbook file are golden files written by the
current code. Opening the golden file as .json and .scjson and saving it again
gives it back.
* Native JSON workbook: read and write through craft-gridcraft-format
The `.json`/`.scjson` extension check, the reader and its error text, and the
pretty writer with newer-format macros written back into `macros` now come from
craft-gridcraft-format (storytold/craft-libs#1749), pinned at its PR tip. The
Workbook model, the style-index and cell-band rebuilds after a read, and macro
reading and checks stay here.
The golden tests from the previous commit pass unchanged.
Part of storytold/craft-libs#778.
* Native JSON workbook: pin craft-gridcraft-format to the craft-libs merge commit 9a6d8942 (storytold/craft-libs#1749)
---------
Co-authored-by: FredApps <FredApps@users.noreply.github.com>
#2483 lets a spill that already exists keep its cells, but when both
anchors held a spill, reading order decided: an array growing into a
neighbour's spill took its cells, in automatic calculation and after a
full recalculation. Excel keeps the cells the neighbour owns.
Standing now also remembers the area each anchor that held a spill
filled before the calculation. For each contested cell the anchor whose
spill held it keeps it; otherwise #2483's rules apply as before.
With the xlsx reader restoring each dynamic array's saved area, a
reopened workbook keeps its layout too, so both known limits documented
on Standing are gone. Tests now covered by #2483 are dropped, and its
grow-and-back test asserts the blocked grower.
**Stacked on #940.** It contains all of #940 (Arabic shaping in PDF) and adds cell direction and right-to-left sheet geometry (`M12.AR5`). Review the [diff against #940's branch](https://github.com/Mouhand-Kaddo/gridcraft/compare/fix/arabic-pdf-text...fix/arabic-pdf-reading-direction); once #940 merges, this PR is up to date with it.
## Summary
PDF export now honors cell Context, Left-to-Right and Right-to-Left settings. Wrapped lines keep their paragraph direction. Right-to-left sheets place columns, repeated headings, merged cells and objects in the same order as the grid, and explicit Left and Right alignment stay on the side the grid shows them.
```diff
PDF export
- infer each line separately; place every sheet left to right
+ preserve cell direction across lines; mirror RTL sheet positions
+ reject oversized text before appending an incomplete PDF block
```
Depends on #940 (Arabic PDF glyphs). The cell reading direction it reads landed with #947.
## Evidence
- **Before:** PDF ignored explicit reading order and RTL sheet layout. A public size-limit probe returned a PDF with an unmatched marked-content block.
**After:** Direction, wrapped paragraphs, numeric brackets, RTL columns, headings, objects, clipping and sparklines have focused regressions. The same size-limit probe returns an error; its regression failed before the fix and passes afterward.
- At the current head, with Noto Sans Arabic installed and no `CRAFT_FONTS_DIR`: the `gridcraft-pdf` and `gridcraft-engine` tests, workspace clippy and fmt pass. The full `cargo xtask ci` with the craft-fonts bundle relies on the hosted gate.
- Poppler rendering inspected for LTR and RTL sheets. Bounding boxes confirm reversed column positions; logical Arabic strings remain searchable. No physical printer test.
## Merge Danger
**Door:** Two-way. Revert the commit to restore prior export behavior.
**Blast Radius:** PDF. Explicit cell direction is shared with XLSX persistence. Latin text retains the standard-font path, including forced RTL numeric text without an Arabic font.
## Summary
Arabic text reached the PDF writer intact, then WinAnsi encoding replaced its characters with question marks. This fixes#923 through the shared PDF text path, including cells, headers and chart labels.
```diff
PDF text
- encode Arabic through WinAnsi
+ shape with harfrust and Unicode bidi
+ embed licensed glyph outlines with matching weight coordinates
+ preserve logical source using ToUnicode and ActualText
+ fall back to the standard and CID fonts for characters the Arabic face lacks
```
Font binaries stay in the optional craft-fonts build input. Native unbundled builds can use installed Noto Sans Arabic. Explicit cell reading-direction integration follows separately.
**Web build:** shaped Arabic on web needs the bundled craft fonts. The current release workflow doesn't enable `web-craft-fonts`, so until a maintainer enables it, web sets Arabic in the CID font, as main does today, which has no Arabic glyphs, and shows a message that no Noto Sans Arabic face was found. The same applies to a desktop without Noto Sans Arabic, and to bold Arabic where only the regular face is installed.
## Evidence
- **Before:** Arabic exported as `?` (#923, v0.6.1); main now sets it in the CID font, which has no Arabic glyphs, so readers show blanks or boxes.
**After:** native and bundled exports show joined letters, marks, Western/Arabic digits, bold/italic, wrapping, rotation and chart labels. Fresh `pdfinfo`, `pdffonts` and `pdftotext -bbox` checks accept the files; eight original Arabic strings match extracted logical text exactly.
- At the current head, with Noto Sans Arabic installed and no `CRAFT_FONTS_DIR`: the `gridcraft-pdf`, `gridcraft-engine` and `gridcraft-xlsx` tests, clippy, fmt, layers, assets, parity and the wasm check pass. The full `cargo xtask ci` with the craft-fonts bundle relies on the hosted gate.
- Characters the Arabic face lacks (emoji, Cyrillic) are set like non-Arabic text, and without an Arabic face for the text's weight Arabic takes the CID path main uses, with one message per export. Only a broken font or a size limit fails the export. Size limits cover text, glyph subsets, outlines and page content.
## Merge Danger
**Door:** two-way
**Blast Radius:** printing
`PdfDoc::finish` now returns a Result and every caller handles it. Latin-only rendering stays on its existing path. This is a glyph-outline PDF solution; platform printer and physical screen-reader behavior are not claimed.
## What
When two array formulas want the same cells, the one that already has its spill keeps them, whichever anchor comes first (this is what Excel does, measured on this PR by Harrison-Booth). The other formula shows `#SPILL!` until the winner is cleared, then it spills. When neither has a spill yet (a first calculation with no remembered layout), the anchor first in reading order (row, then column) wins, so the result never depends on evaluation order.
Before, an incremental recalculation let the existing spill keep its cells, while a full recalculation laid everything out from scratch and gave them to the earlier anchor. The two disagreed. A full recalculation now starts from the layout the sheet held, so both agree.
Also fixed: clearing a spilling formula did not unblock an array blocked by its old area when that array sat below or to the right of it.
## Why
Issue #2480: on the sales sample, `cell.set C14 =TRANSPOSE(B18:B24)` followed by `range.fill =D14:E18` over E13:F13 left F13 as `#SPILL!` in memory but `0` after a full recalc (the fuzzer, `command_sequence_fuzz` seed 0, hits this on #795). Now C14 keeps its cells, F13 is `#SPILL!`, and a full recalc gives the same.
Known limits: the xlsx reader does not restore spill layouts, so a workbook opened from a file is laid out by reading order only (Excel keeps the layout the file records); and when both anchors already held a spill and one grows into the other, reading order decides (Excel keeps the cells the other owns). The rule is documented on `Standing` in `crates/calc/src/recalc.rs`.
## Test
In `crates/engine/src/tests.rs`: the two-command sequence from the issue; both entry orders of an overlap, plus clearing the winner; and a no-history layout, where the earlier anchor wins in both entry orders. All compare cells with a full recalc.
## How verified
- `cargo fmt --check`, `cargo clippy -p gridcraft-calc -p gridcraft-engine --all-targets -- -D warnings`, `cargo test -p gridcraft-calc -p gridcraft-engine` (includes the fuzz test): all pass.
Fixes#2480
In a descending custom-list key a blank tied with values not in the list,
which come first, while it still went after the listed values, so the order
depended on the input. It now goes last.
Comparing two values not in the list changed descending custom-list keys too:
they no longer tied, so a later key could not order them. Only an ascending
key sorts them now; with a descending one they tie, as before.
Repeating a copy down a selection narrower than it writes the copy's width on
every row, so the 4,000,000-cell limit on a tiled paste now counts that area
rather than the selection's. Past it the copy is pasted once, as a tiled
paste over too large a selection already is.
Data Subtotal grouped each group's detail rows at level 1 and left the
subtotal rows at level 0, so outline level 1 still showed every
subtotal. Excel adds an outer group over all data and subtotal rows,
summarised by the grand total: details at level 2, subtotals at
level 1, the grand total at level 0. Subtotal now adds that group after
writing the grand total.
Two tests that read the old levels now expect Excel's: the summary-row
test shows level 2 to keep the subtotal visible, and the sheet-prefix
test expects a detail row at level 2.
Paste tiled the copy only over a selection whose height and width were
both multiples of the copy's. A row copied into a narrower selection
several rows tall (A1:B1 into A3:A6) was pasted once. Excel repeats it
down every row of the selection at the copy's width. A selection
narrower than the copy now tiles down when its height is a multiple of
the copy's, and one shorter than the copy tiles across when its width
is a multiple.
A custom-list sort key compared only each value's position in the list.
Every value outside the list got the same position, so the stable sort
left them in their original order. Excel sorts them after the listed
values in the usual order. Two unlisted values now compare as a sort
without a list does (matchCase included).
Measured with crates/engine/examples/bench.rs (perf/xtask-bench), 100k rows, M2 Pro:
enter.formulas 465 -> 420 ms (23829d8c: 375), xlsx.save 540 -> 488 ms (466).
- number_to_text: the round-up-to-1E+15 check (f29ac7d9e) formatted every number with
exact {:.14e} and parsed it back; formula printing calls it once per literal. Run it
only for magnitudes that can round up (>= 9.9999999999999e14). Same output; boundary
tests added.
- Expr clone/map, xlsx prefix_params: a binary node whose left operand is not a chain
no longer allocates a spine Vec (2aeb21d4d); map rewrites the operands in their boxes.
Expr::walk reserves room for a typical formula up front.
- grow_autofilter checks the sheet has an AutoFilter before looking up the cell.
- retained_bytes_against looks up the newer band's row once per row, not per cell.
- The journal measures an entry's JSON size with a counting writer instead of building
the text (a big paste's params are MBs).
The rest of the enter.formulas gap and all of edit.fanout's (~+12%) is Undo's byte
budget (72db972de, #1227): sizing each snapshot and freeing evicted ones, an intended
cost of bounded memory.
Co-authored-by: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Found while testing crates/engine/src/cmd/data.rs:992 (split_delimited, used by text_to_columns)
Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
Text decoding (byte order marks, UTF-8, Windows-1256/1252), delimiter sniffing,
the record parser and field quoting moved to storytold/craft-libs as craft-csv
(#889), with the SYLK reader as craft_csv::sylk. GridCraft keeps typed values,
date-order inference, the used-range limit and the sheet writer in csv.rs, and in
io/sylk.rs the workbook a SYLK file becomes: formulas parsed (an unparsable one
is skipped and counted, as before), error values, number-format styles and column
widths.
* engine: bound Advanced Filter, Remove Duplicates, AutoFilter, Circle Invalid Data; one-pass AutoFit; saturating range dimensions
* address review: AutoFit scans each run of adjacent selected columns separately
* address review: report a truncated circle-invalid scan, no spill scan for plain cells in Replace, one pass for many AutoFit runs
* address review: warn in the app when Circle Invalid Data stopped early; Replace test requires success
* address review: the scan note joins an open-time notice; say cell visits
* engine: index merges and bound the page in HTML export and clipboard HTML
Save as Web Page and the clipboard's HTML scanned every merge of the
sheet for every cell, counted a merge's span over all the rows the file
gave it, placed each picture by summing every custom row before it, and
grew the page without a byte limit. Merges are now indexed once over
the exported rectangle (overlapping merges past a few visits per cell
are refused), spans use prefix counts clipped to the table, anchors use
LineIndex, and the page stops at 256 MiB with an error.
* address review: check the web page size after each chart and before returning it
* address review: bound the merge index, escape cell text within the page's room, size images before encoding
* address review: escape image attributes within the page's room