Craig McLeod

Added a method to allow the update of both the current and the total for the pic…

…e chart so it's display remains overall accurate.

- (void)updateChartByCurrent:(NSNumber *)current byTotal:(NSNumber *)total;

We have a scenario where our app is pulling updates to both the "checked in" (our current) and "registered and ready to check in" (our total). Since both values can be updated, the chart would not be correct if only the option for the total to be updated was not available.
... ... @@ -23,6 +23,7 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
- (void)strokeChart;
- (void)growChartByAmount:(NSNumber *)growAmount;
- (void)updateChartByCurrent:(NSNumber *)current;
- (void)updateChartByCurrent:(NSNumber *)current byTotal:(NSNumber *)total;
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
... ...
... ... @@ -206,13 +206,20 @@ displayCountingLabel:(BOOL)displayCountingLabel
-(void)updateChartByCurrent:(NSNumber *)current{
[self updateChartByCurrent:current
byTotal:_total];
}
-(void)updateChartByCurrent:(NSNumber *)current byTotal:(NSNumber *)total {
// Add animation
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = self.duration;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = @([_current floatValue] / [_total floatValue]);
pathAnimation.toValue = @([current floatValue] / [_total floatValue]);
_circle.strokeEnd = [current floatValue] / [_total floatValue];
pathAnimation.toValue = @([current floatValue] / [total floatValue]);
_circle.strokeEnd = [current floatValue] / [total floatValue];
if (_strokeColorGradientStart) {
self.gradientMask.strokeEnd = _circle.strokeEnd;
... ... @@ -221,10 +228,11 @@ displayCountingLabel:(BOOL)displayCountingLabel
[_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
if (_displayCountingLabel) {
[self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([current floatValue], [_total floatValue]) withDuration:self.duration];
[self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([current floatValue], [total floatValue]) withDuration:self.duration];
}
_current = current;
_total = total;
}
@end
\ No newline at end of file
... ...