extract SparklineCanvas component from 5 applets
This commit is contained in:
parent
732a14e5cb
commit
8d76df6ef5
8 changed files with 178 additions and 233 deletions
|
|
@ -76,40 +76,16 @@ Column {
|
|||
}
|
||||
|
||||
// Usage history sparkline
|
||||
Canvas {
|
||||
id: _sparkline
|
||||
SparklineCanvas {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 12
|
||||
height: 36
|
||||
|
||||
property var _hist: S.SystemStats.gpuHistory
|
||||
|
||||
on_HistChanged: 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 maxSamples = 60;
|
||||
const bw = width / maxSamples;
|
||||
const offset = maxSamples - d.length;
|
||||
for (let i = 0; i < d.length; i++) {
|
||||
const barH = Math.max(1, height * d[i] / 100);
|
||||
const col = S.Theme.loadColor(d[i]);
|
||||
ctx.fillStyle = col.toString();
|
||||
ctx.fillRect((offset + i) * bw, height - barH, Math.max(1, bw - 0.5), barH);
|
||||
}
|
||||
}
|
||||
history: S.SystemStats.gpuHistory
|
||||
active: root.active
|
||||
maxSamples: 60
|
||||
colorFunction: v => S.Theme.loadColor(v)
|
||||
}
|
||||
|
||||
// VRAM section
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue