diff options
Diffstat (limited to 'src/graph.c')
-rw-r--r-- | src/graph.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/graph.c b/src/graph.c index 8088773..1197a7d 100644 --- a/src/graph.c +++ b/src/graph.c @@ -90,6 +90,7 @@ draw_graph (FILE *fp, int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; grid_t grid; unsigned long ymax = mon->max_rate; + time_t start; yscale = (double) graph_ysize / ymax; xscale = (double) graph_xsize / xmax; @@ -142,38 +143,65 @@ draw_graph (FILE *fp, n = queue_count (dataq); /* Incoming traffic */ - for (i = n - 1, x = 0; i > 0 && x < xmax; i--, x += xstep) + for (i = n - 1, start = 0; i > 0; i--) { struct traffic_history th, tnext; scale_sample (mon, queue_get_ptr (dataq, i), &th); + if (start == 0) + start = th.time; scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); + if (start - tnext.time > xmax) + break; + if (zero_unknown_option + && th.time - tnext.time > xstep * cut_out_fraction) + { + gdImageLine (graph, xtr (start - tnext.time), ytr (0), + xtr (start - tnext.time), ytr (tnext.inrate), i_in); + th.inrate = tnext.inrate = 0; + th.outrate = tnext.outrate = 0; + } + 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 + xstep), ytr (tnext.inrate), i_in); + xtr (start - th.time), ytr (0), + xtr (start - th.time), ytr (tnext.inrate), i_in); + gdImageLine (graph, xtr (start - th.time), ytr (th.inrate), + xtr (start - tnext.time), ytr (tnext.inrate), i_in); } /* Outgoing traffic */ gdImageSetBrush (graph, brush_out); - for (i = n - 1, x = 0; i > 0 && x < xmax; i--, x += xstep) + for (i = n - 1, start = 0; i > 0; i--) { struct traffic_history th, tnext; scale_sample (mon, queue_get_ptr (dataq, i), &th); + if (start == 0) + start = th.time; scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); + if (start - tnext.time > xmax) + break; - gdImageLine (graph, xtr (x), ytr (th.outrate), - xtr (x + xstep), ytr (tnext.outrate), gdBrushed); + if (zero_unknown_option + && th.time - tnext.time > xstep * cut_out_fraction) + { + gdImageLine (graph, xtr (start - tnext.time), ytr (0), + xtr (start - tnext.time), ytr (tnext.inrate), + gdBrushed); + th.inrate = tnext.inrate = 0; + th.outrate = tnext.outrate = 0; + } + + gdImageLine (graph, xtr (start - th.time), ytr (th.outrate), + xtr (start - tnext.time), ytr (tnext.outrate), gdBrushed); } /* Border */ gdImageRectangle (graph, xtr (0), ytr (0), xtr (xmax), ytr (ymax), i_grid); - + dotted_style[0] = i_grid; dotted_style[1] = gdTransparent; |