diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-26 00:52:15 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-26 00:52:15 +0300 |
commit | 099a946ad4465c42db4737b247f1e89bd03c83ae (patch) | |
tree | af302f68f078305d27eeea1716405f79aac81877 /src/graph.c | |
parent | d039b6b354119ff8735e4992dbf06760ea28fa55 (diff) | |
download | tagr-099a946ad4465c42db4737b247f1e89bd03c83ae.tar.gz tagr-099a946ad4465c42db4737b247f1e89bd03c83ae.tar.bz2 |
Improve graphical presentation. Other bugfixes.
* src/graph.c (draw_graph): Cut off values of Y greater than YMAX
Use scale_sample to prepare data.
* src/grid.c (ygrid_create): New function.
(ygrid_next): Use data prepared by ygrid_create.
* src/main.c (change_user): Bugfix.
Update calls to open_db
Move log initialization to the proper place.
* src/output.c (scale_sample): New function.
(add_stats): Use scale_sample to prepare data.
(cb_monitor): Initialize scale and ystep.
(cb_double): New function.
(monitor_kw): New keywords: scale, y-step and swap.
* src/report.c (open_db): Take an argument specifying whether
the database will be written to. All callers updated.
* src/tagr.h (struct monitor): New members: scale, ystep and swap.
max_rate is ulong.
(TAGR_DB_RD, TAGR_DB_WR): New macros.
(open_db): Update proto.
(scale_sample): New proto.
Diffstat (limited to 'src/graph.c')
-rw-r--r-- | src/graph.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/graph.c b/src/graph.c index 0d9f9a7..16483bb 100644 --- a/src/graph.c +++ b/src/graph.c @@ -98,7 +98,7 @@ draw_graph (FILE *fp, xscale = (double) graph_xsize / xmax; #define ytr(y) \ - (unsigned long) ((ymax - (y)) * yscale + graph_h_margin[1]) + (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * yscale + graph_h_margin[1]) #define xtr(x) \ (unsigned long) (growright ? \ ((full_xsize - (x)*xscale)) : \ @@ -146,25 +146,29 @@ draw_graph (FILE *fp, /* Incoming traffic */ for (i = n - 1, x = 0; i > 0 && x < xmax; i--, x += xstep) { - struct traffic_history *th = queue_get_ptr (dataq, i); - struct traffic_history *tnext = queue_get_ptr (dataq, i - 1); + struct traffic_history th, tnext; + + scale_sample (mon, queue_get_ptr (dataq, i), &th); + scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); if (fill_incoming_option) gdImageLine (graph, xtr (x), ytr (0), - xtr (x), ytr (tnext->inrate), i_in); - gdImageLine (graph, xtr (x), ytr (th->inrate), - xtr (x+1), ytr (tnext->inrate), i_in); + xtr (x), ytr (tnext.inrate), i_in); + gdImageLine (graph, xtr (x), ytr (th.inrate), + xtr (x+1), ytr (tnext.inrate), i_in); } /* Outgoing traffic */ gdImageSetBrush (graph, brush_out); for (i = n - 1, x = 0; i > 0 && x < xmax; i--, x += xstep) { - struct traffic_history *th = queue_get_ptr (dataq, i); - struct traffic_history *tnext = queue_get_ptr (dataq, i - 1); + struct traffic_history th, tnext; + + scale_sample (mon, queue_get_ptr (dataq, i), &th); + scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); - gdImageLine (graph, xtr (x), ytr (th->outrate), - xtr (x+1), ytr (tnext->outrate), gdBrushed); + gdImageLine (graph, xtr (x), ytr (th.outrate), + xtr (x+1), ytr (tnext.outrate), gdBrushed); } /* Border */ @@ -178,7 +182,7 @@ draw_graph (FILE *fp, dotted_style[2] = gdTransparent; gdImageSetStyle (graph, dotted_style, 3); - grid = grid_create (ygrid, dataq, 0, ymax, NULL); + grid = grid_create (ygrid, dataq, 0, ymax, mon); if (grid) { unsigned long i; |