0

I'm using a modified version of the code here to display callout popups from points along the plot in a graph. I've got it mostly working, but the problem I have is that when I scroll or zoom the graph, the callout stays in the same place on the screen, not following as the point moves.

In case you'd like some code samples to play around with, here they are. Any ideas on how to make the callout travel with the plot point? Thanks!

-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx {
    if ([plot.identifier isEqual:_plotIdentifier]) {

        NSArray *selectedSymbolItem = [self.data.xyArrays objectAtIndex:idx];
        NSNumber *x = [selectedSymbolItem objectAtIndex:0];
        NSNumber *y = [selectedSymbolItem objectAtIndex:1];
        double doublePrecisionPlotPoint[2];
        doublePrecisionPlotPoint[0] = x.doubleValue;
        doublePrecisionPlotPoint[1] = y.doubleValue;
        CGPoint pointTouched = [plot.graph.defaultPlotSpace plotAreaViewPointForDoublePrecisionPlotPoint:doublePrecisionPlotPoint];

        CGPoint convertedPoint = [plot.graph convertPoint:pointTouched toLayer:self.view.layer];

        _popupView = [[SMCalloutView alloc] init];
        _popupView.title = [NSString stringWithFormat:@"Thing %i", idx];
        [_popupView presentCalloutFromRect:CGRectMake(convertedPoint.x, convertedPoint.y, 10, 10) inLayer:self.view.layer constrainedToLayer:self.hostView.layer permittedArrowDirections:SMCalloutArrowDirectionDown animated:YES];

    }
}
Community
  • 1
  • 1
RL2000
  • 913
  • 10
  • 20

1 Answers1

1

Use a plot space delegate to monitor changes to the plot space and update the callout position as needed.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • Ah, good idea! I'll give that a shot and let you know how it goes! – RL2000 Feb 08 '13 at 13:14
  • Just added a slightly modified version of the above code to the plotSpace:willChangePlotRangeTo:forCoordinate delegate method, and it works great. The SMCalloutView flickers as I scroll, since I end up calling presentCalloutFromRect with NO for the animated property as I scroll, but aside from that, everything works fine. Thanks! – RL2000 Feb 08 '13 at 15:04