Another fix for the energy tooltips
This commit is contained in:
parent
a54dd4d757
commit
41eb9f2a0c
@ -193,8 +193,10 @@ EnergyLogEntry *EnergyLogs::find(const QDateTime ×tamp)
|
|||||||
|
|
||||||
int index = qRound(1.0 * first.secsTo(timestamp) / (m_sampleRate * 60));
|
int index = qRound(1.0 * first.secsTo(timestamp) / (m_sampleRate * 60));
|
||||||
if (index < 0 || index >= m_list.count()) {
|
if (index < 0 || index >= m_list.count()) {
|
||||||
|
// qWarning() << "finding:" << timestamp << index << first.toString() << "NOT FOUND" << m_list.last()->timestamp();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
// qWarning() << "finding:" << timestamp << index << first.toString() << m_list.at(index)->timestamp();
|
||||||
return m_list.at(index);
|
return m_list.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,16 +58,37 @@ Item {
|
|||||||
readonly property int visibleValues: range / sampleRate
|
readonly property int visibleValues: range / sampleRate
|
||||||
|
|
||||||
readonly property var startTime: {
|
readonly property var startTime: {
|
||||||
var date = new Date(now);
|
var date = new Date(fixTime(now));
|
||||||
date.setTime(date.getTime() - range * 60000 + 2000);
|
date.setTime(date.getTime() - range * 60000 + 2000);
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property var endTime: {
|
readonly property var endTime: {
|
||||||
var date = new Date(now);
|
var date = new Date(fixTime(now));
|
||||||
date.setTime(date.getTime() + 2000)
|
date.setTime(date.getTime() + 2000)
|
||||||
return date;
|
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 {
|
Component {
|
||||||
@ -564,7 +585,7 @@ Item {
|
|||||||
backgroundItem: chartView
|
backgroundItem: chartView
|
||||||
backgroundRect: Qt.rect(mouseArea.x + toolTip.x, mouseArea.y + toolTip.y, toolTip.width, toolTip.height)
|
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 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)
|
property PowerBalanceLogEntry entry: powerBalanceLogs.find(timestamp)
|
||||||
|
|
||||||
|
|||||||
@ -273,7 +273,7 @@ StatsBase {
|
|||||||
|
|
||||||
function adjustMax(newValue) {
|
function adjustMax(newValue) {
|
||||||
if (max < newValue) {
|
if (max < newValue) {
|
||||||
print("adjusting to new max", newValue)
|
// print("adjusting to new max", newValue)
|
||||||
max = newValue // Math.ceil(newValue / 100) * 100
|
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 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)
|
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
|
visible: (mouseArea.containsMouse || mouseArea.tooltipping) && !mouseArea.dragging
|
||||||
|
|
||||||
|
|||||||
@ -31,18 +31,39 @@ Item {
|
|||||||
readonly property int visibleValues: range / sampleRate
|
readonly property int visibleValues: range / sampleRate
|
||||||
|
|
||||||
readonly property var startTime: {
|
readonly property var startTime: {
|
||||||
var date = new Date(now);
|
var date = new Date(fixTime(now));
|
||||||
date.setTime(date.getTime() - (range * 60 * 1000) + 2000);
|
date.setTime(date.getTime() - (range * 60 * 1000));
|
||||||
print("setting starttime to", date, range)
|
print("setting starttime to", date, range)
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property var endTime: {
|
readonly property var endTime: {
|
||||||
var date = new Date(now);
|
var date = new Date(fixTime(now));
|
||||||
date.setTime(date.getTime() + 2000)
|
date.setTime(date.getTime())
|
||||||
print("setting endtime to", date, range)
|
print("setting endtime to", date, range)
|
||||||
return date;
|
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 {
|
Connections {
|
||||||
@ -490,9 +511,10 @@ Item {
|
|||||||
backgroundItem: chartView
|
backgroundItem: chartView
|
||||||
backgroundRect: Qt.rect(mouseArea.x + toolTip.x, mouseArea.y + toolTip.y, toolTip.width, toolTip.height)
|
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 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)
|
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 xOnRight: Math.max(0, mouseArea.mouseX) + Style.smallMargins
|
||||||
property int xOnLeft: Math.min(mouseArea.mouseX, mouseArea.width) - Style.smallMargins - width
|
property int xOnLeft: Math.min(mouseArea.mouseX, mouseArea.width) - Style.smallMargins - width
|
||||||
|
|||||||
@ -31,16 +31,38 @@ Item {
|
|||||||
readonly property int visibleValues: range / sampleRate
|
readonly property int visibleValues: range / sampleRate
|
||||||
|
|
||||||
readonly property var startTime: {
|
readonly property var startTime: {
|
||||||
var date = new Date(now);
|
var date = new Date(fixTime(now));
|
||||||
date.setTime(date.getTime() - range * 60000 + 2000);
|
date.setTime(date.getTime() - range * 60000 + 2000);
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property var endTime: {
|
readonly property var endTime: {
|
||||||
var date = new Date(now);
|
var date = new Date(fixTime(now));
|
||||||
date.setTime(date.getTime() + 2000)
|
date.setTime(date.getTime() + 2000)
|
||||||
return date;
|
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 {
|
Connections {
|
||||||
@ -480,7 +502,7 @@ Item {
|
|||||||
backgroundItem: chartView
|
backgroundItem: chartView
|
||||||
backgroundRect: Qt.rect(mouseArea.x + toolTip.x, mouseArea.y + toolTip.y, toolTip.width, toolTip.height)
|
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 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)
|
property PowerBalanceLogEntry entry: powerBalanceLogs.find(timestamp)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user