CorePlot 绘图命中测试

发布于 2024-12-10 16:21:56 字数 905 浏览 0 评论 0原文

我有一个关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心荒芜 2024-12-17 16:21:56

我不确定你到底想测试什么,但你正在混合坐标系。传递给绘图空间委托方法的点位于绘图区域图层的视图坐标中。您将其转换为整个图形层的坐标系,然后根据绘图空间数据坐标测试该点。

绘图空间定义了数据和屏幕上绘图区域之间的映射。 xRangelocation 对应于绘图区域的左边缘及其终点(location + length) 对应于右手边。同样,yRangelocation 对应于绘图区域的底部边缘,其终点对应于顶部边缘。请注意,绘图范围可以具有负长度,这意味着终点的数据坐标可以小于起始位置。

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 the xRange corresponds to the left hand edge of the plot area and its end point (location + length) corresponds to the right hand edge. Similarly, the location of the yRange 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文