mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Fix graph hangs when y <= 0 (#6593)
This commit is contained in:
parent
0662c5e0fb
commit
de2a92e45d
1 changed files with 6 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue