From 120e6d29074eea8cd8ee703830cbccd515b0bc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 27 Nov 2025 13:52:53 +0100 Subject: [PATCH] Update energy charts and fix y value texts --- .../ui/mainviews/energy/ConsumerStats.qml | 12 ++++++--- .../ui/mainviews/energy/ConsumersHistory.qml | 14 ++++++---- .../mainviews/energy/PowerBalanceHistory.qml | 26 ++++++++++++------- .../ui/mainviews/energy/PowerBalanceStats.qml | 12 ++++++--- .../energy/PowerConsumptionBalanceHistory.qml | 15 +++++++---- .../energy/PowerProductionBalanceHistory.qml | 15 +++++++---- 6 files changed, 63 insertions(+), 31 deletions(-) diff --git a/nymea-app/ui/mainviews/energy/ConsumerStats.qml b/nymea-app/ui/mainviews/energy/ConsumerStats.qml index 60c3d855..e1d1a24f 100644 --- a/nymea-app/ui/mainviews/energy/ConsumerStats.qml +++ b/nymea-app/ui/mainviews/energy/ConsumerStats.qml @@ -247,7 +247,7 @@ StatsBase { anchors.fill: parent backgroundColor: "transparent" - // margins.left: 0 + margins.left: Math.max(Style.smallMargins * 2, valueLabelMetrics.width + Style.smallMargins * 2) margins.right: 0 margins.top: 0 margins.bottom: Style.smallIconSize + Style.margins @@ -291,12 +291,18 @@ StatsBase { Behavior on opacity { NumberAnimation {}} } + TextMetrics { + id: valueLabelMetrics + font: Style.extraSmallFont + text: (valueAxis.max).toFixed(1) + "kWh" + } + Item { id: labelsLayout x: Style.smallMargins y: chartView.plotArea.y height: chartView.plotArea.height - width: chartView.plotArea.x - x + width: Math.max(0, chartView.margins.left - Style.smallMargins) Repeater { model: valueAxis.tickCount delegate: Label { @@ -484,7 +490,7 @@ StatsBase { } property int wheelDelta: 0 - onWheel: { + onWheel: (wheel) => { wheelDelta += wheel.pixelDelta.x var slotWidth = mouseArea.width / d.config.count while (wheelDelta > slotWidth) { diff --git a/nymea-app/ui/mainviews/energy/ConsumersHistory.qml b/nymea-app/ui/mainviews/energy/ConsumersHistory.qml index 2324f4b7..113059c7 100644 --- a/nymea-app/ui/mainviews/energy/ConsumersHistory.qml +++ b/nymea-app/ui/mainviews/energy/ConsumersHistory.qml @@ -61,7 +61,7 @@ Item { } } - onEntriesRemoved: { + onEntriesRemoved: (index, count) => { consumptionUpperSeries.removePoints(index, Math.min(count, consumptionUpperSeries.count)) zeroSeries.shrink() } @@ -227,7 +227,7 @@ Item { anchors.fill: parent backgroundColor: "transparent" - margins.left: 0 + margins.left: Math.max(Style.smallMargins * 2, valueLabelMetrics.width + Style.smallMargins * 2) margins.right: 0 margins.top: 0 margins.bottom: Style.smallIconSize + Style.margins @@ -252,6 +252,11 @@ Item { opacity: .5 } + TextMetrics { + id: valueLabelMetrics + font: Style.extraSmallFont + text: ((valueAxis.max) / 1000).toFixed(2) + "kW" + } ValueAxis { id: valueAxis @@ -263,7 +268,6 @@ Item { lineVisible: false titleVisible: false shadesVisible: false - // visible: false function adjustMax(value) { max = Math.max(max, Math.ceil(value / 100) * 100) @@ -275,7 +279,7 @@ Item { x: Style.smallMargins y: chartView.plotArea.y height: chartView.plotArea.height - width: chartView.plotArea.x - x + width: Math.max(0, chartView.margins.left - Style.smallMargins) Repeater { model: valueAxis.tickCount delegate: Label { @@ -692,7 +696,7 @@ Item { d.now = new Date(Math.min(new Date(), new Date(startDatetime.getTime() + timeDelta))) } - onWheel: { + onWheel: (wheel) => { startDatetime = d.now var totalTime = d.endTime.getTime() - d.startTime.getTime() // pixelDelta : timeDelta = width : totalTime diff --git a/nymea-app/ui/mainviews/energy/PowerBalanceHistory.qml b/nymea-app/ui/mainviews/energy/PowerBalanceHistory.qml index 961dfaf0..0276cab1 100644 --- a/nymea-app/ui/mainviews/energy/PowerBalanceHistory.qml +++ b/nymea-app/ui/mainviews/energy/PowerBalanceHistory.qml @@ -94,7 +94,7 @@ Item { } function selectSeries(series) { - if (d.selectedSeries == series) { + if (d.selectedSeries === series) { d.selectedSeries = null } else { d.selectedSeries = series @@ -147,7 +147,7 @@ Item { acquisitionSeries.lowerSeries = fromStorageUpperSeries } - onEntriesRemoved: { + onEntriesRemoved: (index, count) => { // Note QtCharts crash when calling removePoints() for points that don't exist. // Additionally it may decide to ignore values we add, e.g. if we try to add an Inf or undefined value for whatever reason // So, even though in theory the series should always 1:1 reflect the model, it may not do so in practice and we'll have to make sure not crash here @@ -246,7 +246,7 @@ Item { id: chartView anchors.fill: parent backgroundColor: "transparent" - margins.left: 0 + margins.left: Math.max(Style.smallMargins * 2, valueLabelMetrics.width + Style.smallMargins * 2) margins.right: 0 margins.bottom: Style.smallIconSize + Style.margins margins.top: 0 @@ -259,18 +259,24 @@ Item { ActivityIndicator { x: chartView.plotArea.x + (chartView.plotArea.width - width) / 2 y: chartView.plotArea.y + (chartView.plotArea.height - height) / 2 + (chartView.plotArea.height / 8) - visible: powerBalanceLogs.fetchingData && (powerBalanceLogs.count == 0 || powerBalanceLogs.get(0).timestamp > d.startTime) + visible: powerBalanceLogs.fetchingData && (powerBalanceLogs.count === 0 || powerBalanceLogs.get(0).timestamp > d.startTime) opacity: .5 } Label { x: chartView.plotArea.x + (chartView.plotArea.width - width) / 2 y: chartView.plotArea.y + (chartView.plotArea.height - height) / 2 + (chartView.plotArea.height / 8) text: qsTr("No data available") - visible: !powerBalanceLogs.fetchingData && (powerBalanceLogs.count == 0 || powerBalanceLogs.get(0).timestamp > d.now) + visible: !powerBalanceLogs.fetchingData && (powerBalanceLogs.count === 0 || powerBalanceLogs.get(0).timestamp > d.now) font: Style.smallFont opacity: .5 } + TextMetrics { + id: valueLabelMetrics + font: Style.extraSmallFont + text: ((valueAxis.max) / 1000).toFixed(2) + "kW" + } + ValueAxis { id: valueAxis min: 0 @@ -282,12 +288,13 @@ Item { titleVisible: false shadesVisible: false } + Item { id: labelsLayout x: Style.smallMargins y: chartView.plotArea.y height: chartView.plotArea.height - width: chartView.plotArea.x - x + width: Math.max(0, chartView.margins.left - Style.smallMargins) Repeater { model: valueAxis.tickCount delegate: Label { @@ -353,9 +360,9 @@ Item { XYPoint { x: dateTimeAxis.min.getTime(); y: 0 } XYPoint { x: dateTimeAxis.max.getTime(); y: 0 } function ensureValue(timestamp) { - if (count == 0) { + if (count === 0) { append(timestamp, 0) - } else if (count == 1) { + } else if (count === 1) { if (timestamp.getTime() < at(0).x) { insert(0, timestamp, 0) } else { @@ -813,7 +820,7 @@ Item { d.now = new Date(Math.min(new Date(), new Date(startDatetime.getTime() + timeDelta))) } - onWheel: { + onWheel: (wheel) => { startDatetime = d.now var totalTime = d.endTime.getTime() - d.startTime.getTime() // pixelDelta : timeDelta = width : totalTime @@ -966,4 +973,3 @@ Item { } - diff --git a/nymea-app/ui/mainviews/energy/PowerBalanceStats.qml b/nymea-app/ui/mainviews/energy/PowerBalanceStats.qml index 93f006eb..17da03e5 100644 --- a/nymea-app/ui/mainviews/energy/PowerBalanceStats.qml +++ b/nymea-app/ui/mainviews/energy/PowerBalanceStats.qml @@ -242,7 +242,7 @@ StatsBase { legend.font: Style.extraSmallFont legend.labelColor: Style.foregroundColor - // margins.left: 0 + margins.left: Math.max(Style.smallMargins * 2, valueLabelMetrics.width + Style.smallMargins * 2) margins.right: 0 margins.bottom: Style.smallIconSize + Style.margins margins.top: 0 @@ -263,12 +263,18 @@ StatsBase { Behavior on opacity { NumberAnimation {}} } + TextMetrics { + id: valueLabelMetrics + font: Style.extraSmallFont + text: (valueAxis.max).toFixed(1) + "kWh" + } + Item { id: labelsLayout x: Style.smallMargins y: chartView.plotArea.y height: chartView.plotArea.height - width: chartView.plotArea.x - x + width: Math.max(0, chartView.margins.left - Style.smallMargins) Repeater { model: valueAxis.tickCount @@ -615,7 +621,7 @@ StatsBase { } property int wheelDelta: 0 - onWheel: { + onWheel: (wheel) => { wheelDelta += wheel.pixelDelta.x var slotWidth = mouseArea.width / d.config.count while (wheelDelta > slotWidth) { diff --git a/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml b/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml index 703753d5..89c61995 100644 --- a/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml +++ b/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml @@ -110,7 +110,7 @@ Item { } } - onEntriesRemoved: { + onEntriesRemoved: (index, count) => { acquisitionUpperSeries.removePoints(index, count) storageUpperSeries.removePoints(index, count) selfProductionUpperSeries.removePoints(index, count) @@ -194,7 +194,7 @@ Item { id: chartView anchors.fill: parent backgroundColor: "transparent" - margins.left: 0 + margins.left: Math.max(Style.smallMargins * 2, valueLabelMetrics.width + Style.smallMargins * 2) margins.right: 0 margins.bottom: 0 margins.top: 0 @@ -218,6 +218,12 @@ Item { opacity: .5 } + TextMetrics { + id: valueLabelMetrics + font: Style.extraSmallFont + text: ((valueAxis.max) / 1000).toFixed(2) + "kW" + } + ValueAxis { id: valueAxis min: 0 @@ -237,7 +243,7 @@ Item { x: Style.smallMargins y: chartView.plotArea.y height: chartView.plotArea.height - width: chartView.plotArea.x - x + width: Math.max(0, chartView.margins.left - Style.smallMargins) Repeater { model: valueAxis.tickCount delegate: Label { @@ -502,7 +508,7 @@ Item { d.now = new Date(Math.min(new Date(), new Date(startDatetime.getTime() + timeDelta))) } - onWheel: { + onWheel: (wheel) => { startDatetime = d.now var totalTime = d.endTime.getTime() - d.startTime.getTime() // pixelDelta : timeDelta = width : totalTime @@ -630,4 +636,3 @@ Item { } } } - diff --git a/nymea-app/ui/mainviews/energy/PowerProductionBalanceHistory.qml b/nymea-app/ui/mainviews/energy/PowerProductionBalanceHistory.qml index 4b16fcca..aab7f48c 100644 --- a/nymea-app/ui/mainviews/energy/PowerProductionBalanceHistory.qml +++ b/nymea-app/ui/mainviews/energy/PowerProductionBalanceHistory.qml @@ -111,7 +111,7 @@ Item { } } - onEntriesRemoved: { + onEntriesRemoved: (index, count) => { acquisitionUpperSeries.removePoints(index, count) storageUpperSeries.removePoints(index, count) selfConsumptionUpperSeries.removePoints(index, count) @@ -195,7 +195,7 @@ Item { id: chartView anchors.fill: parent backgroundColor: "transparent" - margins.left: 0 + margins.left: Math.max(Style.smallMargins * 2, valueLabelMetrics.width + Style.smallMargins * 2) margins.right: 0 margins.bottom: 0 margins.top: 0 @@ -219,6 +219,12 @@ Item { opacity: .5 } + TextMetrics { + id: valueLabelMetrics + font: Style.extraSmallFont + text: ((valueAxis.max) / 1000).toFixed(2) + "kW" + } + ValueAxis { id: valueAxis min: 0 @@ -235,7 +241,7 @@ Item { x: Style.smallMargins y: chartView.plotArea.y height: chartView.plotArea.height - width: chartView.plotArea.x - x + width: Math.max(0, chartView.margins.left - Style.smallMargins) Repeater { model: valueAxis.tickCount delegate: Label { @@ -495,7 +501,7 @@ Item { d.now = new Date(Math.min(new Date(), new Date(startDatetime.getTime() + timeDelta))) } - onWheel: { + onWheel: (wheel) => { startDatetime = d.now var totalTime = d.endTime.getTime() - d.startTime.getTime() // pixelDelta : timeDelta = width : totalTime @@ -627,4 +633,3 @@ Item { } -