diff options
Diffstat (limited to 'src/graph.c')
-rw-r--r-- | src/graph.c | 51 |
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 | |||
@@ -54,8 +54,18 @@ int graph_ysize = 100; | |||
54 | int graph_h_margin[2] = { 100, 14 }; | 54 | int graph_h_margin[2] = { 100, 14 }; |
55 | int graph_v_margin[2] = { 14, 35 }; | 55 | int graph_v_margin[2] = { 14, 35 }; |
56 | 56 | ||
57 | /* FIXME: I18N?? */ | 57 | struct monitor default_monitor = { |
58 | char *rate_unit = "Bytes per Second"; | 58 | NULL, |
59 | NULL, | ||
60 | NULL, | ||
61 | "Bytes per Second", /* rate_unit, FIXME: I18N?? */ | ||
62 | 0, /* max_rate */ | ||
63 | 0, /* max_adjust */ | ||
64 | 1.0, /* scale */ | ||
65 | 0.1, /* ystep */ | ||
66 | 0, /* ystep_absolute */ | ||
67 | 0 /* swap */ | ||
68 | }; | ||
59 | 69 | ||
60 | #define make_color_index(g, ar) \ | 70 | #define make_color_index(g, ar) \ |
61 | gdImageColorAllocate (g, (ar)[0], (ar)[1], (ar)[2]) | 71 | gdImageColorAllocate (g, (ar)[0], (ar)[1], (ar)[2]) |
@@ -70,6 +80,24 @@ draw_vtext (gdImagePtr graph, int color, const char *text) | |||
70 | (unsigned char *) text, color); | 80 | (unsigned char *) text, color); |
71 | } | 81 | } |
72 | 82 | ||
83 | static double | ||
84 | find_max (queue_t *dataq) | ||
85 | { | ||
86 | int i, n = queue_count (dataq); | ||
87 | double mval = 0; | ||
88 | struct traffic_history *th; | ||
89 | |||
90 | for (i = 0; i < n; i++) | ||
91 | { | ||
92 | th = queue_get_ptr (dataq, i); | ||
93 | if (mval < th->inrate) | ||
94 | mval = th->inrate; | ||
95 | if (mval < th->outrate) | ||
96 | mval = th->outrate; | ||
97 | } | ||
98 | return mval; | ||
99 | } | ||
100 | |||
73 | int | 101 | int |
74 | draw_graph (FILE *fp, | 102 | draw_graph (FILE *fp, |
75 | struct monitor *mon, | 103 | struct monitor *mon, |
@@ -89,13 +117,25 @@ draw_graph (FILE *fp, | |||
89 | int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1]; | 117 | int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1]; |
90 | int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; | 118 | int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; |
91 | grid_t grid; | 119 | grid_t grid; |
92 | double ymax = mon->max_rate; | 120 | double ymax; |
121 | |||
122 | if (mon->max_adjust) | ||
123 | { | ||
124 | double amax = find_max (dataq); | ||
125 | if (amax > mon->max_rate) | ||
126 | { | ||
127 | unsigned long n = (amax - mon->max_rate + mon->max_adjust - 1) / | ||
128 | mon->max_adjust; | ||
129 | mon->max_rate += n * mon->max_adjust; | ||
130 | } | ||
131 | } | ||
132 | ymax = mon->max_rate; | ||
93 | 133 | ||
94 | yscale = (double) graph_ysize / ymax; | 134 | yscale = (double) graph_ysize / ymax; |
95 | xscale = (double) graph_xsize / xmax; | 135 | xscale = (double) graph_xsize / xmax; |
96 | 136 | ||
97 | #define ytr(y) \ | 137 | #define ytr(y) \ |
98 | (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * \ | 138 | (unsigned long) ((ymax >= (y) ? (ymax - (y)) : 0) * \ |
99 | yscale + graph_h_margin[1]) | 139 | yscale + graph_h_margin[1]) |
100 | #define xtr(x) \ | 140 | #define xtr(x) \ |
101 | (unsigned long) (growright ? \ | 141 | (unsigned long) (growright ? \ |
@@ -213,8 +253,7 @@ draw_graph (FILE *fp, | |||
213 | double d; | 253 | double d; |
214 | char *str = NULL; | 254 | char *str = NULL; |
215 | 255 | ||
216 | draw_vtext (graph, i_grid, | 256 | draw_vtext (graph, i_grid, mon->rate_unit); |
217 | mon->rate_unit ? mon->rate_unit : rate_unit); | ||
218 | 257 | ||
219 | /* Draw vertical grid */ | 258 | /* Draw vertical grid */ |
220 | while ((d = grid_next (grid, &str, NULL)) < ymax) | 259 | while ((d = grid_next (grid, &str, NULL)) < ymax) |