feat: memory panel sparkline history
This commit is contained in:
parent
fac3b27679
commit
3582ea2656
2 changed files with 47 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue