Emma Makinson
Committed by Edu Caselles

Makes animation optional on Bar Chart

... ... @@ -31,4 +31,7 @@
@property (nonatomic, assign) BOOL isNegative; //!< 是否是负数
@property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers
/** Display the bar with or without animation. Default is YES. **/
@property (nonatomic) BOOL displayAnimated;
@end
... ...
... ... @@ -55,6 +55,7 @@
[progressline setLineWidth:1.0];
[progressline setLineCapStyle:kCGLineCapSquare];
[self addAnimationIfNeededWithProgressLine:progressline];
if (_barColor) {
... ... @@ -66,20 +67,11 @@
if (_grade) {
CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.fromValue = (id)_chartLine.path;
pathAnimation.toValue = (id)[progressline CGPath];
pathAnimation.duration = 0.5f;
pathAnimation.autoreverses = NO;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[_chartLine addAnimation:pathAnimation forKey:@"animationKey"];
_chartLine.path = progressline.CGPath;
if (_barColorGradientStart) {
// Add gradient
[self.gradientMask addAnimation:pathAnimation forKey:@"animationKey"];
self.gradientMask.path = progressline.CGPath;
CABasicAnimation* opacityAnimation = [self fadeAnimation];
... ... @@ -88,13 +80,6 @@
}
}else{
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 1.0;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = @0.0f;
pathAnimation.toValue = @1.0f;
[_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
_chartLine.strokeEnd = 1.0;
_chartLine.path = progressline.CGPath;
... ... @@ -109,7 +94,6 @@
self.gradientMask.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
self.gradientMask.path = progressline.CGPath;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.startPoint = CGPointMake(0.0,0.0);
gradientLayer.endPoint = CGPointMake(1.0 ,0.0);
... ... @@ -127,7 +111,6 @@
[_chartLine addSublayer:gradientLayer];
self.gradientMask.strokeEnd = 1.0;
[self.gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
CABasicAnimation* opacityAnimation = [self fadeAnimation];
[self.textLayer addAnimation:opacityAnimation forKey:nil];
... ... @@ -267,4 +250,31 @@
return fadeAnimation;
}
-(void)addAnimationIfNeededWithProgressLine:(UIBezierPath *)progressline
{
if (_displayAnimated) {
CABasicAnimation *pathAnimation = nil;
if (_grade) {
pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.fromValue = (id)_chartLine.path;
pathAnimation.toValue = (id)[progressline CGPath];
pathAnimation.duration = 0.5f;
pathAnimation.autoreverses = NO;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[_chartLine addAnimation:pathAnimation forKey:@"animationKey"];
}
else {
pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 1.0;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = @0.0f;
pathAnimation.toValue = @1.0f;
[_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
}
[self.gradientMask addAnimation:pathAnimation forKey:@"animationKey"];
}
}
@end
... ...
... ... @@ -112,6 +112,9 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
/** Controls whether text for x-axis be straight or rotate 45 degree. */
@property (nonatomic) BOOL rotateForXAxisText;
/** Display the bar chart with or without animation. Default is YES. **/
@property (nonatomic) BOOL displayAnimated;
@property (nonatomic, weak) id<PNChartDelegate> delegate;
/**whether show gradient bar*/
... ...
... ... @@ -68,6 +68,7 @@
_rotateForXAxisText = false;
_isGradientShow = YES;
_isShowNumbers = YES;
_displayAnimated = YES;
_yLabelPrefix = @"";
_yLabelSuffix = @"";
_yLabelFormatter = ^(CGFloat yValue){
... ... @@ -241,6 +242,9 @@
//Change Bar Radius
bar.barRadius = _barRadius;
//Set Bar Animation
bar.displayAnimated = _displayAnimated;
//Change Bar Background color
bar.backgroundColor = _barBackgroundColor;
... ...
... ... @@ -53,7 +53,7 @@
@property (nonatomic, weak) id<PNChartDelegate> delegate;
/** Display the pie chart with or wirhout animation. Default is YES. **/
/** Display the pie chart with or without animation. Default is YES. **/
@property (nonatomic) BOOL displayAnimated;
/** Update chart items. Does not update chart itself. */
... ...