bug: single point test case...

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

bug: single point test case...

Post by Todd J. » Sat Apr 06, 2002 7:16 am

You should add a test case to the demo application for graphcs with one point in addition to the null and zero cases that already exist. I've noticed that the date axis throws exceptions under this condition.

Thanks,
-Todd

Todd J.

Solution to bug: single point test case...

Post by Todd J. » Mon Apr 08, 2002 6:26 am

I solved my problem by adding one line to the HorizontalDateAxis class in the autoAdjustRange() method. Here is the modified method within the class (with a few changes to clean up the code):

public void autoAdjustRange()
{
// check for null plot
if(plot==null) return;

// only proceed if HorizontalValuePlot
if( !(plot instanceof HorizontalValuePlot) ) return;

// cast as HorizontalValuePlot
HorizontalValuePlot hvp = (HorizontalValuePlot)plot;

// get the max data value
Number u = hvp.getMaximumHorizontalDataValue();
long upper = new Date().getTime()+24L*60L*60L*1000L;
if (u!=null) upper = u.longValue();

// determine the lower value
long lower;
if (this.fixedAutoRange>0.0) lower = upper - (long)fixedAutoRange;
else
{ Number l = hvp.getMinimumHorizontalDataValue();
lower = new Date().getTime();
if (l!=null) lower = l.longValue();
long range = upper-lower;

// check for exceptional case of only one point or all the same
// if so, then set range to one minute
if(range == 0L) range = 1000L * 60L;

upper = upper+(range/20);
lower = lower-(range/20);
}

this.minimumDate=new Date(lower);
this.minimumAxisValue=(double)lower;
this.maximumDate=new Date(upper);
this.maximumAxisValue=(double)upper;
}

This is a great package and I hope to contribute often.

-Todd

David Gilbert

Re: Solution to bug: single point test case...

Post by David Gilbert » Mon Apr 08, 2002 9:12 am

Hi Todd,

Thanks. I will incorporate your change for the next version. I might also make the default range a property of the axis so that it can be configured (some developers might want 1 minute, others 1 day etc).

Regards,

DG.

Locked