Merge pull request #63 from jackyzonewen/master
Add axis separator
Showing
1 changed file
with
37 additions
and
10 deletions
| @@ -331,7 +331,8 @@ | @@ -331,7 +331,8 @@ | ||
| 331 | [chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 331 | [chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 332 | chartLine.strokeEnd = 1.0; | 332 | chartLine.strokeEnd = 1.0; |
| 333 | 333 | ||
| 334 | - if (chartData.inflexionPointStyle == PNLineChartPointStyleCycle) { | 334 | + // if you want cancel the point animation, conment this code, the point will show immediately |
| 335 | + if (chartData.inflexionPointStyle != PNLineChartPointStyleNone) { | ||
| 335 | [pointLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 336 | [pointLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 336 | } | 337 | } |
| 337 | 338 | ||
| @@ -424,29 +425,55 @@ | @@ -424,29 +425,55 @@ | ||
| 424 | { | 425 | { |
| 425 | if (self.isShowCoordinateAxis) { | 426 | if (self.isShowCoordinateAxis) { |
| 426 | 427 | ||
| 428 | + CGFloat yAsixOffset = 10.f; | ||
| 429 | + | ||
| 427 | CGContextRef ctx = UIGraphicsGetCurrentContext(); | 430 | CGContextRef ctx = UIGraphicsGetCurrentContext(); |
| 428 | UIGraphicsPushContext(ctx); | 431 | UIGraphicsPushContext(ctx); |
| 429 | CGContextSetLineWidth(ctx, self.axisWidth); | 432 | CGContextSetLineWidth(ctx, self.axisWidth); |
| 430 | CGContextSetStrokeColorWithColor(ctx, [self.axisColor CGColor]); | 433 | CGContextSetStrokeColorWithColor(ctx, [self.axisColor CGColor]); |
| 431 | 434 | ||
| 435 | + CGFloat xAxisWidth = CGRectGetWidth(rect) - _chartMargin/2; | ||
| 436 | + CGFloat yAxisHeight = _chartMargin + _chartCavanHeight; | ||
| 437 | + | ||
| 432 | // draw coordinate axis | 438 | // draw coordinate axis |
| 433 | - CGContextMoveToPoint(ctx, _chartMargin + 10, 0); | 439 | + CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset, 0); |
| 434 | - CGContextAddLineToPoint(ctx, _chartMargin + 10, _chartMargin + _chartCavanHeight); | 440 | + CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, yAxisHeight); |
| 435 | - CGContextAddLineToPoint(ctx, CGRectGetWidth(rect) - _chartMargin, _chartMargin + _chartCavanHeight); | 441 | + CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); |
| 436 | CGContextStrokePath(ctx); | 442 | CGContextStrokePath(ctx); |
| 437 | 443 | ||
| 438 | // draw y axis arrow | 444 | // draw y axis arrow |
| 439 | - CGContextMoveToPoint(ctx, _chartMargin + 6, 8); | 445 | + CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset - 3, 6); |
| 440 | - CGContextAddLineToPoint(ctx, _chartMargin + 10, 0); | 446 | + CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, 0); |
| 441 | - CGContextAddLineToPoint(ctx, _chartMargin + 14, 8); | 447 | + CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset + 3, 6); |
| 442 | CGContextStrokePath(ctx); | 448 | CGContextStrokePath(ctx); |
| 443 | 449 | ||
| 444 | // draw x axis arrow | 450 | // draw x axis arrow |
| 445 | - CGContextMoveToPoint(ctx, CGRectGetWidth(rect) - _chartMargin - 8, _chartMargin + _chartCavanHeight - 4); | 451 | + CGContextMoveToPoint(ctx, xAxisWidth - 6, yAxisHeight - 3); |
| 446 | - CGContextAddLineToPoint(ctx, CGRectGetWidth(rect) - _chartMargin, _chartMargin + _chartCavanHeight); | 452 | + CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); |
| 447 | - CGContextAddLineToPoint(ctx, CGRectGetWidth(rect) - _chartMargin - 8, _chartMargin + _chartCavanHeight + 4); | 453 | + CGContextAddLineToPoint(ctx, xAxisWidth - 6, yAxisHeight + 3); |
| 448 | CGContextStrokePath(ctx); | 454 | CGContextStrokePath(ctx); |
| 449 | 455 | ||
| 456 | + if (self.showLabel) { | ||
| 457 | + | ||
| 458 | + // draw x axis separator | ||
| 459 | + CGPoint point; | ||
| 460 | + for (NSUInteger i = 0; i < [self.xLabels count]; i++) { | ||
| 461 | + point = CGPointMake(2 * _chartMargin + (i * _xLabelWidth), _chartMargin + _chartCavanHeight); | ||
| 462 | + CGContextMoveToPoint(ctx, point.x, point.y - 2); | ||
| 463 | + CGContextAddLineToPoint(ctx, point.x, point.y); | ||
| 464 | + CGContextStrokePath(ctx); | ||
| 465 | + } | ||
| 466 | + | ||
| 467 | + // draw y axis separator | ||
| 468 | + CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; | ||
| 469 | + for (NSUInteger i = 0; i < [self.xLabels count]; i++) { | ||
| 470 | + point = CGPointMake(_chartMargin + yAsixOffset, (_chartCavanHeight - i * yStepHeight + _yLabelHeight/2)); | ||
| 471 | + CGContextMoveToPoint(ctx, point.x, point.y); | ||
| 472 | + CGContextAddLineToPoint(ctx, point.x + 2, point.y); | ||
| 473 | + CGContextStrokePath(ctx); | ||
| 474 | + } | ||
| 475 | + } | ||
| 476 | + | ||
| 450 | UIFont *font = [UIFont systemFontOfSize:11]; | 477 | UIFont *font = [UIFont systemFontOfSize:11]; |
| 451 | // draw y unit | 478 | // draw y unit |
| 452 | if ([self.yUnit length]) { | 479 | if ([self.yUnit length]) { |
-
Please register or login to post a comment