From efac547d6a3ca9e212f34ba9babde58b83cb052f Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 4 Jul 2026 22:10:38 +0800 Subject: [PATCH] feat(webui): redesign CPU & memory overview cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CPU 使用率: replace the flat per-core bar row with an adaptive heatmap grid — auto-fill square cells whose color maps to per-core load — so it reads cleanly from a few cores up to many-core (64/128) hosts instead of squashing into an unreadable strip. 内存使用: replace the single usage bar with a segmented 本进程 / 其他已用 / 空闲 breakdown bar plus a legend, surfacing the SnowLuma process's own RSS footprint (systemInfo.runtime.rss) that the card never exposed before. Removed the now-unused bestGrid() helper. All motion uses transform (scale) rather than width/height to avoid layout thrash. --- .../src/components/pages/overview-page.tsx | 100 ++++++++++-------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx index 766691b6..3719f8a1 100644 --- a/packages/webui/src/components/pages/overview-page.tsx +++ b/packages/webui/src/components/pages/overview-page.tsx @@ -511,23 +511,6 @@ 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; @@ -554,42 +537,41 @@ function HostBlock({ config }: { config: HostConfig }) {
CPU 使用率 + {systemInfo && ( + {systemInfo.cpu.perCore.length} 核 + )}
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'} -

- 负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'} +

+ 负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}

{systemInfo && systemInfo.cpu.perCore.length > 0 && ( - (() => { - const n = systemInfo.cpu.perCore.length; - const { cols, rows } = bestGrid(n); - const total = cols * rows; - return ( +
+ {systemInfo.cpu.perCore.map((p, i) => (
- {systemInfo.cpu.perCore.map((p, i) => ( -
-
-
- ))} - {Array.from({ length: total - n }).map((_, i) => ( -
- ))} + + {i} +
- ); - })() + ))} +
)}
)} @@ -605,11 +587,39 @@ function HostBlock({ config }: { config: HostConfig }) { {systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
- -
- 已用 {systemInfo ? formatBytes(systemInfo.memory.used) : '—'} - 共 {systemInfo ? formatBytes(systemInfo.memory.total) : '—'} -
+ {systemInfo ? (() => { + const m = systemInfo.memory; + const rss = Math.min(systemInfo.runtime.rss, m.used); + const other = Math.max(0, m.used - rss); + const segs = [ + { key: 'proc', label: '本进程', bytes: rss, grow: (rss / m.total) * 100, color: 'var(--primary)' }, + { key: 'other', label: '其他已用', bytes: other, grow: (other / m.total) * 100, color: 'color-mix(in oklab, var(--primary) 45%, transparent)' }, + { key: 'free', label: '空闲', bytes: m.free, grow: (m.free / m.total) * 100, color: 'color-mix(in oklab, var(--muted) 85%, transparent)' }, + ]; + return ( + <> +
+ {segs.map((seg) => ( + + ))} +
+
+ {segs.map((seg) => ( + + + {seg.label} + {formatBytes(seg.bytes)} + + ))} +
+ + ); + })() : } )} {/* Runtime */}