~ubuntu-branches/ubuntu/dapper/ploticus/dapper

« back to all changes in this revision

Viewing changes to src/plg.c

  • Committer: Bazaar Package Importer
  • Author(s): James W. Penny
  • Date: 2004-04-04 22:12:00 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040404221200-822i126bwkfgsfx6
Tags: 2.20-3
* Add "late fix" for errbarfields.  Fix found in
  http://groups.yahoo.com/group/ploticus/message/691.
  Solves a problem with asymetric error bands.
* Add "late fix" for proc_axis.c.  Fix found in
  http://groups.yahoo.com/group/ploticus/message/722
  This solves a problem with cumulative rounding of 
  days in graphs with days stubs.
* Add  "late fix" version of chunk_area.  Fix from
  http://ploticus.sourceforge.net/download/chunk_area
  This solves a problem with dates with no day number,
  as mm/yyyy.
* Add "late fix" version of heatarea.pl.  Fix from
  http://ploticus.sourceforge.net/download/heatmap.pl
* Add "late fix" version of proc_getdata.c.  Fix found at
  http://ploticus.sourceforge.net/download/proc_getdata.c
  This permits comma delimited files with more than 255 characters
  per row to be processed.
* Add "late fix" version of proc_lineplot.c.  This is from
  http://ploticus.sourceforge.net/download/proc_lineplot.c
  It clips labels, and handles the degenerate case of no points
  in the range properly.
* Add pltestsuite to debian package as 
  /usr/share/doc/ploticus/examples
* Remove recommends of libming-fonts-openoffice. The package has been
  removed from debian.                         closes: Bug#240560
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ploticus data display engine.  Software, documentation, and examples.  
 
2
 * Copyright 1998-2002 Stephen C. Grubb  (scg@jax.org).
 
3
 * Covered by GPL; see the file ./Copyright for details. */
 
4
 
 
5
 
 
6
/* small, lowlevel routines re: scaled units */
 
7
/* see also units.c which is a layer above this. */
 
8
 
 
9
#include "plg.h"
 
10
 
 
11
struct plgc PLG;
 
12
 
 
13
PLG_set_early_defaults()
 
14
{
 
15
/* overall settings - these can be set by application program before Einit() */
 
16
strcpy( Estandard_font, "/Helvetica" );  
 
17
Estandard_textsize = 10;         
 
18
Estandard_lwscale = 1.0;
 
19
strcpy( Estandard_color, "black" );
 
20
strcpy( Estandard_bkcolor, "white" );
 
21
 
 
22
/* current parameters.. */
 
23
strcpy( Ecurfont, "" );
 
24
Ecurtextsize = 0;
 
25
Ecurtextheight = 0.0;
 
26
Ecurtextwidth = 0.0;
 
27
Ecurtextdirection = 0;
 
28
Ecurpaper = -1;
 
29
Ecurlinewidth = -1.0;
 
30
Ecurlinetype = -1;
 
31
Ecurpatternfactor = 0.0;
 
32
 
 
33
EScale_x = 1; EScale_y = 1; 
 
34
Escaletype_x = E_LINEAR;        
 
35
Escaletype_y = E_LINEAR;        
 
36
 
 
37
strcpy( Eprogname, "" ); 
 
38
Eflip = 0;  
 
39
Eblacklines = 0; 
 
40
Eflashdelay = 150000; 
 
41
 
 
42
return( 0 );
 
43
}
 
44
 
 
45
/* ============================ */
 
46
/* SCALETYPE - select the scaling method */
 
47
 
 
48
PLG_scaletype( typ, axis )
 
49
char typ[];
 
50
char axis;
 
51
{
 
52
char buf[80];
 
53
int stat;
 
54
 
 
55
if( stricmp( typ, "linear" )==0 ) {
 
56
        /* Esetunits( axis, "linear" ); */
 
57
        if( axis == 'x' ) Escaletype_x = E_LINEAR;
 
58
        else if( axis == 'y' ) Escaletype_y = E_LINEAR;
 
59
        return( 0 );
 
60
        }
 
61
 
 
62
else if( stricmp( typ, "log" )==0 ) {
 
63
        /* Esetunits( axis, "linear" ); */ /* linear ok */
 
64
        if( axis == 'x' ) Escaletype_x = E_LOG;
 
65
        else if( axis == 'y' ) Escaletype_y = E_LOG;
 
66
        return( 0 );
 
67
        }
 
68
 
 
69
else if( stricmp( typ, "log+1" )==0 ) {         /* log+1 added scg 11/29/00 */
 
70
        if( axis == 'x' ) Escaletype_x = E_LOGPLUS1;
 
71
        else if( axis == 'y' ) Escaletype_y = E_LOGPLUS1;
 
72
        return( 0 );
 
73
        }
 
74
 
 
75
else    {
 
76
        /* stat = Esetunits( axis, typ );
 
77
         * if( stat != 0 ) {
 
78
         *      sprintf( buf, "Invalid scaling type for %c axis", axis );
 
79
         *      return( Eerr( 101, buf, typ ) );
 
80
         *      }
 
81
         */
 
82
 
 
83
        /* special units always use linear as the basic units.. */
 
84
        if( axis == 'x' ) Escaletype_x = E_LINEAR;
 
85
        else Escaletype_y = E_LINEAR;
 
86
        return( 0 );
 
87
        }
 
88
}
 
89
 
 
90
/* =========================== */
 
91
/* SCALE_X - for setting up scaling in x */
 
92
 
 
93
PLG_scale_x( xlow, xhi, datalow, datahi )
 
94
double  xlow,   /* absolute x location of left side of the area */
 
95
        xhi,    /* absolute x location of the right side of the area */
 
96
        datalow, /* data-units x at the left side */
 
97
        datahi;  /* data-units x at the right side */
 
98
{
 
99
char msgbuf[100];
 
100
 
 
101
EXlo = xlow;
 
102
EXhi = xhi;
 
103
EDXlo = datalow;
 
104
EDXhi = datahi;
 
105
 
 
106
if( datahi-datalow <= 0 ) return( Eerr( 100, "x range is invalid .. likely culprits: xautorange, or invalid date format" , "" ) );
 
107
 
 
108
if( xhi-xlow <= 0 ) {
 
109
        sprintf( msgbuf, "Error in x absolute plot area dimensions (%g and %g)", xlow, xhi);
 
110
        return( Eerr( 101, msgbuf, "" ) );
 
111
        }
 
112
        
 
113
if( Escaletype_x == E_LINEAR ) EScale_x = (xhi-xlow) / (datahi-datalow) ;
 
114
else if( Escaletype_x == E_LOG ) {
 
115
        /* if( datalow <= 0.0 ) datalow = 0.01; */ /* this line commented out 9/26/03 per paul labbe */
 
116
        EScale_x = (xhi-xlow) / (log( datahi ) - log( datalow ));
 
117
        }
 
118
else if( Escaletype_x == E_LOGPLUS1 ) {
 
119
        if( (datalow) < 0.0 ) datalow = 0.0; 
 
120
        EScale_x = (xhi-xlow) / (log( datahi+1.0 ) - log( datalow+1.0 ));
 
121
        }
 
122
return( 0 );
 
123
}
 
124
 
 
125
/* =========================== */
 
126
/* SCALE_Y - for setting up scaling in y */
 
127
 
 
128
PLG_scale_y( ylow, yhi, datalow, datahi )
 
129
double  ylow,   /* absolute y location of low side of the area */
 
130
        yhi,    /* absolute y location of high side of the area */
 
131
        datalow, /* data-units y at the low side */
 
132
        datahi;  /* data-units y at the high side */
 
133
{
 
134
double logpart, linpart;
 
135
char msgbuf[100];
 
136
 
 
137
EYlo = ylow;
 
138
EYhi = yhi;
 
139
EDYlo = datalow;
 
140
EDYhi = datahi;
 
141
 
 
142
if( datahi-datalow <= 0 ) return( Eerr( 100, "y range is invalid .. likely culprit is yautorange or yrange", "" ) );
 
143
 
 
144
if( yhi-ylow <= 0 ) {
 
145
        sprintf( msgbuf, "Error in y absolute plot area dimensions (%g and %g)", ylow, yhi);
 
146
        return( Eerr( 101, msgbuf, "" ) );
 
147
        }
 
148
 
 
149
if( Escaletype_y == E_LINEAR ) EScale_y = (yhi-ylow) / (datahi-datalow) ;
 
150
 
 
151
else if( Escaletype_y == E_LOG ) {
 
152
        /* if( datalow <= 0.0 ) datalow = 0.01; */ /* this line commented out scg 9/26/03 per paul labbe */
 
153
        EScale_y = (yhi-ylow) / (log( datahi ) - log( datalow ));
 
154
        }
 
155
else if( Escaletype_y == E_LOGPLUS1 ) {
 
156
        if( (datalow) < 0.0 ) datalow = 0.0; 
 
157
        EScale_y = (yhi-ylow) / (log( datahi+1.0 ) - log( datalow+1.0 ));
 
158
        }
 
159
return( 0 );
 
160
}
 
161
 
 
162
/* =========================== */
 
163
/* A -  Returns an absolute location from a data value in xory.
 
164
   This is the preferred function to use because it handles flip. */
 
165
 
 
166
double 
 
167
PLG_a( xory, d )
 
168
char xory;
 
169
double d;
 
170
{
 
171
if( Eflip ) {
 
172
        if( xory == 'x' ) return( Eay( d ) );
 
173
        else if( xory == 'y' ) return( Eax( d ) );
 
174
        }
 
175
else    {
 
176
        if( xory == 'x' ) return( Eax( d ) );
 
177
        else if( xory == 'y' ) return( Eay( d ) );
 
178
        }
 
179
return( Eerr( 15, "Ea: nonsensical parameters", "" ) );
 
180
}
 
181
 
 
182
 
 
183
/* =========================== */
 
184
/* AX - returns an absolute x location from a data value */
 
185
 
 
186
double 
 
187
PLG_ax( d )
 
188
double d;
 
189
{
 
190
double f, g;
 
191
 
 
192
 
 
193
if( Escaletype_x == E_LINEAR ) 
 
194
        return( EXlo + (( d - EDXlo ) * EScale_x ));
 
195
else if( Escaletype_x == E_LOG ) {
 
196
        if( d <= 0.0 ) return( EXlo );
 
197
        else if( EDXlo <= 0.0 ) return( EXlo + (( log( d ) - log( 1.0 ) ) * EScale_x ) );
 
198
        else return( EXlo + (( log( d ) - log( EDXlo ) ) * EScale_x ) );
 
199
        }
 
200
else if( Escaletype_x == E_LOGPLUS1 ) {
 
201
        if( d <= 0.0 ) return( EXlo );
 
202
        else if( EDXlo <= 0.0 ) return( EXlo + (( log( d+1.0 ) - log( 1.0 ) ) * EScale_x ) );
 
203
        else return( EXlo + (( log( d+1.0 ) - log( EDXlo ) ) * EScale_x ) );
 
204
        }
 
205
}
 
206
 
 
207
/* =========================== */
 
208
/* AY - returns an absolute y location from a data value */
 
209
double 
 
210
PLG_ay( d )
 
211
double d;
 
212
{
 
213
if( Escaletype_y == E_LINEAR ) return( EYlo + (( d - EDYlo ) * EScale_y ));
 
214
else if( Escaletype_y == E_LOG ) {
 
215
        if( d <= 0.0 ) return( EYlo );
 
216
        else if( EDYlo <= 0.0 ) return( EYlo + (( log( d ) - log( 1.0 ) ) * EScale_y ) );
 
217
        else return( EYlo + (( log( d ) - log( EDYlo ) ) * EScale_y ) );
 
218
        }
 
219
else if( Escaletype_y == E_LOGPLUS1 ) {
 
220
        if( d <= 0.0 ) return( EYlo );
 
221
        else if( EDYlo <= 0.0 ) return( EYlo + (( log( d+1.0 ) - log( 1.0 ) ) * EScale_y ) );
 
222
        else return( EYlo + (( log( d+1.0 ) - log( EDYlo ) ) * EScale_y ) );
 
223
        }
 
224
}
 
225
 
 
226
 
 
227
 
 
228
 
 
229
/* =========================== */
 
230
/* DX - given an abs coord in X, returns a value in data space */
 
231
 
 
232
double 
 
233
PLG_dx( a )
 
234
double a;
 
235
{
 
236
double h;
 
237
if( Escaletype_x == E_LINEAR ) {
 
238
        h = a - EXlo;
 
239
        return( EDXlo + ( h / EScale_x ) );
 
240
        }
 
241
else if( Escaletype_x == E_LOG ) {
 
242
        if( a < EXlo ) return( EDXlo );
 
243
        h = log( a ) - log( EDXlo );
 
244
        return( EDXlo + ( h / EScale_x ) );
 
245
        }
 
246
else if( Escaletype_x == E_LOGPLUS1 ) {
 
247
        if( a < EXlo ) return( EDXlo );
 
248
        h = log( a ) - log( EDXlo );
 
249
        return( (EDXlo + ( h / EScale_x ) ) - 1.0 ); /* ??? */
 
250
        }
 
251
}
 
252
 
 
253
/* =========================== */
 
254
/* DY - given an abs coord in Y, returns a value in data space */
 
255
 
 
256
double 
 
257
PLG_dy( a )
 
258
double a;
 
259
{
 
260
double h;
 
261
if( Escaletype_y == E_LINEAR ) {
 
262
        h = a - EYlo;
 
263
        return( EDYlo + ( h / EScale_y ) );
 
264
        }
 
265
else if( Escaletype_y == E_LOG ) {
 
266
        if( a < EYlo ) return( EDYlo );
 
267
        h = log( a ) - log( EDYlo );
 
268
        return( EDYlo + ( h / EScale_y ) );
 
269
        }
 
270
else if( Escaletype_y == E_LOGPLUS1 ) {
 
271
        if( a < EYlo ) return( EDYlo );
 
272
        h = log( a ) - log( EDYlo );
 
273
        return( (EDYlo + ( h / EScale_y ) ) - 1.0 ); /* ??? */
 
274
        }
 
275
}
 
276
 
 
277
 
 
278
/* ====================== */
 
279
/* LIMIT - Get minima or maxima of either axis, 
 
280
   in either absolute or scaled units.. */
 
281
 
 
282
double 
 
283
PLG_limit( axis, end, units )
 
284
char axis;
 
285
char end; /* either 'l' == lo  or 'h' == hi */
 
286
char units; /* either 'a' == absolute or 's' == scaled */
 
287
{
 
288
if( axis == 'x' ) {
 
289
        if( end == 'l' && units == 's' ) return( EDXlo );
 
290
        else if( end == 'h' && units == 's' ) return( EDXhi );
 
291
        if( end == 'l' && units == 'a' ) return( EXlo );
 
292
        else if( end == 'h' && units == 'a' ) return( EXhi );
 
293
        }
 
294
if( axis == 'y' ) {
 
295
        if( end == 'l' && units == 's' ) return( EDYlo );
 
296
        else if( end == 'h' && units == 's' ) return( EDYhi );
 
297
        if( end == 'l' && units == 'a' ) return( EYlo );
 
298
        else if( end == 'h' && units == 'a' ) return( EYhi );
 
299
        }
 
300
Eerr( 12015, "warning, bad values passed to Elimit", "" );
 
301
return( 0.0 );
 
302
}