[comp.windows.x] zooming time scales

mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) (06/01/90)

> [ problem: wants to choose a "nice" tick interval for a given time
>   interval ]

It's not directly what you want, but we once designed the following
code to do something similar for floating-point intervals.  You may be
able to abstract some ideas from it for your needs.

(This is not compilable as it stands; it is intended as illustrative
rather than as a plug-&-play solution.)

#define NUM_DIVISIONS	10 /* we want approx. 10 ticks per axis */

double findScale(min, max)
double min;
double max;
{
	double delta;
	double minScale;
	double scale;
	static int factor[] = { 1, 2, 5 };
	int i;

	delta = FABS(max - min)/NUM_DIVISIONS;

	minScale = FABS(max - min);
	for (i=0; i<ARRAY_SIZE(factor); i++)
	 { double x = delta/factor[i];
	   if ((scale = (pow(10.0, ceil(log10(x)))*factor[i])) < minScale)
	    { minScale = scale;
	    }
	 }
	return (minScale);
}

....

setup_graph()
{
 ....
 xdelta = findScale (xmin, xmax);
 ydelta = findScale (ymin, ymax);
 ....
}

foreachtick(min,max,delta,fxn)
double min;
double max;
double delta;
int (*fxn)();
{
	double v;

	for (v=delta*ceil(min/delta);v<=max;v+=delta)
	 { (*fxn)(v);
	 }
}

draw_xtick(x)
double x;
{
 ....
}

draw_ytick(y)
double y;
{
 ....
}

draw_axes()
{
 ....
 foreachtick(xaxis_min,xaxis_max,xdelta,draw_xtick);
 foreachtick(yaxis_min,yaxis_max,ydelta,draw_ytick);
 ....
}

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

rmr@CS.UMD.EDU (Randy M. Rohrer) (06/01/90)

    Thanks . I'll take a look a give it a whirl.