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
bug: single point test case...
Solution to bug: single point test case...
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
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
Re: Solution to bug: single point test case...
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.
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.