Skip to content

Commit

Permalink
Record new graph data even when no graph is drawn.
Browse files Browse the repository at this point in the history
Fixes a regression caused by 74b2884.

When a graph meter is too narrow to draw the graph, but the graph data
buffer is allocated, the meter should keep recording new values.

Signed-off-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 committed Oct 26, 2023
1 parent 49bc76d commit 7784c99
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "Meter.h"

#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -295,11 +296,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
mvaddnstr(y, x, caption, captionLen);
x += captionLen;
w -= captionLen;
if (w <= 0)
return;

GraphData* data = &this->drawData;
if ((size_t)w * 2 > data->nValues && MAX_METER_GRAPHDATA_VALUES > data->nValues) {
assert(data->nValues / 2 <= INT_MAX);
if (w > (int)(data->nValues / 2) && MAX_METER_GRAPHDATA_VALUES > data->nValues) {
size_t oldNValues = data->nValues;
data->nValues = MAXIMUM(oldNValues + oldNValues / 2, (size_t)w * 2);
data->nValues = MINIMUM(data->nValues, MAX_METER_GRAPHDATA_VALUES);
Expand All @@ -308,10 +308,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
memset(data->values, 0, (data->nValues - oldNValues) * sizeof(*data->values));
}
const size_t nValues = data->nValues;
if ((size_t)w * 2 > nValues) {
x += w - nValues / 2;
w = nValues / 2;
}
if (nValues < 1)
return;

const Machine* host = this->host;
if (!timercmp(&host->realtime, &(data->time), <)) {
Expand All @@ -325,6 +323,13 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
data->values[nValues - 1] = sumPositiveValues(this->values, this->curItems);
}

if (w <= 0)
return;
if ((size_t)w > nValues / 2) {
x += w - nValues / 2;
w = nValues / 2;
}

const char* const* GraphMeterMode_dots;
int GraphMeterMode_pixPerRow;
#ifdef HAVE_LIBNCURSESW
Expand Down

0 comments on commit 7784c99

Please sign in to comment.