Showing
9 changed files
with
85 additions
and
100 deletions
| @@ -63,10 +63,10 @@ | @@ -63,10 +63,10 @@ | ||
| 63 | [_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 63 | [_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 64 | 64 | ||
| 65 | _chartLine.strokeEnd = 1.0; | 65 | _chartLine.strokeEnd = 1.0; |
| 66 | - | 66 | + |
| 67 | // Check if user wants to add a gradient from the start color to the bar color | 67 | // Check if user wants to add a gradient from the start color to the bar color |
| 68 | if (_barColorGradientStart) { | 68 | if (_barColorGradientStart) { |
| 69 | - | 69 | + |
| 70 | // Add gradient | 70 | // Add gradient |
| 71 | CAShapeLayer *gradientMask = [CAShapeLayer layer]; | 71 | CAShapeLayer *gradientMask = [CAShapeLayer layer]; |
| 72 | gradientMask.fillColor = [[UIColor clearColor] CGColor]; | 72 | gradientMask.fillColor = [[UIColor clearColor] CGColor]; |
| @@ -74,8 +74,8 @@ | @@ -74,8 +74,8 @@ | ||
| 74 | gradientMask.lineWidth = self.frame.size.width; | 74 | gradientMask.lineWidth = self.frame.size.width; |
| 75 | gradientMask.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height); | 75 | gradientMask.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height); |
| 76 | gradientMask.path = progressline.CGPath; | 76 | gradientMask.path = progressline.CGPath; |
| 77 | - | 77 | + |
| 78 | - | 78 | + |
| 79 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; | 79 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; |
| 80 | gradientLayer.startPoint = CGPointMake(0.5,1.0); | 80 | gradientLayer.startPoint = CGPointMake(0.5,1.0); |
| 81 | gradientLayer.endPoint = CGPointMake(0.5,0.0); | 81 | gradientLayer.endPoint = CGPointMake(0.5,0.0); |
| @@ -86,11 +86,11 @@ | @@ -86,11 +86,11 @@ | ||
| 86 | (id)endColor.CGColor | 86 | (id)endColor.CGColor |
| 87 | ]; | 87 | ]; |
| 88 | gradientLayer.colors = colors; | 88 | gradientLayer.colors = colors; |
| 89 | - | 89 | + |
| 90 | [gradientLayer setMask:gradientMask]; | 90 | [gradientLayer setMask:gradientMask]; |
| 91 | - | 91 | + |
| 92 | [_chartLine addSublayer:gradientLayer]; | 92 | [_chartLine addSublayer:gradientLayer]; |
| 93 | - | 93 | + |
| 94 | gradientMask.strokeEnd = 1.0; | 94 | gradientMask.strokeEnd = 1.0; |
| 95 | [gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 95 | [gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 96 | } | 96 | } |
| @@ -112,9 +112,9 @@ | @@ -112,9 +112,9 @@ | ||
| 112 | [sublayer removeFromSuperlayer]; | 112 | [sublayer removeFromSuperlayer]; |
| 113 | } | 113 | } |
| 114 | _barColorGradientStart = barColorGradientStart; | 114 | _barColorGradientStart = barColorGradientStart; |
| 115 | - | 115 | + |
| 116 | [self setGrade:_grade]; | 116 | [self setGrade:_grade]; |
| 117 | - | 117 | + |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | // Only override drawRect: if you perform custom drawing. | 120 | // Only override drawRect: if you perform custom drawing. |
| @@ -50,13 +50,13 @@ | @@ -50,13 +50,13 @@ | ||
| 50 | - (void)setYValues:(NSArray *)yValues | 50 | - (void)setYValues:(NSArray *)yValues |
| 51 | { | 51 | { |
| 52 | _yValues = yValues; | 52 | _yValues = yValues; |
| 53 | - | 53 | + |
| 54 | if (_yMaxValue) { | 54 | if (_yMaxValue) { |
| 55 | _yValueMax = _yMaxValue; | 55 | _yValueMax = _yMaxValue; |
| 56 | } else { | 56 | } else { |
| 57 | [self getYValueMax:yValues]; | 57 | [self getYValueMax:yValues]; |
| 58 | } | 58 | } |
| 59 | - | 59 | + |
| 60 | 60 | ||
| 61 | _xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [_yValues count]; | 61 | _xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [_yValues count]; |
| 62 | } | 62 | } |
| @@ -64,9 +64,9 @@ | @@ -64,9 +64,9 @@ | ||
| 64 | - (void)getYValueMax:(NSArray *)yLabels | 64 | - (void)getYValueMax:(NSArray *)yLabels |
| 65 | { | 65 | { |
| 66 | int max = [[yLabels valueForKeyPath:@"@max.intValue"] intValue]; | 66 | int max = [[yLabels valueForKeyPath:@"@max.intValue"] intValue]; |
| 67 | - | 67 | + |
| 68 | _yValueMax = (int)max; | 68 | _yValueMax = (int)max; |
| 69 | - | 69 | + |
| 70 | if (_yValueMax == 0) { | 70 | if (_yValueMax == 0) { |
| 71 | _yValueMax = _yMinValue; | 71 | _yValueMax = _yMinValue; |
| 72 | } | 72 | } |
| @@ -97,7 +97,7 @@ | @@ -97,7 +97,7 @@ | ||
| 97 | int labelAddCount = 0; | 97 | int labelAddCount = 0; |
| 98 | for (int index = 0; index < _xLabels.count; index++) { | 98 | for (int index = 0; index < _xLabels.count; index++) { |
| 99 | labelAddCount += 1; | 99 | labelAddCount += 1; |
| 100 | - | 100 | + |
| 101 | if (labelAddCount == _xLabelSkip) { | 101 | if (labelAddCount == _xLabelSkip) { |
| 102 | NSString *labelText = [_xLabels[index] description]; | 102 | NSString *labelText = [_xLabels[index] description]; |
| 103 | PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectZero]; | 103 | PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectZero]; |
| @@ -107,24 +107,24 @@ | @@ -107,24 +107,24 @@ | ||
| 107 | label.text = labelText; | 107 | label.text = labelText; |
| 108 | [label sizeToFit]; | 108 | [label sizeToFit]; |
| 109 | CGFloat labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 ); | 109 | CGFloat labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 ); |
| 110 | - | 110 | + |
| 111 | label.center = CGPointMake(labelXPosition, | 111 | label.center = CGPointMake(labelXPosition, |
| 112 | self.frame.size.height - xLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop); | 112 | self.frame.size.height - xLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop); |
| 113 | labelAddCount = 0; | 113 | labelAddCount = 0; |
| 114 | - | 114 | + |
| 115 | [_labels addObject:label]; | 115 | [_labels addObject:label]; |
| 116 | [self addSubview:label]; | 116 | [self addSubview:label]; |
| 117 | } | 117 | } |
| 118 | } | 118 | } |
| 119 | - | 119 | + |
| 120 | //Add y labels | 120 | //Add y labels |
| 121 | - | 121 | + |
| 122 | float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - xLabelHeight) / _yLabelSum; | 122 | float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - xLabelHeight) / _yLabelSum; |
| 123 | - | 123 | + |
| 124 | for (int index = 0; index < _yLabelSum; index++) { | 124 | for (int index = 0; index < _yLabelSum; index++) { |
| 125 | 125 | ||
| 126 | NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum )); | 126 | NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum )); |
| 127 | - | 127 | + |
| 128 | PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0, | 128 | PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0, |
| 129 | yLabelSectionHeight * index + _chartMargin - yLabelHeight/2.0, | 129 | yLabelSectionHeight * index + _chartMargin - yLabelHeight/2.0, |
| 130 | _yChartLabelWidth, | 130 | _yChartLabelWidth, |
| @@ -139,11 +139,11 @@ | @@ -139,11 +139,11 @@ | ||
| 139 | 139 | ||
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | - | 142 | + |
| 143 | 143 | ||
| 144 | [self viewCleanupForCollection:_bars]; | 144 | [self viewCleanupForCollection:_bars]; |
| 145 | - | 145 | + |
| 146 | - | 146 | + |
| 147 | //Add bars | 147 | //Add bars |
| 148 | CGFloat chartCavanHeight = self.frame.size.height - _chartMargin * 2 - xLabelHeight; | 148 | CGFloat chartCavanHeight = self.frame.size.height - _chartMargin * 2 - xLabelHeight; |
| 149 | NSInteger index = 0; | 149 | NSInteger index = 0; |
| @@ -152,15 +152,15 @@ | @@ -152,15 +152,15 @@ | ||
| 152 | float value = [valueString floatValue]; | 152 | float value = [valueString floatValue]; |
| 153 | 153 | ||
| 154 | float grade = (float)value / (float)_yValueMax; | 154 | float grade = (float)value / (float)_yValueMax; |
| 155 | - | 155 | + |
| 156 | if (isnan(grade)) { | 156 | if (isnan(grade)) { |
| 157 | grade = 0; | 157 | grade = 0; |
| 158 | } | 158 | } |
| 159 | - | 159 | + |
| 160 | PNBar *bar; | 160 | PNBar *bar; |
| 161 | CGFloat barWidth; | 161 | CGFloat barWidth; |
| 162 | CGFloat barXPosition; | 162 | CGFloat barXPosition; |
| 163 | - | 163 | + |
| 164 | if (_barWidth) { | 164 | if (_barWidth) { |
| 165 | barWidth = _barWidth; | 165 | barWidth = _barWidth; |
| 166 | barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 - _barWidth /2.0; | 166 | barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 - _barWidth /2.0; |
| @@ -168,112 +168,112 @@ | @@ -168,112 +168,112 @@ | ||
| 168 | barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth * 0.25; | 168 | barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth * 0.25; |
| 169 | if (_showLabel) { | 169 | if (_showLabel) { |
| 170 | barWidth = _xLabelWidth * 0.5; | 170 | barWidth = _xLabelWidth * 0.5; |
| 171 | - | 171 | + |
| 172 | } | 172 | } |
| 173 | else { | 173 | else { |
| 174 | barWidth = _xLabelWidth * 0.6; | 174 | barWidth = _xLabelWidth * 0.6; |
| 175 | - | 175 | + |
| 176 | } | 176 | } |
| 177 | } | 177 | } |
| 178 | - | 178 | + |
| 179 | bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position | 179 | bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position |
| 180 | self.frame.size.height - chartCavanHeight - xLabelHeight - _chartMargin, //Bar Y position | 180 | self.frame.size.height - chartCavanHeight - xLabelHeight - _chartMargin, //Bar Y position |
| 181 | barWidth, // Bar witdh | 181 | barWidth, // Bar witdh |
| 182 | chartCavanHeight)]; //Bar height | 182 | chartCavanHeight)]; //Bar height |
| 183 | - | 183 | + |
| 184 | //Change Bar Radius | 184 | //Change Bar Radius |
| 185 | bar.barRadius = _barRadius; | 185 | bar.barRadius = _barRadius; |
| 186 | - | 186 | + |
| 187 | //Change Bar Background color | 187 | //Change Bar Background color |
| 188 | bar.backgroundColor = _barBackgroundColor; | 188 | bar.backgroundColor = _barBackgroundColor; |
| 189 | - | 189 | + |
| 190 | //Bar StrokColor First | 190 | //Bar StrokColor First |
| 191 | if (self.strokeColor) { | 191 | if (self.strokeColor) { |
| 192 | bar.barColor = self.strokeColor; | 192 | bar.barColor = self.strokeColor; |
| 193 | }else{ | 193 | }else{ |
| 194 | bar.barColor = [self barColorAtIndex:index]; | 194 | bar.barColor = [self barColorAtIndex:index]; |
| 195 | } | 195 | } |
| 196 | - | 196 | + |
| 197 | //Height Of Bar | 197 | //Height Of Bar |
| 198 | bar.grade = grade; | 198 | bar.grade = grade; |
| 199 | - | 199 | + |
| 200 | // Add gradient | 200 | // Add gradient |
| 201 | bar.barColorGradientStart = _barColorGradientStart; | 201 | bar.barColorGradientStart = _barColorGradientStart; |
| 202 | - | 202 | + |
| 203 | 203 | ||
| 204 | //For Click Index | 204 | //For Click Index |
| 205 | bar.tag = index; | 205 | bar.tag = index; |
| 206 | - | 206 | + |
| 207 | - | 207 | + |
| 208 | [_bars addObject:bar]; | 208 | [_bars addObject:bar]; |
| 209 | [self addSubview:bar]; | 209 | [self addSubview:bar]; |
| 210 | 210 | ||
| 211 | index += 1; | 211 | index += 1; |
| 212 | } | 212 | } |
| 213 | - | 213 | + |
| 214 | //Add chart border lines | 214 | //Add chart border lines |
| 215 | - | 215 | + |
| 216 | if (_showChartBorder) { | 216 | if (_showChartBorder) { |
| 217 | _chartBottomLine = [CAShapeLayer layer]; | 217 | _chartBottomLine = [CAShapeLayer layer]; |
| 218 | _chartBottomLine.lineCap = kCALineCapButt; | 218 | _chartBottomLine.lineCap = kCALineCapButt; |
| 219 | _chartBottomLine.fillColor = [[UIColor whiteColor] CGColor]; | 219 | _chartBottomLine.fillColor = [[UIColor whiteColor] CGColor]; |
| 220 | _chartBottomLine.lineWidth = 1.0; | 220 | _chartBottomLine.lineWidth = 1.0; |
| 221 | _chartBottomLine.strokeEnd = 0.0; | 221 | _chartBottomLine.strokeEnd = 0.0; |
| 222 | - | 222 | + |
| 223 | UIBezierPath *progressline = [UIBezierPath bezierPath]; | 223 | UIBezierPath *progressline = [UIBezierPath bezierPath]; |
| 224 | - | 224 | + |
| 225 | [progressline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)]; | 225 | [progressline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)]; |
| 226 | [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)]; | 226 | [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)]; |
| 227 | - | 227 | + |
| 228 | [progressline setLineWidth:1.0]; | 228 | [progressline setLineWidth:1.0]; |
| 229 | [progressline setLineCapStyle:kCGLineCapSquare]; | 229 | [progressline setLineCapStyle:kCGLineCapSquare]; |
| 230 | _chartBottomLine.path = progressline.CGPath; | 230 | _chartBottomLine.path = progressline.CGPath; |
| 231 | - | 231 | + |
| 232 | - | 232 | + |
| 233 | _chartBottomLine.strokeColor = PNLightGrey.CGColor; | 233 | _chartBottomLine.strokeColor = PNLightGrey.CGColor; |
| 234 | - | 234 | + |
| 235 | - | 235 | + |
| 236 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | 236 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; |
| 237 | pathAnimation.duration = 0.5; | 237 | pathAnimation.duration = 0.5; |
| 238 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | 238 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; |
| 239 | pathAnimation.fromValue = @0.0f; | 239 | pathAnimation.fromValue = @0.0f; |
| 240 | pathAnimation.toValue = @1.0f; | 240 | pathAnimation.toValue = @1.0f; |
| 241 | [_chartBottomLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 241 | [_chartBottomLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 242 | - | 242 | + |
| 243 | _chartBottomLine.strokeEnd = 1.0; | 243 | _chartBottomLine.strokeEnd = 1.0; |
| 244 | - | 244 | + |
| 245 | [self.layer addSublayer:_chartBottomLine]; | 245 | [self.layer addSublayer:_chartBottomLine]; |
| 246 | - | 246 | + |
| 247 | //Add left Chart Line | 247 | //Add left Chart Line |
| 248 | - | 248 | + |
| 249 | _chartLeftLine = [CAShapeLayer layer]; | 249 | _chartLeftLine = [CAShapeLayer layer]; |
| 250 | _chartLeftLine.lineCap = kCALineCapButt; | 250 | _chartLeftLine.lineCap = kCALineCapButt; |
| 251 | _chartLeftLine.fillColor = [[UIColor whiteColor] CGColor]; | 251 | _chartLeftLine.fillColor = [[UIColor whiteColor] CGColor]; |
| 252 | _chartLeftLine.lineWidth = 1.0; | 252 | _chartLeftLine.lineWidth = 1.0; |
| 253 | _chartLeftLine.strokeEnd = 0.0; | 253 | _chartLeftLine.strokeEnd = 0.0; |
| 254 | - | 254 | + |
| 255 | UIBezierPath *progressLeftline = [UIBezierPath bezierPath]; | 255 | UIBezierPath *progressLeftline = [UIBezierPath bezierPath]; |
| 256 | - | 256 | + |
| 257 | [progressLeftline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)]; | 257 | [progressLeftline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)]; |
| 258 | [progressLeftline addLineToPoint:CGPointMake(_chartMargin, _chartMargin)]; | 258 | [progressLeftline addLineToPoint:CGPointMake(_chartMargin, _chartMargin)]; |
| 259 | - | 259 | + |
| 260 | [progressLeftline setLineWidth:1.0]; | 260 | [progressLeftline setLineWidth:1.0]; |
| 261 | [progressLeftline setLineCapStyle:kCGLineCapSquare]; | 261 | [progressLeftline setLineCapStyle:kCGLineCapSquare]; |
| 262 | _chartLeftLine.path = progressLeftline.CGPath; | 262 | _chartLeftLine.path = progressLeftline.CGPath; |
| 263 | - | 263 | + |
| 264 | - | 264 | + |
| 265 | _chartLeftLine.strokeColor = PNLightGrey.CGColor; | 265 | _chartLeftLine.strokeColor = PNLightGrey.CGColor; |
| 266 | - | 266 | + |
| 267 | - | 267 | + |
| 268 | CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | 268 | CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; |
| 269 | pathLeftAnimation.duration = 0.5; | 269 | pathLeftAnimation.duration = 0.5; |
| 270 | pathLeftAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | 270 | pathLeftAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; |
| 271 | pathLeftAnimation.fromValue = @0.0f; | 271 | pathLeftAnimation.fromValue = @0.0f; |
| 272 | pathLeftAnimation.toValue = @1.0f; | 272 | pathLeftAnimation.toValue = @1.0f; |
| 273 | [_chartLeftLine addAnimation:pathLeftAnimation forKey:@"strokeEndAnimation"]; | 273 | [_chartLeftLine addAnimation:pathLeftAnimation forKey:@"strokeEndAnimation"]; |
| 274 | - | 274 | + |
| 275 | _chartLeftLine.strokeEnd = 1.0; | 275 | _chartLeftLine.strokeEnd = 1.0; |
| 276 | - | 276 | + |
| 277 | [self.layer addSublayer:_chartLeftLine]; | 277 | [self.layer addSublayer:_chartLeftLine]; |
| 278 | } | 278 | } |
| 279 | } | 279 | } |
| @@ -316,7 +316,7 @@ | @@ -316,7 +316,7 @@ | ||
| 316 | UITouch *touch = [touches anyObject]; | 316 | UITouch *touch = [touches anyObject]; |
| 317 | CGPoint touchPoint = [touch locationInView:self]; | 317 | CGPoint touchPoint = [touch locationInView:self]; |
| 318 | UIView *subview = [self hitTest:touchPoint withEvent:nil]; | 318 | UIView *subview = [self hitTest:touchPoint withEvent:nil]; |
| 319 | - | 319 | + |
| 320 | if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarAtIndex:)]) { | 320 | if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarAtIndex:)]) { |
| 321 | [self.delegate userClickedOnBarAtIndex:subview.tag]; | 321 | [self.delegate userClickedOnBarAtIndex:subview.tag]; |
| 322 | } | 322 | } |
| @@ -75,19 +75,19 @@ | @@ -75,19 +75,19 @@ | ||
| 75 | - (void)strokeChart | 75 | - (void)strokeChart |
| 76 | { | 76 | { |
| 77 | // Add counting label | 77 | // Add counting label |
| 78 | - | 78 | + |
| 79 | NSString *format; | 79 | NSString *format; |
| 80 | switch (self.chartType) { | 80 | switch (self.chartType) { |
| 81 | - case PNChartFormatTypePercent: | 81 | + case PNChartFormatTypePercent: |
| 82 | - format = @"%d%%"; | 82 | + format = @"%d%%"; |
| 83 | - break; | 83 | + break; |
| 84 | - case PNChartFormatTypeDollar: | 84 | + case PNChartFormatTypeDollar: |
| 85 | - format = @"$%d"; | 85 | + format = @"$%d"; |
| 86 | - break; | 86 | + break; |
| 87 | - case PNChartFormatTypeNone: | 87 | + case PNChartFormatTypeNone: |
| 88 | - default: | 88 | + default: |
| 89 | - format = @"%d"; | 89 | + format = @"%d"; |
| 90 | - break; | 90 | + break; |
| 91 | } | 91 | } |
| 92 | self.countingLabel.format = format; | 92 | self.countingLabel.format = format; |
| 93 | [self addSubview:self.countingLabel]; | 93 | [self addSubview:self.countingLabel]; |
| @@ -110,11 +110,11 @@ | @@ -110,11 +110,11 @@ | ||
| 110 | _circle.strokeEnd = [_current floatValue] / [_total floatValue]; | 110 | _circle.strokeEnd = [_current floatValue] / [_total floatValue]; |
| 111 | 111 | ||
| 112 | [_countingLabel countFrom:0 to:[_current floatValue] withDuration:1.0]; | 112 | [_countingLabel countFrom:0 to:[_current floatValue] withDuration:1.0]; |
| 113 | - | 113 | + |
| 114 | - | 114 | + |
| 115 | // Check if user wants to add a gradient from the start color to the bar color | 115 | // Check if user wants to add a gradient from the start color to the bar color |
| 116 | if (_strokeColorGradientStart) { | 116 | if (_strokeColorGradientStart) { |
| 117 | - | 117 | + |
| 118 | // Add gradient | 118 | // Add gradient |
| 119 | CAShapeLayer *gradientMask = [CAShapeLayer layer]; | 119 | CAShapeLayer *gradientMask = [CAShapeLayer layer]; |
| 120 | gradientMask.fillColor = [[UIColor clearColor] CGColor]; | 120 | gradientMask.fillColor = [[UIColor clearColor] CGColor]; |
| @@ -124,7 +124,7 @@ | @@ -124,7 +124,7 @@ | ||
| 124 | CGRect gradientFrame = CGRectMake(0, 0, 2*self.bounds.size.width, 2*self.bounds.size.height); | 124 | CGRect gradientFrame = CGRectMake(0, 0, 2*self.bounds.size.width, 2*self.bounds.size.height); |
| 125 | gradientMask.frame = gradientFrame; | 125 | gradientMask.frame = gradientFrame; |
| 126 | gradientMask.path = _circle.path; | 126 | gradientMask.path = _circle.path; |
| 127 | - | 127 | + |
| 128 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; | 128 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; |
| 129 | gradientLayer.startPoint = CGPointMake(0.5,1.0); | 129 | gradientLayer.startPoint = CGPointMake(0.5,1.0); |
| 130 | gradientLayer.endPoint = CGPointMake(0.5,0.0); | 130 | gradientLayer.endPoint = CGPointMake(0.5,0.0); |
| @@ -135,13 +135,13 @@ | @@ -135,13 +135,13 @@ | ||
| 135 | (id)_strokeColorGradientStart.CGColor | 135 | (id)_strokeColorGradientStart.CGColor |
| 136 | ]; | 136 | ]; |
| 137 | gradientLayer.colors = colors; | 137 | gradientLayer.colors = colors; |
| 138 | - | 138 | + |
| 139 | [gradientLayer setMask:gradientMask]; | 139 | [gradientLayer setMask:gradientMask]; |
| 140 | - | 140 | + |
| 141 | [_circle addSublayer:gradientLayer]; | 141 | [_circle addSublayer:gradientLayer]; |
| 142 | - | 142 | + |
| 143 | gradientMask.strokeEnd = [_current floatValue] / [_total floatValue]; | 143 | gradientMask.strokeEnd = [_current floatValue] / [_total floatValue]; |
| 144 | - | 144 | + |
| 145 | [gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 145 | [gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| @@ -151,7 +151,7 @@ | @@ -151,7 +151,7 @@ | ||
| 151 | - (void)growChartByAmount:(NSNumber *)growAmount | 151 | - (void)growChartByAmount:(NSNumber *)growAmount |
| 152 | { | 152 | { |
| 153 | NSNumber *updatedValue = [NSNumber numberWithFloat:[_current floatValue] + [growAmount floatValue]]; | 153 | NSNumber *updatedValue = [NSNumber numberWithFloat:[_current floatValue] + [growAmount floatValue]]; |
| 154 | - | 154 | + |
| 155 | // Add animation | 155 | // Add animation |
| 156 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | 156 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; |
| 157 | pathAnimation.duration = self.duration; | 157 | pathAnimation.duration = self.duration; |
| @@ -160,7 +160,7 @@ | @@ -160,7 +160,7 @@ | ||
| 160 | pathAnimation.toValue = @([updatedValue floatValue] / [_total floatValue]); | 160 | pathAnimation.toValue = @([updatedValue floatValue] / [_total floatValue]); |
| 161 | _circle.strokeEnd = [updatedValue floatValue] / [_total floatValue]; | 161 | _circle.strokeEnd = [updatedValue floatValue] / [_total floatValue]; |
| 162 | [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 162 | [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 163 | - | 163 | + |
| 164 | [self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([_current floatValue] + [growAmount floatValue], [_total floatValue]) withDuration:self.duration]; | 164 | [self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([_current floatValue] + [growAmount floatValue], [_total floatValue]) withDuration:self.duration]; |
| 165 | _current = updatedValue; | 165 | _current = updatedValue; |
| 166 | } | 166 | } |
| @@ -20,6 +20,7 @@ | @@ -20,6 +20,7 @@ | ||
| 20 | CGContextFillRect(context, rect); | 20 | CGContextFillRect(context, rect); |
| 21 | UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | 21 | UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); |
| 22 | UIGraphicsEndImageContext(); | 22 | UIGraphicsEndImageContext(); |
| 23 | + | ||
| 23 | return img; | 24 | return img; |
| 24 | } | 25 | } |
| 25 | 26 |
| @@ -20,7 +20,6 @@ | @@ -20,7 +20,6 @@ | ||
| 20 | @property (nonatomic, retain) id<PNChartDelegate> delegate; | 20 | @property (nonatomic, retain) id<PNChartDelegate> delegate; |
| 21 | 21 | ||
| 22 | @property (nonatomic) NSArray *xLabels; | 22 | @property (nonatomic) NSArray *xLabels; |
| 23 | - | ||
| 24 | @property (nonatomic) NSArray *yLabels; | 23 | @property (nonatomic) NSArray *yLabels; |
| 25 | 24 | ||
| 26 | /** | 25 | /** |
| @@ -29,31 +28,18 @@ | @@ -29,31 +28,18 @@ | ||
| 29 | @property (nonatomic) NSArray *chartData; | 28 | @property (nonatomic) NSArray *chartData; |
| 30 | 29 | ||
| 31 | @property (nonatomic) NSMutableArray *pathPoints; | 30 | @property (nonatomic) NSMutableArray *pathPoints; |
| 32 | - | ||
| 33 | @property (nonatomic) CGFloat xLabelWidth; | 31 | @property (nonatomic) CGFloat xLabelWidth; |
| 34 | - | ||
| 35 | @property (nonatomic) UIFont *xLabelFont; | 32 | @property (nonatomic) UIFont *xLabelFont; |
| 36 | - | ||
| 37 | @property (nonatomic) UIColor *xLabelColor; | 33 | @property (nonatomic) UIColor *xLabelColor; |
| 38 | - | ||
| 39 | @property (nonatomic) CGFloat yValueMax; | 34 | @property (nonatomic) CGFloat yValueMax; |
| 40 | - | ||
| 41 | @property (nonatomic) CGFloat yValueMin; | 35 | @property (nonatomic) CGFloat yValueMin; |
| 42 | - | ||
| 43 | @property (nonatomic) NSInteger yLabelNum; | 36 | @property (nonatomic) NSInteger yLabelNum; |
| 44 | - | ||
| 45 | @property (nonatomic) CGFloat yLabelHeight; | 37 | @property (nonatomic) CGFloat yLabelHeight; |
| 46 | - | ||
| 47 | @property (nonatomic) UIFont *yLabelFont; | 38 | @property (nonatomic) UIFont *yLabelFont; |
| 48 | - | ||
| 49 | @property (nonatomic) UIColor *yLabelColor; | 39 | @property (nonatomic) UIColor *yLabelColor; |
| 50 | - | ||
| 51 | @property (nonatomic) CGFloat chartCavanHeight; | 40 | @property (nonatomic) CGFloat chartCavanHeight; |
| 52 | - | ||
| 53 | @property (nonatomic) CGFloat chartCavanWidth; | 41 | @property (nonatomic) CGFloat chartCavanWidth; |
| 54 | - | ||
| 55 | @property (nonatomic) CGFloat chartMargin; | 42 | @property (nonatomic) CGFloat chartMargin; |
| 56 | - | ||
| 57 | @property (nonatomic) BOOL showLabel; | 43 | @property (nonatomic) BOOL showLabel; |
| 58 | 44 | ||
| 59 | /** | 45 | /** |
| @@ -6,7 +6,6 @@ | @@ -6,7 +6,6 @@ | ||
| 6 | #import <Foundation/Foundation.h> | 6 | #import <Foundation/Foundation.h> |
| 7 | 7 | ||
| 8 | typedef NS_ENUM(NSUInteger, PNLineChartPointStyle) { | 8 | typedef NS_ENUM(NSUInteger, PNLineChartPointStyle) { |
| 9 | - | ||
| 10 | PNLineChartPointStyleNone = 0, | 9 | PNLineChartPointStyleNone = 0, |
| 11 | PNLineChartPointStyleCircle = 1, | 10 | PNLineChartPointStyleCircle = 1, |
| 12 | PNLineChartPointStyleSquare = 3 | 11 | PNLineChartPointStyleSquare = 3 |
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | 21 | ||
| 22 | + (instancetype)dataItemWithValue:(CGFloat)value | 22 | + (instancetype)dataItemWithValue:(CGFloat)value |
| 23 | color:(UIColor*)color | 23 | color:(UIColor*)color |
| 24 | - description:(NSString *)description{ | 24 | + description:(NSString *)description { |
| 25 | PNPieChartDataItem *item = [PNPieChartDataItem dataItemWithValue:value color:color]; | 25 | PNPieChartDataItem *item = [PNPieChartDataItem dataItemWithValue:value color:color]; |
| 26 | item.textDescription = description; | 26 | item.textDescription = description; |
| 27 | return item; | 27 | return item; |
| @@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
| 15 | // Override point for customization after application launch. | 15 | // Override point for customization after application launch. |
| 16 | return YES; | 16 | return YES; |
| 17 | } | 17 | } |
| 18 | - | 18 | + |
| 19 | - (void)applicationWillResignActive:(UIApplication *)application | 19 | - (void)applicationWillResignActive:(UIApplication *)application |
| 20 | { | 20 | { |
| 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. |
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | 24 | ||
| 25 | - (void)applicationDidEnterBackground:(UIApplication *)application | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application |
| 26 | { | 26 | { |
| 27 | - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | 27 | + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. |
| 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. |
| 29 | } | 29 | } |
| 30 | 30 |
-
Please register or login to post a comment