@@ -149,6 +149,11 @@ - (void)layoutSubviews {
149149
150150 } else numberOfPoints = 0 ;
151151
152+ if (numberOfPoints <= 1 ) {
153+ NSLog (@" BEMSimpleLineGraph - Graph initialized with 0 points." );
154+ return ;
155+ }
156+
152157 // Draw the graph
153158 [self drawGraph ];
154159
@@ -199,16 +204,6 @@ - (void)layoutSubviews {
199204#pragma mark - Drawing
200205
201206- (void )drawGraph {
202- if (numberOfPoints <= 1 ) { // Exception if there is only one point.
203- BEMCircle *circleDot = [[BEMCircle alloc ] initWithFrame: CGRectMake (0 , 0 , self .sizePoint, self .sizePoint)];
204- circleDot.center = CGPointMake (self.frame .size .width /2 , self.frame .size .height /2 );
205- circleDot.Pointcolor = self.colorPoint ;
206- circleDot.alpha = 0 ;
207- [self addSubview: circleDot];
208-
209- return ;
210- }
211-
212207 // CREATION OF THE DOTS
213208 [self drawDots ];
214209
@@ -595,12 +590,11 @@ - (void)handlePan:(UIPanGestureRecognizer *)recognizer {
595590 closestDot = [self closestDotFromVerticalLine: self .verticalLine];
596591 closestDot.alpha = 0.8 ;
597592
598-
599- if (self.enablePopUpReport == YES ) {
593+ if (self.enablePopUpReport == YES && closestDot.tag > 99 && closestDot.tag < 1000 && [closestDot isKindOfClass: [BEMCircle class ]]) {
600594 [self setUpPopUpLabelAbovePoint: closestDot];
601595 }
602596
603- if (closestDot.tag > 99 && closestDot.tag < 1000 ) {
597+ if (closestDot.tag > 99 && closestDot.tag < 1000 && [closestDot isKindOfClass: [BEMCircle class ]] ) {
604598 if ([self .delegate respondsToSelector: @selector (lineGraph:didTouchGraphWithClosestIndex: )] && self.enableTouchReport == YES ) {
605599 [self .delegate lineGraph: self didTouchGraphWithClosestIndex: ((NSInteger )closestDot.tag - 100 )];
606600
@@ -670,22 +664,16 @@ - (void)setUpPopUpLabelAbovePoint:(BEMCircle *)closestPoint {
670664#pragma mark - Graph Calculations
671665
672666- (BEMCircle *)closestDotFromVerticalLine : (UIView *)verticalLine {
673- currentlyCloser = 1000 ;
667+ currentlyCloser = pow ((self. frame . size . width /(numberOfPoints- 1 ))/ 2 , 2 ) ;
674668 for (BEMCircle *point in self.subviews ) {
675-
676- if (point.tag > 99 && point.tag < 1000 ) {
677-
678- [UIView animateWithDuration: 0.2 delay: 0 options: UIViewAnimationOptionCurveEaseOut animations: ^{
679- point.alpha = 0 ;
680- } completion: nil ];
681-
669+ if (point.tag > 99 && point.tag < 1000 && [point isKindOfClass: [BEMCircle class ]]) {
670+ point.alpha = 0 ;
682671 if (pow (((point.center .x ) - verticalLine.frame .origin .x ), 2 ) < currentlyCloser) {
683672 currentlyCloser = pow (((point.center .x ) - verticalLine.frame .origin .x ), 2 );
684673 closestDot = point;
685674 }
686675 }
687676 }
688-
689677 return closestDot;
690678}
691679
0 commit comments