mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 16:37:52 +01:00
Fixed the issue that graph draws out of the boundary. (#6651)
This commit is contained in:
parent
5142d294f5
commit
8b6a358452
@ -177,22 +177,26 @@ void Graph::draw(Display *buff, uint16_t x_offset, uint16_t y_offset, Color colo
|
||||
bool b = (trace->get_line_type() & bit) == bit;
|
||||
if (b) {
|
||||
int16_t y = (int16_t) roundf((this->height_ - 1) * (1.0 - v)) - thick / 2 + y_offset;
|
||||
auto draw_pixel_at = [&buff, c, y_offset, this](int16_t x, int16_t y) {
|
||||
if (y >= y_offset && y < y_offset + this->height_)
|
||||
buff->draw_pixel_at(x, y, c);
|
||||
};
|
||||
if (!continuous || !has_prev || !prev_b || (abs(y - prev_y) <= thick)) {
|
||||
for (int16_t t = 0; t < thick; t++) {
|
||||
buff->draw_pixel_at(x, y + t, c);
|
||||
draw_pixel_at(x, y + t);
|
||||
}
|
||||
} else {
|
||||
int16_t mid_y = (y + prev_y + thick) / 2;
|
||||
if (y > prev_y) {
|
||||
for (int16_t t = prev_y + thick; t <= mid_y; t++)
|
||||
buff->draw_pixel_at(x + 1, t, c);
|
||||
draw_pixel_at(x + 1, t);
|
||||
for (int16_t t = mid_y + 1; t < y + thick; t++)
|
||||
buff->draw_pixel_at(x, t, c);
|
||||
draw_pixel_at(x, t);
|
||||
} else {
|
||||
for (int16_t t = prev_y - 1; t >= mid_y; t--)
|
||||
buff->draw_pixel_at(x + 1, t, c);
|
||||
draw_pixel_at(x + 1, t);
|
||||
for (int16_t t = mid_y - 1; t >= y; t--)
|
||||
buff->draw_pixel_at(x, t, c);
|
||||
draw_pixel_at(x, t);
|
||||
}
|
||||
}
|
||||
prev_y = y;
|
||||
|
Loading…
Reference in New Issue
Block a user