Closed GoogleCodeExporter closed 9 years ago
Do you have any sample code that demonstrates this problem? I'm unable to
duplicate this behavior using the latest source.
Original comment by eskr...@mac.com
on 22 May 2011 at 7:08
I've done some investigation and nailed the cause. It is due to rounding
errors because CGFloat (wrapped in CGPoint) was insufficient in handling large
numbers in CPTBarPlot's -lengthInView: method. If you look into the source
code, the two variables in question are originPoint and displacedPoint. A fix
would be to shift the two plot points to within the current range before
computing the plot-point-to-view-point conversion, as in:
-(CGFloat)lengthInView:(NSDecimal)decimalLength
{
CPTCoordinate coordinate = ( self.barsAreHorizontal ? CPTCoordinateY : CPTCoordinateX );
CGFloat length;
if ( !barWidthsAreInViewCoordinates ) {
NSDecimal originPlotPoint[2] = {CPTDecimalFromInteger(0), CPTDecimalFromInteger(0)};
NSDecimal displacedPlotPoint[2] = {decimalLength, decimalLength};
originPlotPoint[0] = CPTDecimalAdd(originPlotPoint[0], [self.plotSpace plotRangeForCoordinate:coordinate].location);
originPlotPoint[1] = CPTDecimalAdd(originPlotPoint[1], [self.plotSpace plotRangeForCoordinate:coordinate].location);
displacedPlotPoint[0] = CPTDecimalAdd(displacedPlotPoint[0], [self.plotSpace plotRangeForCoordinate:coordinate].location);
displacedPlotPoint[1] = CPTDecimalAdd(displacedPlotPoint[1], [self.plotSpace plotRangeForCoordinate:coordinate].location);
CGPoint originPoint = [self.plotSpace plotAreaViewPointForPlotPoint:originPlotPoint];
CGPoint displacedPoint = [self.plotSpace plotAreaViewPointForPlotPoint:displacedPlotPoint];
length = ( coordinate == CPTCoordinateX ? displacedPoint.x - originPoint.x : displacedPoint.y - originPoint.y );
}
else {
length = CPTDecimalCGFloatValue(decimalLength);
}
return length;
}
Original comment by yuki...@gmail.com
on 14 Sep 2011 at 1:33
... or more concisely:
-(CGFloat)lengthInView:(NSDecimal)decimalLength
{
CPTCoordinate coordinate = ( self.barsAreHorizontal ? CPTCoordinateY : CPTCoordinateX );
CGFloat length;
if ( !barWidthsAreInViewCoordinates ) {
NSDecimal rangeLocation = [self.plotSpace plotRangeForCoordinate:coordinate].location;
NSDecimal originPlotPoint[2] = { rangeLocation, rangeLocation };
NSDecimal displacedPlotPoint[2] = {
CPTDecimalAdd(rangeLocation, decimalLength),
CPTDecimalAdd(rangeLocation, decimalLength) };
CGPoint originPoint = [self.plotSpace plotAreaViewPointForPlotPoint:originPlotPoint];
CGPoint displacedPoint = [self.plotSpace plotAreaViewPointForPlotPoint:displacedPlotPoint];
length = ( coordinate == CPTCoordinateX ? displacedPoint.x - originPoint.x : displacedPoint.y - originPoint.y );
}
else {
length = CPTDecimalCGFloatValue(decimalLength);
}
return length;
}
Original comment by yuki...@gmail.com
on 14 Sep 2011 at 1:44
Original comment by eskr...@mac.com
on 16 Sep 2011 at 12:16
This issue was closed by revision 3e84fc8bb935.
Original comment by eskr...@mac.com
on 18 Sep 2011 at 2:11
Original issue reported on code.google.com by
drewmcco...@mac.com
on 2 Mar 2011 at 8:14