Delayed annotation drawing when creating them in async block (added and redrawn on main)


#1

Hi,

I am running into an odd issue. I am ading annotations to a chart and when i do the whole function on the main queue its ok.
The problem arises when i try to always dispatch the whole calculations onto an async method and call the [chart addAnnotation:] and [annotation updateViewWithCanvas:] on the main thread (dispatch_get_main_queue()).
One annotation is a vertical line and it is displayed ASAP (seems to be almoust instant) but the other (annotationWithText and my custom circle annotations) are not shown for several seconds (I observe in the logs that the calls - add and redraw have been made!). The issue dissapears when i change all of the code to run in the main thread. Have you run into this kind of issue? Can you help me with the resolution? 


#2

Up.

I have removed the canvasUpdate as Adding the annotation already fires an update.
Have a look at this code (Any solution?):

//THIS HAPPENS IN AN DISPATCH_ASYNC - global queue or custom queue - NOT MAIN

//If I move this line into the main queue (inside the dispatch_async(dispatch_get_main_queue(), ^ block 
//then everything is drawn immediately 
SChartAnnotation * lineTagAnnotation = [SChartAnnotation annotationWithText:@"Information String" andFont:[UIFont fontWithName:@"Nunito-Light" size:10.f]
                                                                                      withXAxis:chart.xAxis
                                                                                       andYAxis:chart.yAxis
                                                                                    atXPosition:@(40)
                                                                                   andYPosition:@(60)
                                                                                  withTextColor:[UIColor redColor] withBackgroundColor:chart.plotAreaBackgroundColor];
        //Vertical line
        SChartAnnotation *lineAnnotation = [SChartAnnotation verticalLineAtPosition:[dataPoint xValue]
                                                                                      withXAxis:chart.xAxis
                                                                                       andYAxis:chart.yAxis
                                                                                      withWidth:2.f
                                                                                      withColor:[UIColor redColor]];
        //chartAnnotation.position = SChartAnnotationBelowData;

         dispatch_async(dispatch_get_main_queue(), ^
        {
            //Remove and add annotations
            [chart removeAllAnnotations];<br>            
       
        //The line is drawn immediatly    
        [chart addAnnotation:lineAnnotation]; //add line    

        //There is a big delay in displaying the tag annotation
        [chart addAnnotation:lineTagAnnotation]; //add line tag
        
        NSLog(@"Added annotations");
    });