From 78b0e1a1240589d932418928182e998f1aedfdf4 Mon Sep 17 00:00:00 2001
From: stla <130404897+Stlara-F@users.noreply.github.com>
Date: Thu, 25 Jun 2026 20:46:16 +0800
Subject: [PATCH] feat(webui): auto-compress per-core density grid to fixed
container (#140) (#141)
Replace fixed grid-cols-8 per-core bar display with dynamically
computed square grid that fills a fixed-height (80px) container.
- Adds bestGrid() utility that finds optimal (cols,rows) partition
by minimizing empty cells and aspect balance
- Grid uses grid-template-rows: repeat(N, 1fr) for equal row height
- Empty cells filled with hidden divs for stable layout
- Preserves existing color tokens (bg-muted, bg-primary/70, rounded-sm)
- No scrollbar regardless of core count (tested up to 256)
Closes #140
Co-authored-by: SnowLuma Dev
---
.../src/components/pages/overview-page.tsx | 48 ++++++++++++++++---
1 file changed, 42 insertions(+), 6 deletions(-)
diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx
index 033b365e..023af6a0 100644
--- a/packages/webui/src/components/pages/overview-page.tsx
+++ b/packages/webui/src/components/pages/overview-page.tsx
@@ -511,6 +511,23 @@ function StatTileWidget({ id }: { id: string }) {
const HOST_GRID_COLS: Record = { 1: 'lg:grid-cols-1', 2: 'lg:grid-cols-2', 3: 'lg:grid-cols-3' };
+function bestGrid(n: number, maxCols = 48): { cols: number; rows: number; waste: number } {
+ let best = { cols: 2, rows: Math.ceil(n / 2), waste: 0 };
+ let bestScore = Infinity;
+ const limit = Math.min(maxCols, n);
+ for (let cols = 2; cols <= limit; cols++) {
+ const rows = Math.ceil(n / cols);
+ const waste = cols * rows - n;
+ const balance = Math.abs(cols - rows);
+ const score = waste * 20 + balance;
+ if (score < bestScore) {
+ bestScore = score;
+ best = { cols, rows, waste };
+ }
+ }
+ return best;
+}
+
function HostBlock({ config }: { config: HostConfig }) {
const { systemInfo, refreshSystem } = useAppState();
const panelCount = [config.cpu, config.memory, config.runtime].filter(Boolean).length;
@@ -547,13 +564,32 @@ function HostBlock({ config }: { config: HostConfig }) {
负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}
{systemInfo && systemInfo.cpu.perCore.length > 0 && (
-
- {systemInfo.cpu.perCore.map((p, i) => (
-
-
+ (() => {
+ const n = systemInfo.cpu.perCore.length;
+ const { cols, rows } = bestGrid(n);
+ const total = cols * rows;
+ return (
+
+ {systemInfo.cpu.perCore.map((p, i) => (
+
+ ))}
+ {Array.from({ length: total - n }).map((_, i) => (
+
+ ))}
- ))}
-
+ );
+ })()
)}
)}