Fix graph hangs when y <= 0 (#6593)

This commit is contained in:
chiahsing 2024-04-26 05:01:51 +08:00 committed by GitHub
parent 0662c5e0fb
commit de2a92e45d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}
}