From d61a97cb4a57ecd40cedec6bf1341ff97ac3e3a0 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 20 Oct 2023 23:33:00 +0200 Subject: [PATCH] Fix bool charts after inverting them --- nymea-app/ui/customviews/StateChart.qml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/nymea-app/ui/customviews/StateChart.qml b/nymea-app/ui/customviews/StateChart.qml index edc18e28..9fcc348c 100644 --- a/nymea-app/ui/customviews/StateChart.qml +++ b/nymea-app/ui/customviews/StateChart.qml @@ -95,11 +95,18 @@ Item { value = false; } value *= root.inverted ? -1 : 1 + var previousEntry = i > 0 ? logsModel.get(i-1) : null; + var previousValue = previousEntry ? previousEntry.values[root.stateType.name] : false + if (previousValue == null) { + previousValue = false + } - // for booleans, we'll insert the opposite value right before the new one so the position is doubled + // for booleans, we'll insert the previous value right before the new one so the position is doubled var insertIdx = (index + i) * 2 - valueSeries.insert(insertIdx+1, entry.timestamp.getTime() - 500, !value) - valueSeries.insert(insertIdx, entry.timestamp, value) +// print("inserting bool 1", insertIdx, entry.timestamp.getTime() - 500, !value, new Date(entry.timestamp.getTime() - 500)) + valueSeries.insert(insertIdx, entry.timestamp.getTime() - 500, previousValue) +// print("inserting bool 2", insertIdx + 1, entry.timestamp.getTime(), value, entry.timestamp) + valueSeries.insert(insertIdx+1, entry.timestamp, value) } else { var value = entry.values[root.stateType.name] @@ -117,9 +124,9 @@ Item { } if (root.stateType.type.toLowerCase() == "bool") { - var last = valueSeries.at(0); + var last = valueSeries.at(valueSeries.count-1); if (last.x < d.endTime) { - valueSeries.insert(0, d.endTime, last.y) + valueSeries.append(d.endTime, last.y) zeroSeries.ensureValue(d.endTime) } }