From a15a47225f0833e5ef2d023c4dcd2d8f322d494d Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 18 May 2023 12:18:28 +0200 Subject: [PATCH] Fix value axis labels for negative values in StateChart Fixes: #1028 --- nymea-app/ui/customviews/StateChart.qml | 13 +++++++++++-- .../mainviews/dashboard/DashboardGraphDelegate.qml | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nymea-app/ui/customviews/StateChart.qml b/nymea-app/ui/customviews/StateChart.qml index 74f31721..da62340d 100644 --- a/nymea-app/ui/customviews/StateChart.qml +++ b/nymea-app/ui/customviews/StateChart.qml @@ -20,6 +20,7 @@ Item { property string iconSource: "" property alias title: titleLabel.text property bool titleVisible: true + property bool inverted: false readonly property State valueState: thing && stateType ? thing.states.getState(stateType.id) : null readonly property StateType connectedStateType: hasConnectable ? thing.thingClass.stateTypes.findByName("connected") : null @@ -81,6 +82,8 @@ Item { if (value == null) { value = false; } + value *= root.inverted ? -1 : 1 + // for booleans, we'll insert the opposite value right before the new one so the position is doubled var insertIdx = (index + i) * 2 valueSeries.insert(insertIdx, entry.timestamp.getTime() - 500, !value) @@ -91,6 +94,7 @@ Item { if (value == null) { value = 0; } + value *= root.inverted ? -1 : 1 minValue = minValue == undefined ? value : Math.min(minValue, value) maxValue = maxValue == undefined ? value : Math.max(maxValue, value) @@ -264,13 +268,18 @@ Item { height: chartView.plotArea.height width: chartView.plotArea.x - x visible: root.stateType.type.toLowerCase() != "bool" && logsModel.minValue != logsModel.maxValue + property double range: Math.abs(valueAxis.max - valueAxis.min) + property double stepSize: range / (valueAxis.tickCount - 1) + Repeater { model: valueAxis.tickCount delegate: Label { y: parent.height / (valueAxis.tickCount - 1) * index - font.pixelSize / 2 width: parent.width - Style.smallMargins horizontalAlignment: Text.AlignRight - text: root.stateType ? Types.toUiValue(((valueAxis.max - (index * valueAxis.max / (valueAxis.tickCount - 1)))), root.stateType.unit).toFixed(0) + " " + Types.toUiUnit(root.stateType.unit) : "" + property double offset: (valueAxis.tickCount - index - 1) * labelsLayout.stepSize + property double value: valueAxis.min + offset + text: root.stateType ? Types.toUiValue(value, root.stateType.unit).toFixed(0) + " " + Types.toUiUnit(root.stateType.unit) : "" verticalAlignment: Text.AlignTop font: Style.extraSmallFont } @@ -468,7 +477,7 @@ Item { property int xOnRight: Math.max(0, entryX) + Style.smallMargins property int xOnLeft: Math.min(entryX, mouseArea.width) - Style.smallMargins - width x: xOnRight + width < mouseArea.width ? xOnRight : xOnLeft - property var value: entry ? entry.values[root.stateType.name] : null + property var value: entry ? entry.values[root.stateType.name] * (root.inverted ? -1 : 1) : null y: Math.min(Math.max(mouseArea.height - (value * mouseArea.height / valueAxis.max) - height - Style.margins, 0), mouseArea.height - height) width: tooltipLayout.implicitWidth + Style.smallMargins * 2 diff --git a/nymea-app/ui/mainviews/dashboard/DashboardGraphDelegate.qml b/nymea-app/ui/mainviews/dashboard/DashboardGraphDelegate.qml index 26cf1f63..554c3ca2 100644 --- a/nymea-app/ui/mainviews/dashboard/DashboardGraphDelegate.qml +++ b/nymea-app/ui/mainviews/dashboard/DashboardGraphDelegate.qml @@ -71,7 +71,6 @@ DashboardDelegateBase { // property string interfaceName: parent.interfaceName stateType: root.stateType // property State state: root.state - } }