views:

57

answers:

2

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  A: 

This is what I'm using:

NSDecimal plotPoint[2]; 
CPXYPlotSpace *xySpace = (CPXYPlotSpace *)space; 
[xySpace plotPoint:plotPoint forPlotAreaViewPoint:point]; 

dlog(@"plotPoint = %@, %@", 
[[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateX]] intValue],
[[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateY]] doubleValue]);

I'd guess that you could change CPXYPlotSpace to CPPlotSpace and In my plot the plot space is an CPXYPlotSpace so the plotPoint:forPlotAreaViewPoint method accepts an array of 2 NSDecimal values.

Also in my plot the x-values are all integers, and the y-values are all doubles.

Steve Tranby
A: 

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.

Mark