extract SparklineCanvas component from 5 applets
This commit is contained in:
parent
732a14e5cb
commit
8d76df6ef5
8 changed files with 178 additions and 233 deletions
|
|
@ -71,49 +71,36 @@ Column {
|
|||
}
|
||||
|
||||
// Memory history sparkline
|
||||
Canvas {
|
||||
id: memSparkline
|
||||
SparklineCanvas {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 12
|
||||
height: 18
|
||||
|
||||
property var _hist: S.SystemStats.memHistory
|
||||
property color _col: root.accentColor
|
||||
|
||||
on_HistChanged: if (root.active)
|
||||
requestPaint()
|
||||
on_ColChanged: if (root.active)
|
||||
requestPaint()
|
||||
|
||||
onVisibleChanged: if (visible)
|
||||
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);
|
||||
}
|
||||
}
|
||||
history: S.SystemStats.memHistory
|
||||
color: root.accentColor
|
||||
active: root.active
|
||||
maxSamples: 30
|
||||
backgroundTint: 0.15
|
||||
}
|
||||
|
||||
// Breakdown rows
|
||||
InfoRow { label: "Used"; value: root._fmt(root.usedGb) }
|
||||
InfoRow { label: "Cached"; value: root._fmt(root.cachedGb) }
|
||||
InfoRow { label: "Available"; value: root._fmt(root.availGb) }
|
||||
InfoRow { label: "Total"; value: root._fmt(root.totalGb) }
|
||||
InfoRow {
|
||||
label: "Used"
|
||||
value: root._fmt(root.usedGb)
|
||||
}
|
||||
InfoRow {
|
||||
label: "Cached"
|
||||
value: root._fmt(root.cachedGb)
|
||||
}
|
||||
InfoRow {
|
||||
label: "Available"
|
||||
value: root._fmt(root.availGb)
|
||||
}
|
||||
InfoRow {
|
||||
label: "Total"
|
||||
value: root._fmt(root.totalGb)
|
||||
}
|
||||
|
||||
Separator {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue