Trackball Selection on Endpoints

7 posts, 0 answers
  1. Ryan
    Ryan avatar
    4 posts
    Member since:
    Sep 2015

    Posted 12 May Link to this post

    It is very difficult to begin trackball selection on either endpoint of a line chart. The trackballs on both endpoints are cut in half, and attempting to directly select them is very difficult, especially since the plot extends to the very edge of the touchable region of the TKChart. To make it easier to use, I am attempting to send touches that begin outside the TKChart view and come into the view to the trackballDidTrackSelection delegate method. There is a function on TKChart hitTestForPoint but you have to get the point exactly for it to do any good. TKChart should make available a hitTestForPoint: method that respects your TKChartTrackballSnapMode choice.
  2. Ryan
    Ryan avatar
    4 posts
    Member since:
    Sep 2015

    Posted 12 May Link to this post

    It would still be great to have a method to do this for you, or at least the ability to inset the plotView inside the TKChart frame, but I was able to hack together a solution.

    -(void)edgeSwipe:(UIScreenEdgePanGestureRecognizer*)swipe
    {
        TKChartSeries *series = self.chartView.series.firstObject;
        TKChartSelectionInfo *selection;
        TKChartDataPoint *tkpoint = [series visiblePoints].lastObject;
        TKChartSeriesRender *render = [[TKChartSeriesRender alloc]init];
        render.bounds = self.chartView.plotView.bounds;
        CGPoint truePoint = [render locationOfPoint:tkpoint inSeries:series];
        switch (swipe.state) {
            case UIGestureRecognizerStateBegan:{
                [self hideAnnotation];
                selection = [[TKChartSelectionInfo alloc]initWithSeries:series dataPointIndex:self.plotDataItems.count-1];
                break;
            }
            case UIGestureRecognizerStateChanged:{
                CGPoint point = [swipe locationInView:self.chartView.plotView];
                for (int i = self.plotDataItems.count-1; i > 1; --i) {
                    float xLoc = [render locationOfXNumericValue:i+1 inSeries:series];
                    float xLocBack = [render locationOfXNumericValue:i inSeries:series];
                    if (point.x > xLoc || fabsf(point.x - xLoc) < fabsf(point.x - xLocBack)){
                        tkpoint = [series visiblePoints][i];
                        break;
                    }else if (point.x > xLocBack){
                        tkpoint = [series visiblePoints][i-1];
                        break;
                    }
                }
                truePoint = [render locationOfPoint:tkpoint inSeries:series];
                selection = [self.chartView.plotView hitTestForPoint:truePoint];
                break;
            }
            case UIGestureRecognizerStateEnded:
                [self showAnnotation];
                break;
            default:
                break;
        }
        if (selection) {
            [self.chartView.trackball showAtPoint:truePoint];
            [self chart:self.chartView trackballDidTrackSelection:@[selection]];
        }
    }

  3. DevCraft banner
  4. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 17 May Link to this post

    Hello, Ryan,

    I am glad to hear that you have came up with a solution.
    Since you are interested in plot view insets, you can use the plotViewInsets property for this purpose.

    In case you have any other questions or concerns, do not hesitate to contact us.

    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Ryan
    Ryan avatar
    4 posts
    Member since:
    Sep 2015

    Posted 17 May in reply to Sophi Link to this post

    plotViewInsets does indeed inset the plot from the superview, but this does not change the appearance of the trackball. On the edgepoints, the trackball is still only half a point.
  6. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 20 May Link to this post

    Hi Ryan,

    The appearance of the trackball on the edges of the chart is expected behavior. This is how the chart is meant to be implemented in order to achieve better visual look.

    TKChart does not provide setup, for showing the full trackball on the edges of the chart, at this point of time.

    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Ryan
    Ryan avatar
    4 posts
    Member since:
    Sep 2015

    Posted 02 Jun in reply to Sophi Link to this post

    CorePlot's CPTMutablePlotRange - (void)expandRangeByFactor:(nonnull NSNumber *)factor is exactly what I needed. You may want to look into incorporating this into the library
  8. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 07 Jun Link to this post

    Hello Ryan,

    Thank you for your feedback and reference.
    We will consider including similar feature in the TKChart. 

    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner