Skip to content

Commit

Permalink
Updated draw dots method for performance
Browse files Browse the repository at this point in the history
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
#	modified:   Classes/BEMSimpleLineGraphView.m
#
  • Loading branch information
Ben Lei committed Oct 22, 2014
1 parent cb7d5bd commit 91cbbcf
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions Classes/BEMSimpleLineGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,40 +368,42 @@ - (void)drawDots {
positionOnXAxis = (((self.frame.size.width - self.YAxisLabelXOffset) / (numberOfPoints - 1)) * i) + self.YAxisLabelXOffset;
positionOnYAxis = [self yPositionForDotValue:dotValue];

BEMCircle *circleDot = [[BEMCircle alloc] initWithFrame:CGRectMake(0, 0, self.sizePoint, self.sizePoint)];
circleDot.center = CGPointMake(positionOnXAxis, positionOnYAxis);
circleDot.tag = i+100;
circleDot.alpha = 0;
circleDot.absoluteValue = dotValue;
circleDot.Pointcolor = self.colorPoint;

[yAxisValues addObject:[NSNumber numberWithFloat:positionOnYAxis]];

[self addSubview:circleDot];

if (self.alwaysDisplayPopUpLabels == YES) {
if ([self.delegate respondsToSelector:@selector(lineGraph:alwaysDisplayPopUpAtIndex:)]) {
if ([self.delegate lineGraph:self alwaysDisplayPopUpAtIndex:i] == YES) {
[self displayPermanentLabelForPoint:circleDot];
}
} else [self displayPermanentLabelForPoint:circleDot];
}

// Dot entrance animation
if (self.animationGraphEntranceTime == 0) {
if (self.alwaysDisplayDots == NO) {
circleDot.alpha = 0;
} else circleDot.alpha = 0.7;
} else {
[UIView animateWithDuration:(float)self.animationGraphEntranceTime/numberOfPoints delay:(float)i*((float)self.animationGraphEntranceTime/numberOfPoints) options:UIViewAnimationOptionCurveLinear animations:^{
circleDot.alpha = 0.7;
} completion:^(BOOL finished) {

if (self.animationGraphEntranceTime != 0 || self.alwaysDisplayDots == YES) {
BEMCircle *circleDot = [[BEMCircle alloc] initWithFrame:CGRectMake(0, 0, self.sizePoint, self.sizePoint)];
circleDot.center = CGPointMake(positionOnXAxis, positionOnYAxis);
circleDot.tag = i+100;
circleDot.alpha = 0;
circleDot.absoluteValue = dotValue;
circleDot.Pointcolor = self.colorPoint;

[self addSubview:circleDot];

if (self.alwaysDisplayPopUpLabels == YES) {
if ([self.delegate respondsToSelector:@selector(lineGraph:alwaysDisplayPopUpAtIndex:)]) {
if ([self.delegate lineGraph:self alwaysDisplayPopUpAtIndex:i] == YES) {
[self displayPermanentLabelForPoint:circleDot];
}
} else [self displayPermanentLabelForPoint:circleDot];
}

// Dot entrance animation
if (self.animationGraphEntranceTime == 0) {
if (self.alwaysDisplayDots == NO) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
circleDot.alpha = 0;
} completion:nil];
}
}];
circleDot.alpha = 0; // never reach here
} else circleDot.alpha = 0.7;
} else {
[UIView animateWithDuration:(float)self.animationGraphEntranceTime/numberOfPoints delay:(float)i*((float)self.animationGraphEntranceTime/numberOfPoints) options:UIViewAnimationOptionCurveLinear animations:^{
circleDot.alpha = 0.7;
} completion:^(BOOL finished) {
if (self.alwaysDisplayDots == NO) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
circleDot.alpha = 0;
} completion:nil];
}
}];
}
}
}
}
Expand Down

0 comments on commit 91cbbcf

Please sign in to comment.