Fix min/max calculation for bool type graphs

Fixes #102
This commit is contained in:
Michael Zanetti 2019-01-08 21:11:43 +01:00
parent 0b0e33a7b5
commit 4883fa6c43
2 changed files with 31 additions and 9 deletions

View File

@ -253,6 +253,15 @@ void LogsModelNg::logsReply(const QVariantMap &data)
// End the batch at 1 again
m_graphSeries->append(QPointF(entry->timestamp().addSecs(-1).toMSecsSinceEpoch(), 1));
}
// Adjust min/max
if (!newMin.isValid() || newMin > entry->value()) {
newMin = 0;
}
if (!newMax.isValid() || newMax < entry->value()) {
newMax = 1;
}
} else {
// if (i > 0) {
// LogEntry *newerEntry = newBlock.at(i - 1);
@ -268,18 +277,21 @@ void LogsModelNg::logsReply(const QVariantMap &data)
}
// qDebug() << "Adding line series point:" << (offset + i) << entry->timestamp().toMSecsSinceEpoch() << (entry->value().toReal());
m_graphSeries->append(QPointF(entry->timestamp().toMSecsSinceEpoch(), entry->value().toReal()));
// Adjust min/max
if (!newMin.isValid() || newMin > entry->value()) {
newMin = entry->value().toReal();
}
if (!newMax.isValid() || newMax < entry->value()) {
newMax = entry->value().toReal();
}
}
}
if (!newMin.isValid() || newMin > entry->value()) {
newMin = entry->value().toReal();
}
if (!newMax.isValid() || newMax < entry->value()) {
newMax = entry->value().toReal();
}
}
endInsertRows();
emit countChanged();
// qDebug() << "min" << m_minValue << "max" << m_maxValue << "newMin" << newMin << "newMax" << newMax;
qDebug() << "min" << m_minValue << "max" << m_maxValue << "newMin" << newMin << "newMax" << newMax;
if (m_minValue != newMin) {
m_minValue = newMin;
emit minValueChanged();

View File

@ -104,8 +104,17 @@ Item {
ValueAxis {
id: yAxis
max: Math.ceil(logsModelNg.maxValue + Math.abs(logsModelNg.maxValue * .05))
max: {
switch (root.stateType.type.toLowerCase()) {
case "bool":
return 1;
default:
Math.ceil(logsModelNg.maxValue + Math.abs(logsModelNg.maxValue * .05))
}
}
min: Math.floor(logsModelNg.minValue - Math.abs(logsModelNg.minValue * .05))
onMinChanged: print("min set to", min)
onMaxChanged: print("max set to", min)
labelsFont.pixelSize: app.smallFont
labelFormat: {
switch (root.stateType.type.toLowerCase()) {
@ -241,6 +250,7 @@ Item {
id: lineSeries1
onPointAdded: {
var newPoint = lineSeries1.at(index)
print("pointadded", newPoint.x, newPoint.y)
if (newPoint.x > lineSeries0.at(0).x) {
lineSeries0.replace(0, newPoint.x, 0)
@ -254,7 +264,6 @@ Item {
}
var diffMaxToNew = newPoint.x - xAxis.max.getTime();
print("diffToNew is", diffMaxToNew)
if (diffMaxToNew < 1000 * 60 * 5) {
chartView.animationOptions = ChartView.NoAnimation
var newMin = xAxis.min.getTime() + diffMaxToNew;
@ -262,6 +271,7 @@ Item {
xAxis.min = new Date(newMin)
chartView.animationOptions = ChartView.SeriesAnimations
}
}
}
color: Qt.rgba(root.color.r, root.color.g, root.color.b, .3)