0

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!

anon
  • 41,035
  • 53
  • 197
  • 293
  • Wouldn't the user be utterly confused if you kept rescaling? –  Feb 25 '10 at 02:03
  • 1) I'm the user. 2) It's for debugging; I'm running a simulation; I need to plot a bunch of different things. I would like a single class that I can just toss it a bunch of data, and it'll just "do the right thing" – anon Feb 25 '10 at 02:09

1 Answers1

1

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
  • 373
  • 1
  • 14