From dafe1fdb75d0cf05a7b54904a33dea78d15cde50 Mon Sep 17 00:00:00 2001 From: ajnart Date: Sat, 18 Jul 2026 14:35:19 +0200 Subject: [PATCH] fix(beszel): restore balanced grid layout for system grid widget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverts getColCount to the minimize-empty-cells heuristic from v1.68.0 after the aspect-ratio rewrite in 576856d63 broke 2×2 layout for 4 systems at common widget widths (240–359px). Lowered MIN_CELL_WIDTH from 180 to 140 — a compromise between the original 120 (v1.68.0) and the current 180, leaving room for the DiskUsage component while keeping the 2×2 threshold at 280px. Fixes #6385 --- .../widgets/src/beszel-system-grid/component.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/widgets/src/beszel-system-grid/component.tsx b/packages/widgets/src/beszel-system-grid/component.tsx index 51e5d014c..dd2f56c54 100644 --- a/packages/widgets/src/beszel-system-grid/component.tsx +++ b/packages/widgets/src/beszel-system-grid/component.tsx @@ -114,14 +114,22 @@ const getMaxVisibleMetrics = (cellHeight: number, size: SizeConfig): number => { return Math.max(1, Math.floor(available / size.rowHeight)); }; -const MIN_CELL_WIDTH = 180; +const MIN_CELL_WIDTH = 140; const MIN_CELL_HEIGHT = 80; -const getColCount = (width: number, height: number, itemCount: number): number => { +const getColCount = (width: number, _height: number, itemCount: number): number => { if (itemCount <= 1) return 1; const maxCols = Math.min(itemCount, Math.max(1, Math.floor(width / MIN_CELL_WIDTH))); - const aspectRatio = width / Math.max(height, MIN_CELL_HEIGHT); - return Math.min(maxCols, Math.max(1, Math.ceil(Math.sqrt(itemCount * aspectRatio)))); + + let best = 1; + for (let c = 1; c <= maxCols; c++) { + const emptyCells = (c - (itemCount % c)) % c; + const bestEmpty = (best - (itemCount % best)) % best; + if (emptyCells < bestEmpty || (emptyCells === bestEmpty && c > best)) { + best = c; + } + } + return best; }; interface MetricRowProps {