battery applet: add wattage history sparkline, sparkline supports signed data with auto-range

This commit is contained in:
Damocles 2026-04-24 21:14:32 +02:00
parent b5be146619
commit 42d11e7a14
4 changed files with 67 additions and 26 deletions

View file

@ -30,6 +30,8 @@ QtObject {
// 24h history (1440 samples @ 60s)
property var history: []
// Wattage history (60 samples @ 60s = 1h), signed: positive = charging
property var rateHistory: []
property var _histTimer: Timer {
interval: 60000
@ -39,6 +41,9 @@ QtObject {
onTriggered: {
const h = root.history.concat([root.percent]);
root.history = h.length > 1440 ? h.slice(h.length - 1440) : h;
const w = root.charging ? root.changeRate : -root.changeRate;
const rh = root.rateHistory.concat([w]);
root.rateHistory = rh.length > 60 ? rh.slice(rh.length - 60) : rh;
}
}