File: upstream_2067b2ab_kcms-energy-More-stable-UI-for-history-graph.patch

package info (click to toggle)
kinfocenter 4%3A6.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,800 kB
  • sloc: cpp: 3,144; xml: 249; python: 142; sh: 18; makefile: 3
file content (144 lines) | stat: -rw-r--r-- 4,882 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
From 2067b2abf6f22ddc5fa1b4edc75f9add0e8b5de7 Mon Sep 17 00:00:00 2001
From: Ismael Asensio <isma.af@gmail.com>
Date: Thu, 30 Jan 2025 21:20:32 +0100
Subject: [PATCH] kcms/energy: More stable UI for history graph

For devices that have history data available, always show the graph.
If there are no data points for the selected time range, simply show
a placeholder message instead of hiding it.

On the other hand, always hide the graph and options for those devices
that cannot provide a history, removing also the potentially confusing
warning message

This moves away from having an annoyingly jumping an unclear UI.

BUG: 490239
FIXED-IN: 6.4
---
 kcms/energy/ui/Graph.qml | 38 ++++++++++++++++++++------------------
 kcms/energy/ui/main.qml  | 35 +++++++++++++++++------------------
 2 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/kcms/energy/ui/Graph.qml b/kcms/energy/ui/Graph.qml
index 66f7a861..75c9224a 100644
--- a/kcms/energy/ui/Graph.qml
+++ b/kcms/energy/ui/Graph.qml
@@ -93,31 +93,33 @@ Canvas
         var currentUnixTime = Date.now()
         var xMinUnixTime = currentUnixTime - xDuration * 1000
 
-        // Draw the line graph
         c.beginPath();
 
-        var index = 0
+        // Draw the line graph if we have enough points
+        if (data.length >= 2) {
+            var index = 0
 
-        while ((index < data.length - 1) && (data[index].x < (xMinUnixTime / 1000))) {
-            index++
-        }
+            while ((index < data.length - 1) && (data[index].x < (xMinUnixTime / 1000))) {
+                index++
+            }
 
-        var firstPoint = scalePoint(data[index], currentUnixTime)
-        c.moveTo(firstPoint.x, firstPoint.y)
+            var firstPoint = scalePoint(data[index], currentUnixTime)
+            c.moveTo(firstPoint.x, firstPoint.y)
 
-        var point
-        for (var i = index + 1; i < data.length; i++) {
-            if (data[i].x > (xMinUnixTime / 1000)) {
-                point = scalePoint(data[i], currentUnixTime)
-                c.lineTo(point.x, point.y)
+            var point
+            for (var i = index + 1; i < data.length; i++) {
+                if (data[i].x > (xMinUnixTime / 1000)) {
+                    point = scalePoint(data[i], currentUnixTime)
+                    c.lineTo(point.x, point.y)
+                }
             }
+
+            c.stroke();
+            c.strokeStyle = 'rgba(0, 0, 0, 0)';
+            c.lineTo(point.x, height - yPadding);
+            c.lineTo(firstPoint.x, height - yPadding);
+            c.fill();
         }
-            
-        c.stroke();
-        c.strokeStyle = 'rgba(0, 0, 0, 0)';
-        c.lineTo(point.x, height - yPadding);
-        c.lineTo(firstPoint.x, height - yPadding);
-        c.fill();
 
         c.closePath()
 
diff --git a/kcms/energy/ui/main.qml b/kcms/energy/ui/main.qml
index e8670130..ba71ba77 100644
--- a/kcms/energy/ui/main.qml
+++ b/kcms/energy/ui/main.qml
@@ -238,18 +238,17 @@ KCM.SimpleKCM {
             }
         }
 
+        HistoryModel {
+            id: history
+            duration: timespanComboDurations[timespanCombo.currentIndex]
+            device: currentUdi
+            type: root.historyType
+        }
+
         ColumnLayout {
             Layout.fillWidth: true
             spacing: Kirigami.Units.smallSpacing
-            visible: !!currentBattery
-
-
-            HistoryModel {
-                id: history
-                duration: timespanComboDurations[timespanCombo.currentIndex]
-                device: currentUdi
-                type: root.historyType
-            }
+            visible: !!currentBattery && history.available
 
             Graph {
                 id: graph
@@ -291,7 +290,15 @@ KCM.SimpleKCM {
                     }
                 }
                 yStep: root.historyType == HistoryModel.RateType ? 10 : 20
-                visible: history.count > 1
+            }
+
+            // Reparented to keep the item outside of a layout and the graph canvas
+            Kirigami.PlaceholderMessage {
+                parent: graph
+                anchors.centerIn: parent
+                visible: graph.data.length < 2
+                width: parent.width - (Kirigami.Units.largeSpacing * 4)
+                text: i18nc("@info:status", "No history information for this time span")
             }
 
             GridLayout {
@@ -343,14 +350,6 @@ KCM.SimpleKCM {
                     onClicked: history.refresh()
                 }
             }
-
-            Kirigami.InlineMessage {
-                Layout.fillWidth: true
-                Layout.topMargin: Kirigami.Units.smallSpacing
-                showCloseButton: true
-                text: i18n("This type of history is currently not available for this device.")
-                visible: !graph.visible
-            }
         }
 
         ColumnLayout {
-- 
GitLab