added min, max, avg
This commit is contained in:
parent
905cfcaf01
commit
563ccdd8dc
@ -62,6 +62,7 @@ private:
|
|||||||
bool found;
|
bool found;
|
||||||
double temperature;
|
double temperature;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
|
std::string seriesId;
|
||||||
std::string seriesName;
|
std::string seriesName;
|
||||||
double distance;
|
double distance;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -559,6 +559,7 @@ TemperatureChart::NearestPoint TemperatureChart::findNearestDataPoint(double mou
|
|||||||
result.found = true;
|
result.found = true;
|
||||||
result.temperature = point.temperature;
|
result.temperature = point.temperature;
|
||||||
result.timestamp = point.timestamp;
|
result.timestamp = point.timestamp;
|
||||||
|
result.seriesId = series.id;
|
||||||
result.seriesName = series.name;
|
result.seriesName = series.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -583,8 +584,23 @@ void TemperatureChart::showTooltip(double x, double y, const NearestPoint &point
|
|||||||
gtk_widget_set_parent(tooltipWindow, drawingArea);
|
gtk_widget_set_parent(tooltipWindow, drawingArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the tooltip text with real current time
|
// Calculate min/max/average from currently visible history in this series.
|
||||||
char tooltipText[256];
|
double minSeriesTemp = point.temperature;
|
||||||
|
double maxSeriesTemp = point.temperature;
|
||||||
|
double avgSeriesTemp = point.temperature;
|
||||||
|
auto seriesIt = seriesMap.find(point.seriesId);
|
||||||
|
if (seriesIt != seriesMap.end() && !seriesIt->second.points.empty()) {
|
||||||
|
const auto &points = seriesIt->second.points;
|
||||||
|
minSeriesTemp = points.front().temperature;
|
||||||
|
maxSeriesTemp = points.front().temperature;
|
||||||
|
double sum = 0.0;
|
||||||
|
for (const auto &dataPoint : points) {
|
||||||
|
minSeriesTemp = std::min(minSeriesTemp, dataPoint.temperature);
|
||||||
|
maxSeriesTemp = std::max(maxSeriesTemp, dataPoint.temperature);
|
||||||
|
sum += dataPoint.temperature;
|
||||||
|
}
|
||||||
|
avgSeriesTemp = sum / points.size();
|
||||||
|
}
|
||||||
|
|
||||||
// Convert timestamp from milliseconds since epoch to time structure
|
// Convert timestamp from milliseconds since epoch to time structure
|
||||||
time_t timeSeconds = point.timestamp / 1000;
|
time_t timeSeconds = point.timestamp / 1000;
|
||||||
@ -595,12 +611,16 @@ void TemperatureChart::showTooltip(double x, double y, const NearestPoint &point
|
|||||||
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", timeinfo);
|
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", timeinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(tooltipText, sizeof(tooltipText),
|
char tooltipText[512];
|
||||||
"%s\n%.1f°C\n%s",
|
snprintf(tooltipText, sizeof(tooltipText),
|
||||||
|
"%s\nAktualni: %.1f°C\nMinimum: %.1f°C\nMaximum: %.1f°C\nPrumer: %.1f°C\n%s",
|
||||||
point.seriesName.c_str(),
|
point.seriesName.c_str(),
|
||||||
point.temperature,
|
point.temperature,
|
||||||
|
minSeriesTemp,
|
||||||
|
maxSeriesTemp,
|
||||||
|
avgSeriesTemp,
|
||||||
timeStr);
|
timeStr);
|
||||||
|
|
||||||
gtk_label_set_text(GTK_LABEL(tooltipLabel), tooltipText);
|
gtk_label_set_text(GTK_LABEL(tooltipLabel), tooltipText);
|
||||||
|
|
||||||
// Position the tooltip
|
// Position the tooltip
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user