Skip to content

Commit b1470b1

Browse files
committed
Fixed missing data labels when adding and removing plot data. Fixed issue core-plot#293.
1 parent ec1759e commit b1470b1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

framework/Source/CPTPlot.m

+22-1
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,15 @@ -(void)insertDataAtIndex:(NSUInteger)idx numberOfRecords:(NSUInteger)numberOfRec
628628
}
629629
}
630630

631+
CPTMutableAnnotationArray *labelArray = self.labelAnnotations;
632+
if ( labelArray ) {
633+
id nullObject = [NSNull null];
634+
NSUInteger lastIndex = idx + numberOfRecords - 1;
635+
for ( NSUInteger i = idx; i <= lastIndex; i++ ) {
636+
[labelArray insertObject:nullObject atIndex:i];
637+
}
638+
}
639+
631640
self.cachedDataCount += numberOfRecords;
632641
[self reloadDataInIndexRange:NSMakeRange(idx, numberOfRecords)];
633642
}
@@ -659,8 +668,20 @@ -(void)deleteDataInIndexRange:(NSRange)indexRange
659668
}
660669
}
661670

671+
CPTMutableAnnotationArray *labelArray = self.labelAnnotations;
672+
673+
NSUInteger maxIndex = NSMaxRange(indexRange);
674+
Class annotationClass = [CPTAnnotation class];
675+
676+
for ( NSUInteger i = indexRange.location; i < maxIndex; i++ ) {
677+
CPTAnnotation *annotation = labelArray[i];
678+
if ( [annotation isKindOfClass:annotationClass] ) {
679+
[self removeAnnotation:annotation];
680+
}
681+
}
682+
[labelArray removeObjectsInRange:indexRange];
683+
662684
self.cachedDataCount -= indexRange.length;
663-
[self relabelIndexRange:NSMakeRange(indexRange.location, self.cachedDataCount - indexRange.location)];
664685
[self setNeedsDisplay];
665686
}
666687

0 commit comments

Comments
 (0)