gujjula / core-plot

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

Labels getting overwritten #278

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have implemented pinch zoom using UIPinchGestureRecognizer.

To make zoom in/out faster, I am calling the respective methods using thread 
executing as a background process.

But the labels are getting overwritten on each other.

Zoom in/out code snippets:

-(void)scaleGraph:(UIPinchGestureRecognizer *)gestureRecognizer{
    NSString *scale = [NSString stringWithFormat:@"%.5f",gestureRecognizer.scale];
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

        if(tempZm < [scale doubleValue]){
            tempZm = [scale doubleValue];
            if(!zoomIsActive){
                [self performSelectorInBackground:@selector(zoomIn) withObject:nil];
            }
        }
        else if(tempZm > [scale doubleValue]){
            tempZm = [scale doubleValue];
            if(!zoomIsActive){
                [self performSelectorInBackground:@selector(zoomOut) withObject:nil];
            }
        }
    }
    if ([gestureRecognizer state] == UIGestureRecognizerStateEnded){
        tempZm = 1.0000;
        [gestureRecognizer setScale:1];
        if(!zoomIsActive){
        [self constructGraph:NO];
        [graph reloadData];
        }
    }

}

-(void)zoomIn{
    zoomIsActive = YES;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    float newValue;
    if(zoomValue >= 0.01 && zoomValue <= 10.0){
        newValue = zoomValue  - 0.01;
    }else if(zoomValue > 10.0 && zoomValue <= 20.0){
        newValue = zoomValue  - 0.10;
    }else if(zoomValue > 20.0 && zoomValue <= 30.0){
        newValue = zoomValue  - 0.5;
    }else if(zoomValue > 30.0){
        newValue = zoomValue  - 1.0;
    }   
    zoomValue = newValue;

    xLocation = newValue * -5;
    xLen = newValue *10;

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLocation) length:CPDecimalFromDouble(xLen )];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLocation) length:CPDecimalFromDouble(xLen )];
    xAxis.majorIntervalLength = CPDecimalFromFloat(newValue);
    yAxis.majorIntervalLength = CPDecimalFromFloat(newValue);

    xMin = xLocation;
    xMax = xLen;

    [pool drain];
    zoomIsActive = NO;
}

-(void)zoomOut{
    zoomIsActive = YES; 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    float newValue;
    if(zoomValue >= 0.01 && zoomValue <= 10.0){
        newValue = zoomValue  + 0.01;
    }else if(zoomValue > 10.0 && zoomValue <= 20.0){
        newValue = zoomValue  + 0.10;
    }else if(zoomValue > 20.0 && zoomValue <= 30.0){
        newValue = zoomValue  + 0.5;
    }else if(zoomValue > 30.0){
        newValue = zoomValue  + 1.0;
    }   
    zoomValue = newValue;

    xLocation = newValue * -5;
    xLen = newValue *10;

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLocation) length:CPDecimalFromDouble(xLen )];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLocation) length:CPDecimalFromDouble(xLen )];

    xAxis.majorIntervalLength = CPDecimalFromFloat(newValue);
    yAxis.majorIntervalLength = CPDecimalFromFloat(newValue);

    xMin = xLocation;
    xMax = xLen;

    [pool drain];
    zoomIsActive = NO;
}

Original issue reported on code.google.com by Manm...@gmail.com on 6 Apr 2011 at 9:16

Attachments:

GoogleCodeExporter commented 9 years ago
Does it work if you call the zoom methods directly instead of using another 
thread?

Original comment by eskr...@mac.com on 7 Apr 2011 at 12:51

GoogleCodeExporter commented 9 years ago
Yes, its works perfectly well if zoom methods are called directly..

Original comment by Manm...@gmail.com on 7 Apr 2011 at 4:22

GoogleCodeExporter commented 9 years ago
I'm new in iphone , can you help me to understand where to place this code? 
actualy i use CPXYGraph into ScatterPlot ... thanks

Original comment by dorin.pa...@gmail.com on 23 Apr 2011 at 5:57

GoogleCodeExporter commented 9 years ago
Core Plot now includes pinch zooming automatically, so you shouldn't need this 
code. Just check out the latest source with mercurial. The CPGraphHostingView 
is what handles the pinches.

Original comment by drewmcco...@mac.com on 24 Apr 2011 at 8:04

GoogleCodeExporter commented 9 years ago
Can you please suggest me how to pinch and zooming automatically in the latest 
code

Original comment by pulata.r...@gmail.com on 2 Jul 2011 at 12:10

GoogleCodeExporter commented 9 years ago
Set allowPinchScaling to YES in your CPTGraphHostingView.

Original comment by drewmcco...@mac.com on 2 Jul 2011 at 2:37