fix(beszel): restore balanced grid layout for Beszel System Grid widget (#6389)

This commit is contained in:
Thomas authored and GitHub committed 2026-07-28 21:49:04 +02:00
1 parent 51a6cbe6d4
commit 3419805a49
1 file changed
+12 -4
@@ -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 {