Merge pull request #145 from JunsionGu/master
Fix little issue in PNLineChart.m
Showing
1 changed file
with
22 additions
and
8 deletions
| @@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
| 19 | 19 | ||
| 20 | @property (nonatomic) NSMutableArray *chartPath; // Array of line path, one for each line. | 20 | @property (nonatomic) NSMutableArray *chartPath; // Array of line path, one for each line. |
| 21 | @property (nonatomic) NSMutableArray *pointPath; // Array of point path, one for each line | 21 | @property (nonatomic) NSMutableArray *pointPath; // Array of point path, one for each line |
| 22 | - | 22 | +@property (nonatomic) NSMutableArray *endPointsOfPath; // Array of start and end points of each line path, one for each line |
| 23 | @end | 23 | @end |
| 24 | 24 | ||
| 25 | @implementation PNLineChart | 25 | @implementation PNLineChart |
| @@ -189,9 +189,9 @@ | @@ -189,9 +189,9 @@ | ||
| 189 | CGPoint touchPoint = [touch locationInView:self]; | 189 | CGPoint touchPoint = [touch locationInView:self]; |
| 190 | 190 | ||
| 191 | for (NSInteger p = _pathPoints.count - 1; p >= 0; p--) { | 191 | for (NSInteger p = _pathPoints.count - 1; p >= 0; p--) { |
| 192 | - NSArray *linePointsArray = _pathPoints[p]; | 192 | + NSArray *linePointsArray = _endPointsOfPath[p]; |
| 193 | 193 | ||
| 194 | - for (int i = 0; i < linePointsArray.count - 1; i += 1) { | 194 | + for (int i = 0; i < linePointsArray.count - 1; i += 2) { |
| 195 | CGPoint p1 = [linePointsArray[i] CGPointValue]; | 195 | CGPoint p1 = [linePointsArray[i] CGPointValue]; |
| 196 | CGPoint p2 = [linePointsArray[i + 1] CGPointValue]; | 196 | CGPoint p2 = [linePointsArray[i + 1] CGPointValue]; |
| 197 | 197 | ||
| @@ -251,7 +251,7 @@ | @@ -251,7 +251,7 @@ | ||
| 251 | _chartPath = [[NSMutableArray alloc] init]; | 251 | _chartPath = [[NSMutableArray alloc] init]; |
| 252 | _pointPath = [[NSMutableArray alloc] init]; | 252 | _pointPath = [[NSMutableArray alloc] init]; |
| 253 | 253 | ||
| 254 | - [self calculateChartPath:_chartPath andPointsPath:_pointPath andPathKeyPoints:_pathPoints]; | 254 | + [self calculateChartPath:_chartPath andPointsPath:_pointPath andPathKeyPoints:_pathPoints andPathStartEndPoints:_endPointsOfPath]; |
| 255 | // Draw each line | 255 | // Draw each line |
| 256 | for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) { | 256 | for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) { |
| 257 | PNLineChartData *chartData = self.chartData[lineIndex]; | 257 | PNLineChartData *chartData = self.chartData[lineIndex]; |
| @@ -294,7 +294,7 @@ | @@ -294,7 +294,7 @@ | ||
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | 296 | ||
| 297 | -- (void)calculateChartPath:(NSMutableArray *)chartPath andPointsPath:(NSMutableArray *)pointsPath andPathKeyPoints:(NSMutableArray *)pathPoints | 297 | +- (void)calculateChartPath:(NSMutableArray *)chartPath andPointsPath:(NSMutableArray *)pointsPath andPathKeyPoints:(NSMutableArray *)pathPoints andPathStartEndPoints:(NSMutableArray *)pointsOfPath |
| 298 | { | 298 | { |
| 299 | 299 | ||
| 300 | // Draw each line | 300 | // Draw each line |
| @@ -320,7 +320,7 @@ | @@ -320,7 +320,7 @@ | ||
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | NSMutableArray *linePointsArray = [[NSMutableArray alloc] init]; | 322 | NSMutableArray *linePointsArray = [[NSMutableArray alloc] init]; |
| 323 | - | 323 | + NSMutableArray *lineStartEndPointsArray = [[NSMutableArray alloc] init]; |
| 324 | int last_x = 0; | 324 | int last_x = 0; |
| 325 | int last_y = 0; | 325 | int last_y = 0; |
| 326 | CGFloat inflexionWidth = chartData.inflexionPointWidth; | 326 | CGFloat inflexionWidth = chartData.inflexionPointWidth; |
| @@ -360,6 +360,9 @@ | @@ -360,6 +360,9 @@ | ||
| 360 | 360 | ||
| 361 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; | 361 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; |
| 362 | [progressline addLineToPoint:CGPointMake(x1, y1)]; | 362 | [progressline addLineToPoint:CGPointMake(x1, y1)]; |
| 363 | + | ||
| 364 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(last_x1, last_y1)]]; | ||
| 365 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x1, y1)]]; | ||
| 363 | } | 366 | } |
| 364 | 367 | ||
| 365 | last_x = x; | 368 | last_x = x; |
| @@ -388,6 +391,9 @@ | @@ -388,6 +391,9 @@ | ||
| 388 | 391 | ||
| 389 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; | 392 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; |
| 390 | [progressline addLineToPoint:CGPointMake(x1, y1)]; | 393 | [progressline addLineToPoint:CGPointMake(x1, y1)]; |
| 394 | + | ||
| 395 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(last_x1, last_y1)]]; | ||
| 396 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x1, y1)]]; | ||
| 391 | } | 397 | } |
| 392 | 398 | ||
| 393 | last_x = x; | 399 | last_x = x; |
| @@ -417,6 +423,9 @@ | @@ -417,6 +423,9 @@ | ||
| 417 | 423 | ||
| 418 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; | 424 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; |
| 419 | [progressline addLineToPoint:CGPointMake(x1, y1)]; | 425 | [progressline addLineToPoint:CGPointMake(x1, y1)]; |
| 426 | + | ||
| 427 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(last_x1, last_y1)]]; | ||
| 428 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x1, y1)]]; | ||
| 420 | } | 429 | } |
| 421 | 430 | ||
| 422 | last_x = x; | 431 | last_x = x; |
| @@ -426,16 +435,20 @@ | @@ -426,16 +435,20 @@ | ||
| 426 | 435 | ||
| 427 | if ( i != 0 ) { | 436 | if ( i != 0 ) { |
| 428 | [progressline addLineToPoint:CGPointMake(x, y)]; | 437 | [progressline addLineToPoint:CGPointMake(x, y)]; |
| 438 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; | ||
| 429 | } | 439 | } |
| 430 | 440 | ||
| 431 | [progressline moveToPoint:CGPointMake(x, y)]; | 441 | [progressline moveToPoint:CGPointMake(x, y)]; |
| 442 | + if(i != chartData.itemCount - 1){ | ||
| 443 | + [lineStartEndPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; | ||
| 444 | + } | ||
| 432 | } | 445 | } |
| 433 | 446 | ||
| 434 | [linePointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; | 447 | [linePointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; |
| 435 | } | 448 | } |
| 436 | 449 | ||
| 437 | [pathPoints addObject:[linePointsArray copy]]; | 450 | [pathPoints addObject:[linePointsArray copy]]; |
| 438 | - | 451 | + [pointsOfPath addObject:[lineStartEndPointsArray copy]]; |
| 439 | } | 452 | } |
| 440 | } | 453 | } |
| 441 | 454 | ||
| @@ -530,7 +543,7 @@ | @@ -530,7 +543,7 @@ | ||
| 530 | 543 | ||
| 531 | [self prepareYLabelsWithData:data]; | 544 | [self prepareYLabelsWithData:data]; |
| 532 | 545 | ||
| 533 | - [self calculateChartPath:_chartPath andPointsPath:_pointPath andPathKeyPoints:_pathPoints]; | 546 | + [self calculateChartPath:_chartPath andPointsPath:_pointPath andPathKeyPoints:_pathPoints andPathStartEndPoints:_endPointsOfPath]; |
| 534 | 547 | ||
| 535 | for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) { | 548 | for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) { |
| 536 | 549 | ||
| @@ -652,6 +665,7 @@ | @@ -652,6 +665,7 @@ | ||
| 652 | self.chartLineArray = [NSMutableArray new]; | 665 | self.chartLineArray = [NSMutableArray new]; |
| 653 | _showLabel = YES; | 666 | _showLabel = YES; |
| 654 | _pathPoints = [[NSMutableArray alloc] init]; | 667 | _pathPoints = [[NSMutableArray alloc] init]; |
| 668 | + _endPointsOfPath = [[NSMutableArray alloc] init]; | ||
| 655 | self.userInteractionEnabled = YES; | 669 | self.userInteractionEnabled = YES; |
| 656 | 670 | ||
| 657 | _yLabelNum = 5.0; | 671 | _yLabelNum = 5.0; |
-
Please register or login to post a comment