Using core-plot, how can you convert a touched poi

2020-06-23 05:51发布

问题:

I have a very simple graph that I want to enable touch on, I have the first part working:

plotSpace.delegate = self;

and the method:

-(BOOL)plotSpace:(CPPlotSpace *)space
shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point
{
    NSLog(@"touched at: x: %f y: %f", point.x, point.y);
}

How do I convert the point "point" to the plot space of my graph?

I can see the methods, but Im unsure on how to use them, the doco, although large, doesnt really describe them well enough :)

Thanks a lot Mark

回答1:

I have to admit, I forgot about this question, thanks for the reply Steve.

I did get it solved too, here is my implementation (im extending CPXYGraph)

-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point {

    CPScatterPlot *plot = (CPScatterPlot*)[[self allPlots] objectAtIndex: 0];
    CGPoint pointInPlotArea = [plot convertPoint:point toLayer:plot];

    if ([plot containsPoint:pointInPlotArea]) {
        CPXYPlotSpace *plotSpace = (CPXYPlotSpace*)[self defaultPlotSpace];
        NSDecimal touchDataPoint[2];
        [plotSpace plotPoint:touchDataPoint forPlotAreaViewPoint:pointInPlotArea];
    }
}

touchDataPoint then contains the coords that the user has touched.