diff options
author | Michael F. Schönitzer <michael@schoenitzer.de> | 2021-02-26 22:17:03 +0100 |
---|---|---|
committer | Michael F. Schönitzer <michael@schoenitzer.de> | 2021-02-28 17:42:10 +0100 |
commit | 76350c0350e6bd0335668d79842339732b3823ee (patch) | |
tree | 78464c8e63076b28a9327682402fa419731d2a6c /Meter.c | |
parent | 12c2337939cbdee21c437c28646f128667a162de (diff) |
Rescale graph when value of total is changed
Diffstat (limited to 'Meter.c')
-rw-r--r-- | Meter.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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++) { |