Added an auto-maximum feature to graphs

This commit is contained in:
Romain Porte 2012-08-07 23:11:44 +02:00
parent 29e9cee5fb
commit 6f84f0cbbd

View File

@ -71,10 +71,25 @@ status_free_ctx(struct status_ctx *ctx)
static void static void
status_graph_draw(struct status_ctx *ctx, struct status_seq *sq, struct status_gcache *gc) status_graph_draw(struct status_ctx *ctx, struct status_seq *sq, struct status_gcache *gc)
{ {
int max = 0;
int i, j, y; int i, j, y;
float c; float c;
int ys = sq->geo.y + sq->geo.h - 1; int ys = sq->geo.y + sq->geo.h - 1;
/* If invalid maximum, we have to compute it ourselves */
if(sq->data[2] <= 0)
{
for(i = sq->geo.x + sq->geo.w - 1, j = gc->ndata - 1;
j >= 0 && i >= sq->geo.x;
--j, --i)
{
if(j > max)
max = gc->datas[j];
}
}
else
max = sq->data[2];
XSetForeground(W->dpy, W->gc, sq->color2); XSetForeground(W->dpy, W->gc, sq->color2);
for(i = sq->geo.x + sq->geo.w - 1, j = gc->ndata - 1; for(i = sq->geo.x + sq->geo.w - 1, j = gc->ndata - 1;
@ -84,7 +99,7 @@ status_graph_draw(struct status_ctx *ctx, struct status_seq *sq, struct status_g
/* You divided by zero didn't you? */ /* You divided by zero didn't you? */
if(gc->datas[j]) if(gc->datas[j])
{ {
c = (float)sq->data[2] / (float)gc->datas[j]; c = (float)max / (float)gc->datas[j];
y = ys - (sq->geo.h / (c > 1 ? c : 1)) + 1; y = ys - (sq->geo.h / (c > 1 ? c : 1)) + 1;
draw_line(ctx->barwin->dr, i, y, i, ys); draw_line(ctx->barwin->dr, i, y, i, ys);
} }