Edu Caselles
Committed by Edu Caselles

Adds property to disable animations when drawing the pie chart.

@@ -52,6 +52,10 @@ @@ -52,6 +52,10 @@
52 52
53 @property (nonatomic, weak) id<PNChartDelegate> delegate; 53 @property (nonatomic, weak) id<PNChartDelegate> delegate;
54 54
  55 +
  56 +/** Display the pie chart with or wirhout animation. Default is YES. **/
  57 +@property (nonatomic) BOOL displayAnimated;
  58 +
55 /** Update chart items. Does not update chart itself. */ 59 /** Update chart items. Does not update chart itself. */
56 - (void)updateChartData:(NSArray *)data; 60 - (void)updateChartData:(NSArray *)data;
57 61
@@ -47,6 +47,17 @@ @@ -47,6 +47,17 @@
47 self = [self initWithFrame:frame]; 47 self = [self initWithFrame:frame];
48 if(self){ 48 if(self){
49 _items = [NSArray arrayWithArray:items]; 49 _items = [NSArray arrayWithArray:items];
  50 + [self baseInit];
  51 + }
  52 +
  53 + return self;
  54 +}
  55 +
  56 +- (void)awakeFromNib{
  57 + [self baseInit];
  58 +}
  59 +
  60 +- (void)baseInit{
50 _selectedItems = [NSMutableDictionary dictionary]; 61 _selectedItems = [NSMutableDictionary dictionary];
51 _outerCircleRadius = CGRectGetWidth(self.bounds) / 2; 62 _outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
52 _innerCircleRadius = CGRectGetWidth(self.bounds) / 6; 63 _innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
@@ -58,12 +69,10 @@ @@ -58,12 +69,10 @@
58 _shouldHighlightSectorOnTouch = YES; 69 _shouldHighlightSectorOnTouch = YES;
59 _enableMultipleSelection = NO; 70 _enableMultipleSelection = NO;
60 _hideValues = NO; 71 _hideValues = NO;
  72 + _displayAnimated = YES;
61 73
62 [super setupDefaultValues]; 74 [super setupDefaultValues];
63 [self loadDefault]; 75 [self loadDefault];
64 - }  
65 -  
66 - return self;  
67 } 76 }
68 77
69 - (void)loadDefault{ 78 - (void)loadDefault{
@@ -129,6 +138,8 @@ @@ -129,6 +138,8 @@
129 [_contentView addSubview:descriptionLabel]; 138 [_contentView addSubview:descriptionLabel];
130 [_descriptionLabels addObject:descriptionLabel]; 139 [_descriptionLabels addObject:descriptionLabel];
131 } 140 }
  141 +
  142 + [self addAnimationIfNeeded];
132 } 143 }
133 144
134 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index{ 145 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index{
@@ -244,6 +255,10 @@ @@ -244,6 +255,10 @@
244 endPercentage:1]; 255 endPercentage:1];
245 256
246 _pieLayer.mask = maskLayer; 257 _pieLayer.mask = maskLayer;
  258 +}
  259 +
  260 +- (void)addAnimationIfNeeded{
  261 + if (_displayAnimated) {
247 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 262 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
248 animation.duration = _duration; 263 animation.duration = _duration;
249 animation.fromValue = @0; 264 animation.fromValue = @0;
@@ -251,7 +266,14 @@ @@ -251,7 +266,14 @@
251 animation.delegate = self; 266 animation.delegate = self;
252 animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 267 animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
253 animation.removedOnCompletion = YES; 268 animation.removedOnCompletion = YES;
254 - [maskLayer addAnimation:animation forKey:@"circleAnimation"]; 269 + [_pieLayer.mask addAnimation:animation forKey:@"circleAnimation"];
  270 + }
  271 + else {
  272 + // Add description labels since no animation is required
  273 + [_descriptionLabels enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  274 + [obj setAlpha:1];
  275 + }];
  276 + }
255 } 277 }
256 278
257 - (void)createArcAnimationForLayer:(CAShapeLayer *)layer 279 - (void)createArcAnimationForLayer:(CAShapeLayer *)layer