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:
unhold 2023-04-12 23:18:09 +02:00 committed by GitHub
parent d75daa9644
commit 443c3c2a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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_)) {