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. */
6
/* small, lowlevel routines re: scaled units */
7
/* see also units.c which is a layer above this. */
13
PLG_set_early_defaults()
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" );
22
/* current parameters.. */
23
strcpy( Ecurfont, "" );
27
Ecurtextdirection = 0;
31
Ecurpatternfactor = 0.0;
33
EScale_x = 1; EScale_y = 1;
34
Escaletype_x = E_LINEAR;
35
Escaletype_y = E_LINEAR;
37
strcpy( Eprogname, "" );
45
/* ============================ */
46
/* SCALETYPE - select the scaling method */
48
PLG_scaletype( typ, axis )
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;
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;
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;
76
/* stat = Esetunits( axis, typ );
78
* sprintf( buf, "Invalid scaling type for %c axis", axis );
79
* return( Eerr( 101, buf, typ ) );
83
/* special units always use linear as the basic units.. */
84
if( axis == 'x' ) Escaletype_x = E_LINEAR;
85
else Escaletype_y = E_LINEAR;
90
/* =========================== */
91
/* SCALE_X - for setting up scaling in x */
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 */
106
if( datahi-datalow <= 0 ) return( Eerr( 100, "x range is invalid .. likely culprits: xautorange, or invalid date format" , "" ) );
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, "" ) );
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 ));
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 ));
125
/* =========================== */
126
/* SCALE_Y - for setting up scaling in y */
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 */
134
double logpart, linpart;
142
if( datahi-datalow <= 0 ) return( Eerr( 100, "y range is invalid .. likely culprit is yautorange or yrange", "" ) );
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, "" ) );
149
if( Escaletype_y == E_LINEAR ) EScale_y = (yhi-ylow) / (datahi-datalow) ;
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 ));
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 ));
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. */
172
if( xory == 'x' ) return( Eay( d ) );
173
else if( xory == 'y' ) return( Eax( d ) );
176
if( xory == 'x' ) return( Eax( d ) );
177
else if( xory == 'y' ) return( Eay( d ) );
179
return( Eerr( 15, "Ea: nonsensical parameters", "" ) );
183
/* =========================== */
184
/* AX - returns an absolute x location from a data value */
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 ) );
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 ) );
207
/* =========================== */
208
/* AY - returns an absolute y location from a data value */
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 ) );
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 ) );
229
/* =========================== */
230
/* DX - given an abs coord in X, returns a value in data space */
237
if( Escaletype_x == E_LINEAR ) {
239
return( EDXlo + ( h / EScale_x ) );
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 ) );
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 ); /* ??? */
253
/* =========================== */
254
/* DY - given an abs coord in Y, returns a value in data space */
261
if( Escaletype_y == E_LINEAR ) {
263
return( EDYlo + ( h / EScale_y ) );
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 ) );
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 ); /* ??? */
278
/* ====================== */
279
/* LIMIT - Get minima or maxima of either axis,
280
in either absolute or scaled units.. */
283
PLG_limit( axis, end, units )
285
char end; /* either 'l' == lo or 'h' == hi */
286
char units; /* either 'a' == absolute or 's' == scaled */
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 );
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 );
300
Eerr( 12015, "warning, bad values passed to Elimit", "" );