From 76350c0350e6bd0335668d79842339732b3823ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Fri, 26 Feb 2021 22:17:03 +0100 Subject: Rescale graph when value of total is changed --- Meter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Meter.c') diff --git a/Meter.c b/Meter.c index e42b29b9..e8bfaad0 100644 --- a/Meter.c +++ b/Meter.c @@ -334,7 +334,6 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { double value = 0.0; for (uint8_t i = 0; i < this->curItems; i++) value += this->values[i]; - value /= this->total; data->values[nValues - 1] = value; } @@ -345,8 +344,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { } for (; i < nValues - 1; i += 2, k++) { int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT; - int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix); - int v2 = CLAMP((int) lround(data->values[i + 1] * pix), 1, pix); + if (this->total < 1) + this->total = 1; + int v1 = CLAMP((int) lround(data->values[i] / this->total * pix), 1, pix); + int v2 = CLAMP((int) lround(data->values[i + 1] / this->total * pix), 1, pix); int colorIdx = GRAPH_1; for (int line = 0; line < GRAPH_HEIGHT; line++) { -- cgit v1.2.3