From de2a92e45de9444b7bcc88e8a0c8984c6240b53b Mon Sep 17 00:00:00 2001 From: chiahsing Date: Fri, 26 Apr 2024 05:01:51 +0800 Subject: [PATCH] Fix graph hangs when y <= 0 (#6593) --- esphome/components/graph/graph.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/graph/graph.cpp b/esphome/components/graph/graph.cpp index 0e437a3425..1178af911d 100644 --- a/esphome/components/graph/graph.cpp +++ b/esphome/components/graph/graph.cpp @@ -164,7 +164,7 @@ void Graph::draw(Display *buff, uint16_t x_offset, uint16_t y_offset, Color colo ESP_LOGV(TAG, "Updating graph. ymin %f, ymax %f", ymin, ymax); for (auto *trace : traces_) { Color c = trace->get_line_color(); - uint16_t thick = trace->get_line_thickness(); + int16_t thick = trace->get_line_thickness(); bool continuous = trace->get_continuous(); bool has_prev = false; bool prev_b = false; @@ -178,20 +178,20 @@ void Graph::draw(Display *buff, uint16_t x_offset, uint16_t y_offset, Color colo if (b) { int16_t y = (int16_t) roundf((this->height_ - 1) * (1.0 - v)) - thick / 2 + y_offset; if (!continuous || !has_prev || !prev_b || (abs(y - prev_y) <= thick)) { - for (uint16_t t = 0; t < thick; t++) { + for (int16_t t = 0; t < thick; t++) { buff->draw_pixel_at(x, y + t, c); } } else { int16_t mid_y = (y + prev_y + thick) / 2; if (y > prev_y) { - for (uint16_t t = prev_y + thick; t <= mid_y; t++) + for (int16_t t = prev_y + thick; t <= mid_y; t++) buff->draw_pixel_at(x + 1, t, c); - for (uint16_t t = mid_y + 1; t < y + thick; t++) + for (int16_t t = mid_y + 1; t < y + thick; t++) buff->draw_pixel_at(x, t, c); } else { - for (uint16_t t = prev_y - 1; t >= mid_y; t--) + for (int16_t t = prev_y - 1; t >= mid_y; t--) buff->draw_pixel_at(x + 1, t, c); - for (uint16_t t = mid_y - 1; t >= y; t--) + for (int16_t t = mid_y - 1; t >= y; t--) buff->draw_pixel_at(x, t, c); } }