ShinobiCharts hangs when SChartAnnotation is within ExcludedTimePeriod of SChartDiscontinuousDateTimeAxis


#1

Not sure if this is the correct place to report a bug but a few days back I wrote this issue to info@shinobicontrols.com and didn’t get any reply.

I ran into a problem where Shinobi hangs when SChartAnnotation is within the excluded time period of SChartDiscontinuousDateTimeAxis. The hang happens after some manual zooming and scrolling or when setting defaultRange of the axis and redrawing. Minimal example to reproduce the issue is below.

For me this is quite a blocker - I cannot make a release with discontinuous axis crashig the app. I bought the premium version basically only because of the discontinuous axis support and if I knew this feature wouldn’t be working properly, I would have just bought the standard version.

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _chart = [[ShinobiChart alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    
    _chart.licenseKey = @"the key";
    
    SChartDiscontinuousDateTimeAxis *xAxis = [[SChartDiscontinuousDateTimeAxis alloc] init];
    xAxis.enableGesturePanning = YES;
    xAxis.enableGestureZooming = YES;
    xAxis.enableMomentumPanning = YES;
    xAxis.enableMomentumZooming = YES;
    
    _chart.xAxis = xAxis;
    
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] init];
    yAxis.enableGesturePanning = YES;
    yAxis.enableGestureZooming = YES;
    yAxis.enableMomentumPanning = YES;
    yAxis.enableMomentumZooming = YES;
    
    _chart.yAxis = yAxis;
    
    _chart.legend.hidden = YES;
    
    _chart.datasource = self;

    // excluded time period within annotations range
    SChartDateFrequency *freq = [[SChartDateFrequency alloc] initWithSecond:10];
    [xAxis addExcludedTimePeriod:[[SChartTimePeriod alloc] initWithStart: [[NSDate alloc] initWithTimeIntervalSinceNow:10.0] andLength: freq]];

    // freezes with this...
    SChartAnnotation *annotation = [SChartAnnotation verticalBandAtPosition:[[NSDate alloc] initWithTimeIntervalSinceNow:5.0] andMaxX:[[NSDate alloc] initWithTimeIntervalSinceNow:25.0] withXAxis:_chart.xAxis andYAxis:_chart.yAxis withColor:[[UIColor grayColor] colorWithAlphaComponent:0.2f]];
    [_chart addAnnotation: annotation];
    
    // ...but also with this
    annotation = [SChartAnnotation verticalLineAtPosition:[[NSDate alloc] initWithTimeIntervalSinceNow:15.0] withXAxis:_chart.xAxis andYAxis:_chart.yAxis withWidth:2.0 withColor:[UIColor blackColor]];
    [_chart addAnnotation: annotation];

    [self.view addSubview:_chart];
}

- (int)numberOfSeriesInSChart:(ShinobiChart *)chart {
    return 1;
}


- (SChartSeries*)sChart:(ShinobiChart *)chart seriesAtIndex:(int)index {
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];
    return lineSeries;
}


- (int)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(int)seriesIndex {
    return 100;
}


- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(int)dataIndex forSeriesAtIndex:(int)seriesIndex {
    SChartDataPoint *datapoint = [[SChartDataPoint alloc] init];
    
    datapoint.xValue = [NSDate dateWithTimeIntervalSinceNow:dataIndex];
    datapoint.yValue = @(dataIndex);
    
    return datapoint;
}

iOS SChartDiscontinuousDateTimeAxis hangs 100% cpu when the date frequency changes across a range
#2

Hi techet,

Thanks for the bug report. We’re looking into it right now and will get back to you when we have an answer


#3

Hi techet,

I’m sorry you’ve been having this problem. Thanks for the example code - it was really helpful when I came to setup a chart to reproduce this issue. I’m afraid I haven’t had any luck reproducing it so far - the annotation has been added and spans for about 20 seconds or so, with the skip-period inside it. I’ve tried panning around, zooming and setting a default range but have been unsuccessful in reproducing a crash or hang. Is there any other code or gestures I should try to cause the hang?

Best regards,

Rob


#4

Hm, I’m not sure if mails sent to info@shinobicontrols.com end in /dev/null, just posting here what I replied on Friday to be sure:

Hello Rob,

 

thanks a lot for looking into the issue - it’s really important for me to get it resolved. In order to reproduce the crash you need to zoom in to the area where the discontinuation is - i.e. where the vertical line is within the gray area. Then just try to zoom in and out quickly with pinch-to-zoom around the line for a while until it hangs. I just got the hang with y axes between 11 and 18 and x axis between about 18:18:36 and 18:18:50.

 

Best regards,

Jiri

 


 

OK, one more note - during the “hang” CPU utilisation of the app jumps to 100pct (it’s then killed by iOS after several seconds). I suspect this could be some floating-point issue where you loop in a cycle and wait for certain value which never comes (either testing for equality, which is not a good idea for floating point, or just testing for some value which is within the discontinuation range and which doesn’t appear).
 

Jiri


#5

Hi Jiri,

We’ve managed to reproduce the issue - it seems to be when the xAxis’ zoom is sufficient that a second-frequency is needed to display the tick labels. A workaround for the moment is to manually set the xAxis’ tick frequencies, for example:

xAxis.minorTickFrequency = xAxis.majorTickFrequency = [SChartDateFrequency dateFrequencyWithSecond:30];

You can monitor the axis’ zoom level (sChartIsZooming delegate method) and set this manually when appropriate.

This prevents the hang (when adding tick labels into a skip period, iterating takes too long stepping second-by-second). I’ve added this to our internal bug tracker and we hope to have this fixed in a future release - I’ve noted you down as the reporter and we’ll be in touch when a fix is out :slight_smile:

Best regards,

Rob