29 |
|
|
30 |
#include "chart.h" |
#include "chart.h" |
31 |
#include "str.h" |
#include "str.h" |
32 |
|
#include "alloc.h" |
33 |
|
#include "som.h" |
34 |
|
#include "output.h" |
35 |
|
|
36 |
|
|
37 |
const char *data_colour[] = { |
const char *data_colour[] = { |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
int |
struct chart * |
52 |
chart_initialise(struct chart *chart) |
chart_create(void) |
53 |
{ |
{ |
54 |
|
struct chart *chart; |
55 |
|
|
56 |
chart->pl_params = pl_newplparams(); |
struct outp_driver *d; |
57 |
|
|
58 |
chart->lp = pl_newpl_r ("X",0,stdout,stderr,chart->pl_params); |
chart = xmalloc(sizeof(struct chart) ); |
59 |
|
|
60 |
|
for (d = outp_drivers (NULL); d; d = outp_drivers (d)) |
61 |
|
{ |
62 |
|
assert(d->class->initialise_chart); |
63 |
|
d->class->initialise_chart(d, chart); |
64 |
|
break; /* KLUDGE!! */ |
65 |
|
} |
66 |
|
|
67 |
|
if ( ! chart->lp ) |
68 |
|
return 0; |
69 |
|
|
70 |
if (pl_openpl_r (chart->lp) < 0) /* open Plotter */ |
if (pl_openpl_r (chart->lp) < 0) /* open Plotter */ |
71 |
return 1; |
return 0; |
72 |
|
|
73 |
pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */ |
pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */ |
74 |
pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */ |
pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */ |
104 |
chart->data_left, chart->data_bottom, |
chart->data_left, chart->data_bottom, |
105 |
chart->data_right, chart->data_top); |
chart->data_right, chart->data_top); |
106 |
|
|
107 |
return 0; |
return chart; |
108 |
|
|
109 |
} |
} |
110 |
|
|
121 |
{ |
{ |
122 |
const int tickSize = 10; |
const int tickSize = 10; |
123 |
|
|
124 |
|
assert(chart); |
125 |
|
|
126 |
pl_savestate_r(chart->lp); |
pl_savestate_r(chart->lp); |
127 |
|
|
128 |
pl_move_r(chart->lp, chart->data_left, chart->data_bottom); |
pl_move_r(chart->lp, chart->data_left, chart->data_bottom); |
166 |
va_list ap; |
va_list ap; |
167 |
char buf[100]; |
char buf[100]; |
168 |
|
|
169 |
|
assert(chart); |
170 |
|
|
171 |
pl_savestate_r(chart->lp); |
pl_savestate_r(chart->lp); |
172 |
pl_ffontsize_r(chart->lp,chart->font_size * 1.5); |
pl_ffontsize_r(chart->lp,chart->font_size * 1.5); |
173 |
pl_move_r(chart->lp,chart->data_left, chart->title_bottom); |
pl_move_r(chart->lp,chart->data_left, chart->title_bottom); |
181 |
} |
} |
182 |
|
|
183 |
|
|
184 |
|
extern struct som_table_class tab_table_class; |
185 |
|
|
186 |
void |
void |
187 |
chart_finalise(struct chart *chart) |
chart_submit(struct chart *chart) |
188 |
{ |
{ |
189 |
|
struct som_entity s; |
190 |
|
|
191 |
|
assert(chart); |
192 |
|
|
193 |
pl_restorestate_r(chart->lp); |
pl_restorestate_r(chart->lp); |
194 |
|
|
195 |
|
s.class = &tab_table_class; |
196 |
|
s.ext = chart; |
197 |
|
s.type = SOM_CHART; |
198 |
|
som_submit (&s); |
199 |
|
|
200 |
if (pl_closepl_r (chart->lp) < 0) /* close Plotter */ |
if (pl_closepl_r (chart->lp) < 0) /* close Plotter */ |
201 |
{ |
{ |
202 |
fprintf (stderr, "Couldn't close Plotter\n"); |
fprintf (stderr, "Couldn't close Plotter\n"); |
203 |
} |
} |
204 |
|
|
|
|
|
205 |
pl_deletepl_r(chart->lp); |
pl_deletepl_r(chart->lp); |
206 |
|
|
207 |
pl_deleteplparams(chart->pl_params); |
pl_deleteplparams(chart->pl_params); |
208 |
|
|
209 |
|
free(chart); |
210 |
|
|
211 |
} |
} |
212 |
|
|
213 |
|
|
220 |
const double tick_interval = |
const double tick_interval = |
221 |
chart_rounded_tick( (max - min) / (double) ticks); |
chart_rounded_tick( (max - min) / (double) ticks); |
222 |
|
|
223 |
|
assert ( ch ); |
224 |
|
|
225 |
|
|
226 |
ch->x_max = ceil( max / tick_interval ) * tick_interval ; |
ch->x_max = ceil( max / tick_interval ) * tick_interval ; |
227 |
ch->x_min = floor ( min / tick_interval ) * tick_interval ; |
ch->x_min = floor ( min / tick_interval ) * tick_interval ; |
228 |
|
|
229 |
|
|
230 |
ch->abscissa_scale = fabs(ch->data_right - ch->data_left) / |
ch->abscissa_scale = fabs(ch->data_right - ch->data_left) / |
231 |
fabs(ch->x_max - ch->x_min); |
fabs(ch->x_max - ch->x_min); |
232 |
|
|
248 |
const double tick_interval = |
const double tick_interval = |
249 |
chart_rounded_tick( (smax - smin) / (double) ticks); |
chart_rounded_tick( (smax - smin) / (double) ticks); |
250 |
|
|
251 |
|
|
252 |
|
assert (ch) ; |
253 |
|
|
254 |
|
|
255 |
ch->y_max = ceil ( smax / tick_interval ) * tick_interval ; |
ch->y_max = ceil ( smax / tick_interval ) * tick_interval ; |
256 |
ch->y_min = floor ( smin / tick_interval ) * tick_interval ; |
ch->y_min = floor ( smin / tick_interval ) * tick_interval ; |
257 |
|
|