XForms: better autoscaling for xyplot?

Percy Zahl (zahl@dynamic.fkp.uni-hannover.de)
Wed, 07 Jan 1998 20:24:41 +0100

To subscribers of the xforms list from Percy Zahl <zahl@dynamic.fkp.uni-hannover.de> :

Better autoscaling for xyplot:

I have one feature I'd very much like to see added as an enhancement
to the xyplot object.=20
An more intelligent autoscaling mode:
- only use "human" intervalls eg. ( 1, 0.5, 0.25, 0.2 )* 10^x
- always align ticks to Zero, eg. not to get label like
-0.3, -0.1, 0.1, ... but -0.2, 0.0, 0.2 ... !
- korrekt sub-tickmarks in log mode

I'd like to give you some code:

// get scaling Intervall from value dl
// if you got an range -5...5, and you like about 10 tickmarks
// you set dl =3D (5-(-5))/10 =3D range/#ticks
double AutoSkl(double dl){
double dp=3Dfloor(log10(dl));
if(dp!=3D0.)
dl/=3Dpow(10.,dp);
if(dl>4) dl=3D5;
else if(dl>1) dl=3D2;
else dl=3D1;
if(dp!=3D0.)
dl*=3Dpow(10.,dp);
return dl;
}

// get the starting value for scaling
double AutoNext(double x0, double dl){
return(ceil(x0/dl)*dl);
}

// Example for the use of these functions:
...
MAXTICS=3DMaximal allowed real number of tickmarks
ntics=3D50; // Number of preferred tickmarks
while((Uend-Ustart)/( dU =3D AutoSkl((Uend-Ustart)/ntics) ) > MAXTICS=
)
ntics--;
// find the starting Value
for(Us=3DU=3DAutoNext(Ustart, dU), idx0=3Didx=3D0; U<Uend; idx++, U+=3D=
dU)
if(fabs(U) < dU/2.){=20
if(U!=3D0.)
Us+=3DU;
idx0=3D10-idx%10; // 10 subticks !
break;=20
}
// now set all tickmarks
for(U=3DUs, idx=3Didx0, ntics=3D0; U<Uend && ntics<148; idx++, ntics+=
+,
U+=3DdU){
tics[ntics].x1 =3D D2D_BORDER_WIDTH +
(int)(mem2d->uMap2idxDbl(spa->ModeFlg & MODE_BZ ?
mem2d->BZ2U(U):U)*(double)ZoomFac+.5); // Map Value in some wise...
tics[ntics].y1 =3D D2D_BORDER_WIDTH;
tics[ntics].x2 =3D tics[ntics].x1;
tics[ntics].y2 =3D D2D_BORDER_WIDTH - D2D_BORDER_WIDTH/(idx%10?5:3)=
;
ntics++;
tics[ntics].x1 =3D tics[ntics-1].x1;
tics[ntics].x2 =3D tics[ntics-1].x1;
tics[ntics].y1 =3D D2D_BORDER_WIDTH + XPM_y;
tics[ntics].y2 =3D D2D_BORDER_WIDTH + XPM_y +
D2D_BORDER_WIDTH/(idx%10?5:3);
if(!(idx%10)){ // 10 subticks !! Draw label ...
if(fabs(U) < 1e-8) U=3D0.;
sprintf(lbl,"%g%s", U, spa->ModeFlg & MODE_BZ ? "%":"V");
lblw=3Dfl_get_string_width(FL_BOLD_STYLE, FL_SMALL_SIZE, lbl,
strlen(lbl));
fl_drw_text(FL_ALIGN_CENTER,tics[ntics].x1,
tics[ntics].y2+D2D_BORDER_WIDTH/3, lblw, 0,
FL_BLACK, FL_BOLD_STYLE, FL_SMALL_SIZE, lbl);
}
}

--=20
with frendly regards,
Percy Zahl
Email: zahl@fkp.uni-hannover.de
Dipl.Phys. P.Zahl: http://www.fkp.uni-hannover.de/~zahl/main.html
Institut f=FCr Festk=F6rperphysik, Appelstr. 2, D-30167 Hannover
Tel.Labor: +49 (0)511/762-4825, Fax: -4877
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bloch.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/