Skip to content

Commit a2d914a

Browse files
SamTV12345claude
andauthored
feat(sheet): show Min and Max in the status-bar stats (#363)
Excel's status bar shows Average/Count/Min/Max/Sum for a numeric selection; we only had Average/Count/Sum. Adds Min and Max to the same single-pass scan. E2e assertion extended. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 86b02f0 commit a2d914a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

playwright/specs/sheet_excel_chrome.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test.describe('Sheet Excel chrome', () => {
104104
await expect(cell(page, 0, 0)).toHaveText('neu2');
105105
});
106106

107-
test('statusbar shows average, count, and sum for a numeric selection', async ({ page }) => {
107+
test('statusbar shows average, count, min, max, and sum for a numeric selection', async ({ page }) => {
108108
const padId = `xl-stats-${Date.now()}`;
109109
await openSheet(page, padId);
110110
await commitCell(page, 0, 0, '1'); // A1
@@ -116,6 +116,8 @@ test.describe('Sheet Excel chrome', () => {
116116
const stats = page.locator('.sheet-statusbar .sheet-stats');
117117
await expect(stats).toContainText('Average: 2');
118118
await expect(stats).toContainText('Count: 3');
119+
await expect(stats).toContainText('Min: 1');
120+
await expect(stats).toContainText('Max: 3');
119121
await expect(stats).toContainText('Sum: 6');
120122
});
121123

ui/src/js/sheet/sheetEditor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export function startSheetEditor(root: HTMLElement): void {
137137
let sum = 0;
138138
let numCount = 0;
139139
let count = 0;
140+
let min = Infinity;
141+
let max = -Infinity;
140142
for (const { row, col } of selCells(selection)) {
141143
const raw = rawValue(row, col);
142144
if (raw === '') continue;
@@ -146,13 +148,16 @@ export function startSheetEditor(root: HTMLElement): void {
146148
if (value.trim() !== '' && Number.isFinite(n)) {
147149
sum += n;
148150
numCount++;
151+
if (n < min) min = n;
152+
if (n > max) max = n;
149153
}
150154
}
151155
if (numCount === 0) return;
152156
// toPrecision(12) strips float noise (0.1+0.2 -> 0.3) without truncating
153157
// typical spreadsheet magnitudes.
154158
const f = (n: number): string => String(parseFloat(n.toPrecision(12)));
155-
for (const part of [`Average: ${f(sum / numCount)}`, `Count: ${count}`, `Sum: ${f(sum)}`]) {
159+
// Excel status-bar order: Average, Count, Min, Max, Sum.
160+
for (const part of [`Average: ${f(sum / numCount)}`, `Count: ${count}`, `Min: ${f(min)}`, `Max: ${f(max)}`, `Sum: ${f(sum)}`]) {
156161
const s = document.createElement('span');
157162
s.textContent = part;
158163
statsEl.appendChild(s);

0 commit comments

Comments
 (0)