aboutsummaryrefslogtreecommitdiff
path: root/src/graph.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graph.c')
-rw-r--r--src/graph.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/graph.c b/src/graph.c
index 80b2a97..89f02a1 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -51,14 +51,24 @@ int color_percent[3] = { 239,159,79 };
int graph_xsize = 460;
int graph_ysize = 100;
int graph_h_margin[2] = { 100, 14 };
int graph_v_margin[2] = { 14, 35 };
-/* FIXME: I18N?? */
-char *rate_unit = "Bytes per Second";
+struct monitor default_monitor = {
+ NULL,
+ NULL,
+ NULL,
+ "Bytes per Second", /* rate_unit, FIXME: I18N?? */
+ 0, /* max_rate */
+ 0, /* max_adjust */
+ 1.0, /* scale */
+ 0.1, /* ystep */
+ 0, /* ystep_absolute */
+ 0 /* swap */
+};
#define make_color_index(g, ar) \
gdImageColorAllocate (g, (ar)[0], (ar)[1], (ar)[2])
static void
draw_vtext (gdImagePtr graph, int color, const char *text)
@@ -67,12 +77,30 @@ draw_vtext (gdImagePtr graph, int color, const char *text)
8,
graph_ysize + graph_v_margin[0] -
(graph_ysize - gdFontSmall->w * strlen (text))/2,
(unsigned char *) text, color);
}
+static double
+find_max (queue_t *dataq)
+{
+ int i, n = queue_count (dataq);
+ double mval = 0;
+ struct traffic_history *th;
+
+ for (i = 0; i < n; i++)
+ {
+ th = queue_get_ptr (dataq, i);
+ if (mval < th->inrate)
+ mval = th->inrate;
+ if (mval < th->outrate)
+ mval = th->outrate;
+ }
+ return mval;
+}
+
int
draw_graph (FILE *fp,
struct monitor *mon,
queue_t *dataq, const struct avg_acc *avg, time_t start,
int xstep, unsigned long xmax,
int growright,
@@ -86,19 +114,31 @@ draw_graph (FILE *fp,
int i_outp, i_outpg;
double xscale, yscale;
int dotted_style[3];
int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1];
int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1];
grid_t grid;
- double ymax = mon->max_rate;
+ double ymax;
+
+ if (mon->max_adjust)
+ {
+ double amax = find_max (dataq);
+ if (amax > mon->max_rate)
+ {
+ unsigned long n = (amax - mon->max_rate + mon->max_adjust - 1) /
+ mon->max_adjust;
+ mon->max_rate += n * mon->max_adjust;
+ }
+ }
+ ymax = mon->max_rate;
yscale = (double) graph_ysize / ymax;
xscale = (double) graph_xsize / xmax;
#define ytr(y) \
- (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * \
+ (unsigned long) ((ymax >= (y) ? (ymax - (y)) : 0) * \
yscale + graph_h_margin[1])
#define xtr(x) \
(unsigned long) (growright ? \
((full_xsize - (x)*xscale)) : \
(graph_h_margin[0] + (x)*xscale))
@@ -210,14 +250,13 @@ draw_graph (FILE *fp,
grid = grid_create (ygrid, dataq, 0, ymax, mon);
if (grid)
{
double d;
char *str = NULL;
- draw_vtext (graph, i_grid,
- mon->rate_unit ? mon->rate_unit : rate_unit);
+ draw_vtext (graph, i_grid, mon->rate_unit);
/* Draw vertical grid */
while ((d = grid_next (grid, &str, NULL)) < ymax)
{
int y = ytr (d);

Return to:

Send suggestions and report system problems to the System administrator.