From f0c548d3a1b50e4b4d9d1ec0dba854115be45995 Mon Sep 17 00:00:00 2001
From: orblazer <orblazer.minecraft@gmail.com>
Date: Mon, 3 Jan 2022 12:39:09 +0100
Subject: [PATCH] fix(graph): improve stability of label values

Fix #25
---
 package/contents/ui/components/SensorGraph.qml | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/package/contents/ui/components/SensorGraph.qml b/package/contents/ui/components/SensorGraph.qml
index b909ff9..33e311c 100644
--- a/package/contents/ui/components/SensorGraph.qml
+++ b/package/contents/ui/components/SensorGraph.qml
@@ -9,7 +9,7 @@ import org.kde.quickcharts 1.0 as Charts
 import "./" as RMComponents
 
 RMComponents.BaseSensorGraph {
-	id: chart
+    id: chart
 
     readonly property alias sensorsModel: sensorsModel
 
@@ -54,8 +54,11 @@ RMComponents.BaseSensorGraph {
 
                     // Update albel
                     if (index === 0) { // is first line
-                        firstLineLabel.text = value || '...'
-                        firstLineLabel.visible = true
+                        if (typeof value === 'undefined') {
+                            firstLineLabel.text = '...'
+                        } else {
+                            firstLineLabel.text = value
+                        }
                     } else if (index === 1) { // is second line
                         if (typeof value === 'undefined') {
                             secondLineLabel.text = '...'
@@ -96,9 +99,8 @@ RMComponents.BaseSensorGraph {
         var data = sensorsModel.getData(0)
         if (typeof data !== "undefined") {
             firstLineLabel.text = data
-            firstLineLabel.visible = true
         } else {
-            firstLineLabel.visible = false
+            firstLineLabel.text = '...'
         }
 
         // Show second line
@@ -107,7 +109,8 @@ RMComponents.BaseSensorGraph {
             secondLineLabel.text = data
             secondLineLabel.visible = sensorsModel.getData(1, Sensors.SensorDataModel.Value) !== 0 || secondLabelWhenZero
         } else {
-            secondLineLabel.visible = false
+            secondLineLabel.text = '...'
+            secondLineLabel.visible = secondLabelWhenZero
         }
 
         chart.showValueWhenMouseMove()