Subtle bug when switching datasets (0.9.6)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Irv Thomae

Subtle bug when switching datasets (0.9.6)

Post by Irv Thomae » Mon Mar 03, 2003 9:01 pm

Hello David,
I've discovered a subtle problem which I had never noticed before switching over to 0.9.6, although I cannot be absolutely certain.

My application's main TimeSeriesChart displays 24 hours' worth of minute-by-minute data, or 1440 time values in all. Data collected from some 28 different sources are held in memory, and a menu allows the user to select any one of about 25 data sources. (All of the data in question comes from exactly the same 24-hour timespan.) The code that loads the new dataset does call "fireDatasetChanged()", and the plot does indeed get updated to show the new data.
Because some sets of data have much larger full-scale ranges than others, jFreeChart's autoranging often produces longer (or shorter) TickUnitLabels for the vertical axis, causing it to shift left or right. This in turn may expand or contract the space available for the x-axis, so it now gets rescaled, moving the hourly tickmarks either farther apart or closer together.
However, when that happens, the displayed data does NOT get correspondingly stretched or squeezed. - so (for example) data from 23 hours ago now stands labelled as if it was only 22 hours old. Changing the x-axis scale should, of course, trigger redrawing the data itself - is there a new fireWhatever() method that needs to be called along with fireDatasetChanged() ???

Thanks,
Irv Thomae

Irv Thomae

Re: Subtle bug when switching datasets (0.9.6)

Post by Irv Thomae » Mon Mar 03, 2003 9:33 pm

(Addendum to my previous posting)

Alternatively, is there a way to "freeze" the left-rt postion of the vertical axis, so that it won't move left/rt as the vertical axis is rescaled?

Thanks!

David Gilbert

Re: Subtle bug when switching datasets (0.9.6)

Post by David Gilbert » Tue Mar 04, 2003 7:30 am

Hi Irv,

That sounds nasty. I can't think how it could happen, but then isn't that always the case with bugs! I have added it to the bug database and SourceForge (697093) and will take a look when I get a chance.

There is a method setFixedDimension(...) that all axes inherit from the Axis class. It is used to ensure that all axes in a combined plot use the same width or height (depending on the orientation). It might solve your problem, although you would somehow have to calculate the width you need to allow.

Regards,

Dave Gilbert

Irv Thomae

Re: Subtle bug when switching datasets (0.9.6)

Post by Irv Thomae » Tue Mar 04, 2003 5:26 pm

Hi Dave,
Yes, it is nasty. Vertical-axis zooms can also cause the y-axis to move left or right, redrawing the x-axis. In this case too the onscreen length of the data should change to match, but does not.

However, it's not really "your" bug, because the plot in question uses class "FastXYImpulseRenderer", which I posted in this phorum several months ago. For optimum performance, this class caches the calculated x-positions [i.e., the results from domainAxis.translateValueToJava2D() ] There _is_ a flushCache() method, which clearly _should_ be invoked whenever the y-axis scale changes, but in fact is not.

In retrospect, this is clear: a Renderer class which caches any aspect of its data should register as a SeriesChangeEvent listener, so it can flush its cache when the dataset or series changes. I'm not sure, however, that this will take care of the vertical-axis zoom problem.

So I'll re-frame my question: in jFreeChart-0.9.6, is there a single event-type that will be fired in response to vertical-scale changes as well as to dataset changes?

Thanks,
Irv Thomae

David Gilbert

Re: Subtle bug when switching datasets (0.9.6)

Post by David Gilbert » Tue Mar 04, 2003 5:54 pm

Hi Irv,

The plot always gets notified of dataset changes via the datasetChanged(...) method inherited from the Plot class - the default behaviour is to pass on a PlotChangeEvent to listeners (usually just the JFreeChart object).

Similarly, the plot always gets notified of axis change events via the axisChanged(...) method inherited from the Plot class - and the default behaviour is similar, a PlotChangeEvent is passed on to listeners (usually just the JFreeChart object).

I wonder if there is a way for you to cache information within the plot rather than the renderer...then it will be easier to clear the cache in response to these events.

Regards,

Dave Gilbert

Irv Thomae

Re: Subtle bug when switching datasets (0.9.6)

Post by Irv Thomae » Tue Mar 04, 2003 7:05 pm

Hi Dave,
Your explanation was very helpful, and the frozen-data bug is now fixed.. Knowing that both scale-change and data-change events would drive a PlotChangeEvent, it was very easy to make my special renderer implement PlotChangeListener. Then, in the display setup code, I simply inserted an addChangeListener(myRenderer) call just after creating the renderer.

Thanks!!

Irv

Locked