aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-30 12:26:40 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-04-30 12:26:40 +0300
commitfbc8bdac6efb0c63a73c5105bbf4ecb304187e44 (patch)
treefa5116b264d2880841044f5aa18542c465f7f97b
parent5a1f674eecba607ffa328484ca34c598690ff8d2 (diff)
downloadtagr-fbc8bdac6efb0c63a73c5105bbf4ecb304187e44.tar.gz
tagr-fbc8bdac6efb0c63a73c5105bbf4ecb304187e44.tar.bz2
Grid step is double-precision.
* src/grid.c (struct grid): vmin, vmax and cur are double. All uses updated. * src/output.c (add_stats): Add zero stats if the queue is empty. * src/readconfig.c: The argument to y-step is double. * src/tagr.h (struct monitor.ystep): Change to double. (struct grid_class.next): Return double. (grid_next): Return double. (grid_create): Change proto. * src/graph.c: Update grid_next return values.
-rw-r--r--src/graph.c14
-rw-r--r--src/grid.c30
-rw-r--r--src/output.c41
-rw-r--r--src/readconfig.c7
-rw-r--r--src/tagr.h10
5 files changed, 52 insertions, 50 deletions
diff --git a/src/graph.c b/src/graph.c
index 02e0586..80b2a97 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -86,13 +86,13 @@ draw_graph (FILE *fp,
86 int i_outp, i_outpg; 86 int i_outp, i_outpg;
87 double xscale, yscale; 87 double xscale, yscale;
88 int dotted_style[3]; 88 int dotted_style[3];
89 int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1]; 89 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]; 90 int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1];
91 grid_t grid; 91 grid_t grid;
92 unsigned long ymax = mon->max_rate; 92 double ymax = mon->max_rate;
93 93
94 yscale = (double) graph_ysize / ymax; 94 yscale = (double) graph_ysize / ymax;
95 xscale = (double) graph_xsize / xmax; 95 xscale = (double) graph_xsize / xmax;
96 96
97#define ytr(y) \ 97#define ytr(y) \
98 (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * \ 98 (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * \
@@ -207,22 +207,22 @@ draw_graph (FILE *fp,
207 dotted_style[2] = gdTransparent; 207 dotted_style[2] = gdTransparent;
208 gdImageSetStyle (graph, dotted_style, 3); 208 gdImageSetStyle (graph, dotted_style, 3);
209 209
210 grid = grid_create (ygrid, dataq, 0, ymax, mon); 210 grid = grid_create (ygrid, dataq, 0, ymax, mon);
211 if (grid) 211 if (grid)
212 { 212 {
213 unsigned long i; 213 double d;
214 char *str = NULL; 214 char *str = NULL;
215 215
216 draw_vtext (graph, i_grid, 216 draw_vtext (graph, i_grid,
217 mon->rate_unit ? mon->rate_unit : rate_unit); 217 mon->rate_unit ? mon->rate_unit : rate_unit);
218 218
219 /* Draw vertical grid */ 219 /* Draw vertical grid */
220 while ((i = grid_next (grid, &str, NULL)) < ymax) 220 while ((d = grid_next (grid, &str, NULL)) < ymax)
221 { 221 {
222 int y = ytr (i); 222 int y = ytr (d);
223 223
224 /* Left tick */ 224 /* Left tick */
225 gdImageLine (graph, 225 gdImageLine (graph,
226 xtr (0) - 2, y, 226 xtr (0) - 2, y,
227 xtr (0) + 1, y, 227 xtr (0) + 1, y,
228 i_grid); 228 i_grid);
@@ -244,19 +244,19 @@ draw_graph (FILE *fp,
244 grid_destroy (grid); 244 grid_destroy (grid);
245 } 245 }
246 246
247 grid = grid_create (xgrid, dataq, 0, xmax, &start); 247 grid = grid_create (xgrid, dataq, 0, xmax, &start);
248 if (grid) 248 if (grid)
249 { 249 {
250 unsigned long i; 250 double d;
251 char *str = NULL; 251 char *str = NULL;
252 int mark; 252 int mark;
253 253
254 while ((i = grid_next (grid, &str, &mark)) < xmax) 254 while ((d = grid_next (grid, &str, &mark)) < xmax)
255 { 255 {
256 int x = xtr (i); 256 int x = xtr (d);
257 257
258 /* Tick */ 258 /* Tick */
259 gdImageLine (graph, 259 gdImageLine (graph,
260 x, ytr (0) - 2, x, ytr (0) + 1, 260 x, ytr (0) - 2, x, ytr (0) + 1,
261 i_grid); 261 i_grid);
262 /* Grid line */ 262 /* Grid line */
diff --git a/src/grid.c b/src/grid.c
index 1671753..08e1c08 100644
--- a/src/grid.c
+++ b/src/grid.c
@@ -22,22 +22,22 @@
22#include <tagr.h> 22#include <tagr.h>
23 23
24struct grid 24struct grid
25{ 25{
26 struct grid_class *class; 26 struct grid_class *class;
27 queue_t *q; 27 queue_t *q;
28 unsigned long vmin; 28 double vmin;
29 unsigned long vmax; 29 double vmax;
30 unsigned long cur; 30 double cur;
31 char *str; 31 char *str;
32 void *data; 32 void *data;
33}; 33};
34 34
35grid_t 35grid_t
36grid_create (struct grid_class *class, queue_t *q, 36grid_create (struct grid_class *class, queue_t *q,
37 unsigned long vmin, unsigned long vmax, void *cdata) 37 double vmin, double vmax, void *cdata)
38{ 38{
39 grid_t grid; 39 grid_t grid;
40 40
41 if (!class) 41 if (!class)
42 return NULL; 42 return NULL;
43 grid = xmalloc (sizeof (*grid)); 43 grid = xmalloc (sizeof (*grid));
@@ -51,13 +51,13 @@ grid_create (struct grid_class *class, queue_t *q,
51 else 51 else
52 grid->data = NULL; 52 grid->data = NULL;
53 grid->str = NULL; 53 grid->str = NULL;
54 return grid; 54 return grid;
55} 55}
56 56
57unsigned long 57double
58grid_next (grid_t grid, char **str, int *mark) 58grid_next (grid_t grid, char **str, int *mark)
59{ 59{
60 return grid->class->next (grid, str, mark); 60 return grid->class->next (grid, str, mark);
61} 61}
62 62
63void 63void
@@ -84,25 +84,25 @@ grid_free_data (void *ptr)
84static char *short_suffix[] = {"", "k", "M", "G", "T"}; 84static char *short_suffix[] = {"", "k", "M", "G", "T"};
85char **number_suffix = short_suffix; 85char **number_suffix = short_suffix;
86size_t number_suffix_count = sizeof (short_suffix) / sizeof (short_suffix[0]); 86size_t number_suffix_count = sizeof (short_suffix) / sizeof (short_suffix[0]);
87 87
88struct ygrid_data 88struct ygrid_data
89{ 89{
90 unsigned long step; 90 double step;
91}; 91};
92 92
93static void * 93static void *
94ygrid_create (grid_t grid, void *cdata) 94ygrid_create (grid_t grid, void *cdata)
95{ 95{
96 struct monitor *mon = cdata; 96 struct monitor *mon = cdata;
97 struct ygrid_data *gr = xmalloc (sizeof (*gr)); 97 struct ygrid_data *gr = xmalloc (sizeof (*gr));
98 gr->step = mon->ystep; 98 gr->step = mon->ystep;
99 return gr; 99 return gr;
100} 100}
101 101
102static unsigned long 102static double
103ygrid_next (grid_t grid, char **str, int *mark) 103ygrid_next (grid_t grid, char **str, int *mark)
104{ 104{
105 struct ygrid_data *gr = grid->data; 105 struct ygrid_data *gr = grid->data;
106 if (mark) 106 if (mark)
107 *mark = 0; 107 *mark = 0;
108 grid->cur += gr->step; 108 grid->cur += gr->step;
@@ -151,17 +151,17 @@ xgrid_2h_create (grid_t grid, void *cdata)
151 gr->off = frac + h * TWOHRS; 151 gr->off = frac + h * TWOHRS;
152 gr->unit = tm->tm_hour - h; 152 gr->unit = tm->tm_hour - h;
153 153
154 return gr; 154 return gr;
155} 155}
156 156
157static unsigned long 157static double
158xgrid_2h_next (grid_t grid, char **str, int *mark) 158xgrid_2h_next (grid_t grid, char **str, int *mark)
159{ 159{
160 struct xgrid_data *gr = grid->data; 160 struct xgrid_data *gr = grid->data;
161 unsigned long ret = gr->off; 161 double ret = gr->off;
162 162
163 if (grid->str) 163 if (grid->str)
164 { 164 {
165 free (grid->str); 165 free (grid->str);
166 grid->str = NULL; 166 grid->str = NULL;
167 } 167 }
@@ -197,17 +197,17 @@ xgrid_wday_create (grid_t grid, void *cdata)
197 gr->off = frac; 197 gr->off = frac;
198 gr->unit = tm->tm_wday; 198 gr->unit = tm->tm_wday;
199 199
200 return gr; 200 return gr;
201} 201}
202 202
203static unsigned long 203static double
204xgrid_wday_next (grid_t grid, char **str, int *mark) 204xgrid_wday_next (grid_t grid, char **str, int *mark)
205{ 205{
206 struct xgrid_data *gr = grid->data; 206 struct xgrid_data *gr = grid->data;
207 unsigned long ret = gr->off; 207 double ret = gr->off;
208 char buf[80]; 208 char buf[80];
209 struct tm *tm = localtime (&gr->start); 209 struct tm *tm = localtime (&gr->start);
210 210
211 if (grid->str) 211 if (grid->str)
212 { 212 {
213 free (grid->str); 213 free (grid->str);
@@ -247,17 +247,17 @@ xgrid_week_create (grid_t grid, void *cdata)
247 gr->off = frac; 247 gr->off = frac;
248 gr->unit = 0; 248 gr->unit = 0;
249 249
250 return gr; 250 return gr;
251} 251}
252 252
253static unsigned long 253static double
254xgrid_week_next (grid_t grid, char **str, int *mark)