开发者

Using core-plot, how can you convert a touched point to the plot space?

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:开发者_如何学Python(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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜