From fa25cebed52d48a026ad48463ed7e6170e61ae31 Mon Sep 17 00:00:00 2001 From: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com> Date: Sat, 15 Mar 2025 06:55:20 +0100 Subject: [PATCH] Added getters for graphs ymin and ymax (#8112) Co-authored-by: guillempages --- esphome/components/graph/graph.cpp | 4 ++++ esphome/components/graph/graph.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/esphome/components/graph/graph.cpp b/esphome/components/graph/graph.cpp index cbe059b255..5abf2ade0d 100644 --- a/esphome/components/graph/graph.cpp +++ b/esphome/components/graph/graph.cpp @@ -132,6 +132,10 @@ void Graph::draw(Display *buff, uint16_t x_offset, uint16_t y_offset, Color colo yrange = ymax - ymin; } + // Store graph limts + this->graph_limit_max_ = ymax; + this->graph_limit_min_ = ymin; + /// Draw grid if (!std::isnan(this->gridspacing_y_)) { for (int y = yn; y <= ym; y++) { diff --git a/esphome/components/graph/graph.h b/esphome/components/graph/graph.h index 34accb7d3a..468583ca21 100644 --- a/esphome/components/graph/graph.h +++ b/esphome/components/graph/graph.h @@ -161,11 +161,15 @@ class Graph : public Component { uint32_t get_duration() { return duration_; } uint32_t get_width() { return width_; } uint32_t get_height() { return height_; } + float get_graph_limit_min() { return graph_limit_min_; } + float get_graph_limit_max() { return graph_limit_max_; } protected: uint32_t duration_; /// in seconds uint32_t width_; /// in pixels uint32_t height_; /// in pixels + float graph_limit_min_{NAN}; + float graph_limit_max_{NAN}; float min_value_{NAN}; float max_value_{NAN}; float min_range_{1.0};