This is a migrated thread and some comments may be shown as answers.

Trackball Selection on Endpoints

6 Answers 64 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 12 May 2016, 03:14 PM
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.

6 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 12 May 2016, 05:03 PM

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]];
    }
}

0
Sophi
Telerik team
answered on 17 May 2016, 08:29 AM
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
0
Ryan
Top achievements
Rank 1
answered on 17 May 2016, 01:10 PM
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.
0
Sophi
Telerik team
answered on 20 May 2016, 08:04 AM
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
0
Ryan
Top achievements
Rank 1
answered on 02 Jun 2016, 03:11 PM
CorePlot's CPTMutablePlotRange - (void)expandRangeByFactor:(nonnull NSNumber *)factor is exactly what I needed. You may want to look into incorporating this into the library
0
Sophi
Telerik team
answered on 07 Jun 2016, 11:46 AM
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
Tags
Chart
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Sophi
Telerik team
Share this question
or