81 lines
2.2 KiB
C++
81 lines
2.2 KiB
C++
#ifndef TEMPERATURE_CHART_H
|
|
#define TEMPERATURE_CHART_H
|
|
|
|
#include <gtk/gtk.h>
|
|
#include <cairo.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <cstdint>
|
|
|
|
struct DataPoint {
|
|
double temperature;
|
|
int64_t timestamp;
|
|
};
|
|
|
|
struct SeriesData {
|
|
std::vector<DataPoint> points;
|
|
GdkRGBA color;
|
|
std::string name;
|
|
};
|
|
|
|
class TemperatureChart {
|
|
public:
|
|
TemperatureChart(GtkWidget *parent = nullptr);
|
|
~TemperatureChart();
|
|
|
|
GtkWidget* getWidget() const { return drawingArea; }
|
|
|
|
bool addTemperatureData(const std::string &device, const std::string &sensor,
|
|
double temperature, int64_t timestamp);
|
|
void clear();
|
|
void draw();
|
|
|
|
// Get list of series with their colors
|
|
std::vector<std::pair<std::string, GdkRGBA>> getSeriesColors() const;
|
|
void setSeriesColor(const std::string &seriesName, const GdkRGBA &color);
|
|
void drawChart(GtkDrawingArea *area, cairo_t *cr, int width, int height);
|
|
|
|
private:
|
|
void setupColors();
|
|
GdkRGBA getColorForSeries(const std::string &seriesKey);
|
|
void redraw();
|
|
void updateThemeColors();
|
|
|
|
static gboolean onTick(gpointer userData);
|
|
static void onLeave(GtkEventControllerMotion *motion, gpointer userData);
|
|
|
|
struct NearestPoint {
|
|
bool found;
|
|
double temperature;
|
|
int64_t timestamp;
|
|
std::string seriesName;
|
|
double distance;
|
|
};
|
|
|
|
NearestPoint findNearestDataPoint(double mouseX, double mouseY, int width, int height);
|
|
void showTooltip(double x, double y, const NearestPoint &point);
|
|
void hideTooltip();
|
|
|
|
GtkWidget *drawingArea;
|
|
GtkWidget *tooltipWindow;
|
|
GtkWidget *tooltipLabel;
|
|
std::map<std::string, SeriesData> seriesMap;
|
|
std::map<std::string, GdkRGBA> colorMap;
|
|
int maxDataPoints;
|
|
guint tickHandler;
|
|
double lastMouseX, lastMouseY;
|
|
|
|
// Cairo drawing state
|
|
double minTemp, maxTemp;
|
|
int64_t minTime, maxTime;
|
|
static constexpr int MAX_TIME_MS = 600000; // 10 minutes in milliseconds
|
|
static constexpr double MIN_TEMP = 10.0;
|
|
static constexpr double MAX_TEMP = 110.0;
|
|
|
|
// Theme colors
|
|
GdkRGBA bgColor, textColor, gridColor, axisColor;
|
|
};
|
|
|
|
#endif // TEMPERATURE_CHART_H
|