tags:

views:

50

answers:

1

Problem:

I am plotting a time series. I don't know apriori the minimum & maximum values. I want to plot it for the last 5 seconds of data. I want the plot to automaticaly rescale itself to best fit the data for the past five seconds. However, I don't want the rescaling to be jerky (as one would get by constantly resetting the min & max) -- when it does rescale, I want the rescaling to be smooth.

Are there any existing algorithms for handling this?

Formally:

I have a function

float sample();

that you can call multiple times. I want you to constantly, in real time, plot the last 5 * 60 values to me, with the chart nicely scaled. I want the chart to automatically rescale; but not in a "jerky" way.

Thanks!

+1  A: 

You could try something like

 float currentScale = 0;
 float adjustSpeed = .3f;

 void iterate() {

       float targetScale = sample();
       currentScale += adjustSpeed * (targetScale - currentScale);

 }

And lower the adjustSpeed if it's too jerky.

Tyler