Problem with Math.Round and gridStep
Status: Alpha
Brought to you by:
simply_me
When i was trying to use rrdSharp, occasionally it would
hang when trying to graph. Upon inspection of the code
it gets caught in an endless loop in
ValueAxisUnit.GetValueMarkers().
Basically gridstep was less than or equal to 0.5. (in my
case it was 0.5) Thus when:
minPoint = Math.Round( minPoint + gridStep);
its value never changes and it loops forever.
Please note that the Round function is different in Java
than .NET.
.NET uses bankers rounding which if there are two
nearest integers then it goes to the even one.
so in java Math.Round(4.5) = 5
while in .NET Math.Round(4.5) = 4
Logged In: YES
user_id=1496172
I found that this problem occured for when a data series has
all zero values.
Not having a lot of time to dig into the code, I was able to
come up with a hack work around that some may find useful
until the maintainers can update the code to fix this.
Using .NET 2.0, I added "MidpointRounding.AwayFromZero"
paramater to all Math.Round() calls, ex.
minPoint = Math.Round(minPoint + gridStep,
MidpointRounding.AwayFromZero);
And in ValueAxisUnit.cs added loops to increment the
gridStep and labelStep values by *10.
Starting from Line 81
// Now get all time markers.
// Again we choose to use a series of loops as to avoid
unnecessary drawing.
ArrayList markerList = new ArrayList();
while ( minPoint <= upper && majPoint <= upper )
{
// Added the following 2 while loops to increment
// gridStep and labelStep
while (gridStep < 0.5)
{
gridStep *= 10;
}
while (labelStep < 1)
{
labelStep *= 10;
}