CorePlot 绘图命中测试
我有一个关于 CorePlot 的问题。我的问题是: 我画了一条曲线。下一个任务是:曲线选择。 我已经添加了处理程序:
但这不起作用。 有什么想法吗? 谢谢。
- (BOOL)npvCurveContainPoint:(CGPoint)point
{
if ([[graph allPlots] count] == 0) {
return NO;
}
CPTPlot* plot = [graph plotAtIndex:0];
BOOL xContains = [[plot plotRangeForCoordinate:CPTCoordinateX] containsDouble:point.x];
BOOL yContains = [[plot plotRangeForCoordinate:CPTCoordinateY] containsDouble:point.y];
if (xContains && yContains) {
return YES;
}
return NO;
}
#pragma mark - Plot Space Delegate Methods
- (BOOL)plotSpace:(CPTPlotSpace*)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point
{
CGPoint pointInPlotArea = [graph convertPoint:point fromLayer:graph.plotAreaFrame];
if ([self npvCurveContainPoint:pointInPlotArea]) {
NSLog(@"Curve is selected!!!");
}
return NO;
}
I have a question about CorePlot. My question is:
I've drawn a curve. Next task is: curve selection.
I've added the handler:
But that does not work.
Any ideas?
Thanks.
- (BOOL)npvCurveContainPoint:(CGPoint)point
{
if ([[graph allPlots] count] == 0) {
return NO;
}
CPTPlot* plot = [graph plotAtIndex:0];
BOOL xContains = [[plot plotRangeForCoordinate:CPTCoordinateX] containsDouble:point.x];
BOOL yContains = [[plot plotRangeForCoordinate:CPTCoordinateY] containsDouble:point.y];
if (xContains && yContains) {
return YES;
}
return NO;
}
#pragma mark - Plot Space Delegate Methods
- (BOOL)plotSpace:(CPTPlotSpace*)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point
{
CGPoint pointInPlotArea = [graph convertPoint:point fromLayer:graph.plotAreaFrame];
if ([self npvCurveContainPoint:pointInPlotArea]) {
NSLog(@"Curve is selected!!!");
}
return NO;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你到底想测试什么,但你正在混合坐标系。传递给绘图空间委托方法的点位于绘图区域图层的视图坐标中。您将其转换为整个图形层的坐标系,然后根据绘图空间数据坐标测试该点。
绘图空间定义了数据和屏幕上绘图区域之间的映射。
xRange
的location
对应于绘图区域的左边缘及其终点(location
+length
) 对应于右手边。同样,yRange
的location
对应于绘图区域的底部边缘,其终点对应于顶部边缘。请注意,绘图范围可以具有负长度,这意味着终点的数据坐标可以小于起始位置。I'm not sure exactly what you're trying to test, but you're mixing coordinate systems. The point passed to the plot space delegate method is in the view coordinates of the plot area layer. You convert it to the coordinate system of the entire graph layer and then test the point against the plot space data coordinates.
The plot space defines the mapping between the data and the plot area on screen. The
location
of thexRange
corresponds to the left hand edge of the plot area and its end point (location
+length
) corresponds to the right hand edge. Similarly, thelocation
of theyRange
corresponds to the bottom edge of the plot area and its end point corresponds to the top edge. Note the plot ranges can have negative lengths, which means that the data coordinate of the end point can be less than the starting location.