mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
Fix graph limits for negative values and other corner cases (#4253)
Fix lower graph limit for negative values by rounding down instead of truncating. Consistently handle the corner cases: empty trace, min=max (e.g. single value) by drawing the grid lines for a single grid division.
This commit is contained in:
parent
d75daa9644
commit
443c3c2a56
1 changed files with 12 additions and 5 deletions
|
@ -122,11 +122,18 @@ void Graph::draw(DisplayBuffer *buff, uint16_t x_offset, uint16_t y_offset, Colo
|
|||
}
|
||||
|
||||
// Adjust limits to nice y_per_div boundaries
|
||||
int yn = int(ymin / y_per_div);
|
||||
int ym = int(ymax / y_per_div) + int(1 * (fmodf(ymax, y_per_div) != 0));
|
||||
ymin = yn * y_per_div;
|
||||
ymax = ym * y_per_div;
|
||||
yrange = ymax - ymin;
|
||||
int yn = 0;
|
||||
int ym = 1;
|
||||
if (!std::isnan(ymin) && !std::isnan(ymax)) {
|
||||
yn = (int) floorf(ymin / y_per_div);
|
||||
ym = (int) ceilf(ymax / y_per_div);
|
||||
if (yn == ym) {
|
||||
ym++;
|
||||
}
|
||||
ymin = yn * y_per_div;
|
||||
ymax = ym * y_per_div;
|
||||
yrange = ymax - ymin;
|
||||
}
|
||||
|
||||
/// Draw grid
|
||||
if (!std::isnan(this->gridspacing_y_)) {
|
||||
|
|
Loading…
Reference in a new issue