diff --git a/modules/Memory.qml b/modules/Memory.qml index 0713095..5d8b7a0 100644 --- a/modules/Memory.qml +++ b/modules/Memory.qml @@ -144,6 +144,50 @@ M.BarSection { } } + // Memory history sparkline + Canvas { + id: memSparkline + anchors.left: parent.left + anchors.leftMargin: 12 + anchors.right: parent.right + anchors.rightMargin: 12 + height: 18 + + property var _hist: M.SystemStats.memHistory + property color _col: root.accentColor + + on_HistChanged: if (root._showPanel) + requestPaint() + on_ColChanged: if (root._showPanel) + requestPaint() + + Connections { + target: root + function on_ShowPanelChanged() { + if (root._showPanel) + memSparkline.requestPaint(); + } + } + + onPaint: { + const ctx = getContext("2d"); + if (!ctx) + return; + ctx.clearRect(0, 0, width, height); + const d = _hist; + if (!d.length) + return; + const bw = width / 30; + ctx.fillStyle = Qt.rgba(_col.r, _col.g, _col.b, 0.15).toString(); + ctx.fillRect(0, 0, width, height); + ctx.fillStyle = _col.toString(); + for (let i = 0; i < d.length; i++) { + const h = Math.max(1, height * d[i] / 100); + ctx.fillRect((30 - d.length + i) * bw, height - h, Math.max(1, bw - 0.5), h); + } + } + } + // Breakdown rows Item { width: parent.width diff --git a/modules/SystemStats.qml b/modules/SystemStats.qml index 678f494..3582a79 100644 --- a/modules/SystemStats.qml +++ b/modules/SystemStats.qml @@ -40,6 +40,7 @@ QtObject { property real memAvailGb: 0 property real memCachedGb: 0 property real memBuffersGb: 0 + property var memHistory: [] // ── Disk ───────────────────────────────────────────────────────────── property var diskMounts: [] @@ -89,6 +90,8 @@ QtObject { root.memAvailGb = ev.avail_gb; root.memCachedGb = ev.cached_gb; root.memBuffersGb = ev.buffers_gb; + const h = root.memHistory.concat([ev.percent]); + root.memHistory = h.length > 30 ? h.slice(h.length - 30) : h; } } catch (e) {} }