aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Duquesnoy <xorg62@gmail.com>2012-08-09 06:02:51 -0700
committerMartin Duquesnoy <xorg62@gmail.com>2012-08-09 06:02:51 -0700
commitecb0f82058de9e24eb54e2e2b76f730bd77632a0 (patch)
tree6c935192e7882236cc56e0fa8b0abd9f6c2b14b0
parent6e3f6ef326871f35c35f07bd3e72f60470d4e2f9 (diff)
parentb9d41602739a3d3de5c9dbcb651268f26eadbbaa (diff)
downloadwmfs-ecb0f82058de9e24eb54e2e2b76f730bd77632a0.zip
wmfs-ecb0f82058de9e24eb54e2e2b76f730bd77632a0.tar.gz
wmfs-ecb0f82058de9e24eb54e2e2b76f730bd77632a0.tar.bz2
Merge pull request #71 from MicroJoe/master
Added an auto-maximum feature to graphs
-rw-r--r--src/status.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/status.c b/src/status.c
index 7b98667..fbc2073 100644
--- a/src/status.c
+++ b/src/status.c
@@ -71,10 +71,25 @@ status_free_ctx(struct status_ctx *ctx)
static void
status_graph_draw(struct status_ctx *ctx, struct status_seq *sq, struct status_gcache *gc)
{
+ int max = 0;
int i, j, y;
float c;
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(gc->datas[j] > max)
+ max = gc->datas[j];
+ }
+ }
+ else
+ max = sq->data[2];
+
XSetForeground(W->dpy, W->gc, sq->color2);
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? */
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;
draw_line(ctx->barwin->dr, i, y, i, ys);
}