Edu Caselles
Committed by Edu Caselles

Adds property to disable animations when drawing the pie chart.

... ... @@ -52,6 +52,10 @@
@property (nonatomic, weak) id<PNChartDelegate> delegate;
/** Display the pie chart with or wirhout animation. Default is YES. **/
@property (nonatomic) BOOL displayAnimated;
/** Update chart items. Does not update chart itself. */
- (void)updateChartData:(NSArray *)data;
... ...
... ... @@ -47,6 +47,17 @@
self = [self initWithFrame:frame];
if(self){
_items = [NSArray arrayWithArray:items];
[self baseInit];
}
return self;
}
- (void)awakeFromNib{
[self baseInit];
}
- (void)baseInit{
_selectedItems = [NSMutableDictionary dictionary];
_outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
_innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
... ... @@ -58,12 +69,10 @@
_shouldHighlightSectorOnTouch = YES;
_enableMultipleSelection = NO;
_hideValues = NO;
_displayAnimated = YES;
[super setupDefaultValues];
[self loadDefault];
}
return self;
}
- (void)loadDefault{
... ... @@ -129,6 +138,8 @@
[_contentView addSubview:descriptionLabel];
[_descriptionLabels addObject:descriptionLabel];
}
[self addAnimationIfNeeded];
}
- (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index{
... ... @@ -244,6 +255,10 @@
endPercentage:1];
_pieLayer.mask = maskLayer;
}
- (void)addAnimationIfNeeded{
if (_displayAnimated) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = _duration;
animation.fromValue = @0;
... ... @@ -251,7 +266,14 @@
animation.delegate = self;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.removedOnCompletion = YES;
[maskLayer addAnimation:animation forKey:@"circleAnimation"];
[_pieLayer.mask addAnimation:animation forKey:@"circleAnimation"];
}
else {
// Add description labels since no animation is required
[_descriptionLabels enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[obj setAlpha:1];
}];
}
}
- (void)createArcAnimationForLayer:(CAShapeLayer *)layer
... ...