Merge PR #890: Another fix for the energy tooltips

This commit is contained in:
jenkins 2022-09-24 13:28:42 +02:00
commit c4e7c023b7
5 changed files with 81 additions and 13 deletions

View File

@ -193,8 +193,10 @@ EnergyLogEntry *EnergyLogs::find(const QDateTime &timestamp)
int index = qRound(1.0 * first.secsTo(timestamp) / (m_sampleRate * 60));
if (index < 0 || index >= m_list.count()) {
// qWarning() << "finding:" << timestamp << index << first.toString() << "NOT FOUND" << m_list.last()->timestamp();
return nullptr;
}
// qWarning() << "finding:" << timestamp << index << first.toString() << m_list.at(index)->timestamp();
return m_list.at(index);
}

View File

@ -58,16 +58,37 @@ Item {
readonly property int visibleValues: range / sampleRate
readonly property var startTime: {
var date = new Date(now);
var date = new Date(fixTime(now));
date.setTime(date.getTime() - range * 60000 + 2000);
return date;
}
readonly property var endTime: {
var date = new Date(now);
var date = new Date(fixTime(now));
date.setTime(date.getTime() + 2000)
return date;
}
function fixTime(timestamp) {
switch (sampleRate) {
case EnergyLogs.SampleRate1Min:
timestamp.setSeconds(0, 0)
break;
case EnergyLogs.SampleRate15Mins:
timestamp.setMinutes(timestamp.getMinutes() - timestamp.getMinutes() % 15, 0, 0)
break;
case EnergyLogs.SampleRate1Hour:
timestamp.setMinutes(0, 0, 0);
break;
case EnergyLogs.SampleRate3Hours:
timestamp.setHours(timestamp.getHours() % 3, 0, 0, 0);
break;
case EnergyLogs.SampleRate1Day:
timestamp.setHours(0, 0, 0, 0)
break;
}
return timestamp
}
}
Component {
@ -564,7 +585,7 @@ Item {
backgroundItem: chartView
backgroundRect: Qt.rect(mouseArea.x + toolTip.x, mouseArea.y + toolTip.y, toolTip.width, toolTip.height)
property int idx: Math.min(d.visibleValues, Math.max(0, Math.ceil(mouseArea.mouseX * d.visibleValues / mouseArea.width)))
property int idx: Math.min(d.visibleValues, Math.max(0, Math.round(mouseArea.mouseX * d.visibleValues / mouseArea.width)))
property var timestamp: new Date(Math.min(d.endTime.getTime(), Math.max(d.startTime, d.startTime.getTime() + (idx * d.sampleRate * 60000))))
property PowerBalanceLogEntry entry: powerBalanceLogs.find(timestamp)

View File

@ -273,7 +273,7 @@ StatsBase {
function adjustMax(newValue) {
if (max < newValue) {
print("adjusting to new max", newValue)
// print("adjusting to new max", newValue)
max = newValue // Math.ceil(newValue / 100) * 100
}
}
@ -457,6 +457,7 @@ StatsBase {
property int idx: visible ? Math.min(d.config.count -1, Math.max(0, Math.ceil(mouseArea.mouseX * d.config.count / mouseArea.width) - 1)) : 0
property date timestamp: root.calculateTimestamp(d.config.startTime(), d.config.sampleRate, d.startOffset + idx)
onTimestampChanged: print("idx changed", idx, "timestamp", timestamp)
visible: (mouseArea.containsMouse || mouseArea.tooltipping) && !mouseArea.dragging

View File

@ -31,18 +31,39 @@ Item {
readonly property int visibleValues: range / sampleRate
readonly property var startTime: {
var date = new Date(now);
date.setTime(date.getTime() - (range * 60 * 1000) + 2000);
var date = new Date(fixTime(now));
date.setTime(date.getTime() - (range * 60 * 1000));
print("setting starttime to", date, range)
return date;
}
readonly property var endTime: {
var date = new Date(now);
date.setTime(date.getTime() + 2000)
var date = new Date(fixTime(now));
date.setTime(date.getTime())
print("setting endtime to", date, range)
return date;
}
function fixTime(timestamp) {
switch (sampleRate) {
case EnergyLogs.SampleRate1Min:
timestamp.setSeconds(0, 0)
break;
case EnergyLogs.SampleRate15Mins:
timestamp.setMinutes(timestamp.getMinutes() - timestamp.getMinutes() % 15, 0, 0)
break;
case EnergyLogs.SampleRate1Hour:
timestamp.setMinutes(0, 0, 0);
break;
case EnergyLogs.SampleRate3Hours:
timestamp.setHours(timestamp.getHours() % 3, 0, 0, 0);
break;
case EnergyLogs.SampleRate1Day:
timestamp.setHours(0, 0, 0, 0)
break;
}
return timestamp
}
}
Connections {
@ -490,9 +511,10 @@ Item {
backgroundItem: chartView
backgroundRect: Qt.rect(mouseArea.x + toolTip.x, mouseArea.y + toolTip.y, toolTip.width, toolTip.height)
property int idx: Math.min(d.visibleValues, Math.max(0, Math.ceil(mouseArea.mouseX * d.visibleValues / mouseArea.width)))
property var timestamp: new Date(Math.min(d.endTime.getTime(), Math.max(d.startTime, d.startTime.getTime() + (idx * d.sampleRate * 60000))))
property int idx: Math.min(d.visibleValues, Math.max(0, Math.round(mouseArea.mouseX * d.visibleValues / mouseArea.width)))
property var timestamp: new Date(Math.min(d.endTime.getTime(), Math.max(d.startTime.getTime(), d.startTime.getTime() + (idx * d.sampleRate * 60000))))
property PowerBalanceLogEntry entry: powerBalanceLogs.find(timestamp)
// onTimestampChanged: print("idx changed", idx, "timestamp", timestamp)
property int xOnRight: Math.max(0, mouseArea.mouseX) + Style.smallMargins
property int xOnLeft: Math.min(mouseArea.mouseX, mouseArea.width) - Style.smallMargins - width

View File

@ -31,16 +31,38 @@ Item {
readonly property int visibleValues: range / sampleRate
readonly property var startTime: {
var date = new Date(now);
var date = new Date(fixTime(now));
date.setTime(date.getTime() - range * 60000 + 2000);
return date;
}
readonly property var endTime: {
var date = new Date(now);
var date = new Date(fixTime(now));
date.setTime(date.getTime() + 2000)
return date;
}
function fixTime(timestamp) {
switch (sampleRate) {
case EnergyLogs.SampleRate1Min:
timestamp.setSeconds(0, 0)
break;
case EnergyLogs.SampleRate15Mins:
timestamp.setMinutes(timestamp.getMinutes() - timestamp.getMinutes() % 15, 0, 0)
break;
case EnergyLogs.SampleRate1Hour:
timestamp.setMinutes(0, 0, 0);
break;
case EnergyLogs.SampleRate3Hours:
timestamp.setHours(timestamp.getHours() % 3, 0, 0, 0);
break;
case EnergyLogs.SampleRate1Day:
timestamp.setHours(0, 0, 0, 0)
break;
}
return timestamp
}
}
Connections {
@ -480,7 +502,7 @@ Item {
backgroundItem: chartView
backgroundRect: Qt.rect(mouseArea.x + toolTip.x, mouseArea.y + toolTip.y, toolTip.width, toolTip.height)
property int idx: Math.min(d.visibleValues, Math.max(0, Math.ceil(mouseArea.mouseX * d.visibleValues / mouseArea.width)))
property int idx: Math.min(d.visibleValues, Math.max(0, Math.round(mouseArea.mouseX * d.visibleValues / mouseArea.width)))
property var timestamp: new Date(Math.min(d.endTime.getTime(), Math.max(d.startTime, d.startTime.getTime() + (idx * d.sampleRate * 60000))))
property PowerBalanceLogEntry entry: powerBalanceLogs.find(timestamp)