added min, max, avg
This commit is contained in:
parent
905cfcaf01
commit
563ccdd8dc
@ -62,6 +62,7 @@ private:
|
||||
bool found;
|
||||
double temperature;
|
||||
int64_t timestamp;
|
||||
std::string seriesId;
|
||||
std::string seriesName;
|
||||
double distance;
|
||||
};
|
||||
|
||||
@ -559,6 +559,7 @@ TemperatureChart::NearestPoint TemperatureChart::findNearestDataPoint(double mou
|
||||
result.found = true;
|
||||
result.temperature = point.temperature;
|
||||
result.timestamp = point.timestamp;
|
||||
result.seriesId = series.id;
|
||||
result.seriesName = series.name;
|
||||
}
|
||||
}
|
||||
@ -583,8 +584,23 @@ void TemperatureChart::showTooltip(double x, double y, const NearestPoint &point
|
||||
gtk_widget_set_parent(tooltipWindow, drawingArea);
|
||||
}
|
||||
|
||||
// Format the tooltip text with real current time
|
||||
char tooltipText[256];
|
||||
// Calculate min/max/average from currently visible history in this series.
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
snprintf(tooltipText, sizeof(tooltipText),
|
||||
"%s\n%.1f°C\n%s",
|
||||
char tooltipText[512];
|
||||
snprintf(tooltipText, sizeof(tooltipText),
|
||||
"%s\nAktualni: %.1f°C\nMinimum: %.1f°C\nMaximum: %.1f°C\nPrumer: %.1f°C\n%s",
|
||||
point.seriesName.c_str(),
|
||||
point.temperature,
|
||||
minSeriesTemp,
|
||||
maxSeriesTemp,
|
||||
avgSeriesTemp,
|
||||
timeStr);
|
||||
|
||||
|
||||
gtk_label_set_text(GTK_LABEL(tooltipLabel), tooltipText);
|
||||
|
||||
// Position the tooltip
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user