gujjula / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Bar Widths of CPBarPlot sometimes change during zooming #262

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that bar widths can sometimes change when zooming a CPBarPlot. This 
might be related to having very many bars. Son Nguyen reports that with 2000 
bars, this problem arises. You can see it in this video:

http://www.youtube.com/watch?v=BpVtgd5vNR4

This seems like perhaps the bar width is not set at the time of drawing, or 
something like that. It could also be a bug in CPXYPlotSpace, which for some 
reason is not accurately converting between plot and view coordinates when 
determining the bar width.

Original issue reported on code.google.com by drewmcco...@mac.com on 2 Mar 2011 at 8:14

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
... 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

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 16 Sep 2011 at 12:16

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 3e84fc8bb935.

Original comment by eskr...@mac.com on 18 Sep 2011 at 2:11