Merge pull request #90 from klauslanza/master
Fix Y labels and graph position when all Y values are the same
Showing
1 changed file
with
68 additions
and
53 deletions
| @@ -66,16 +66,28 @@ | @@ -66,16 +66,28 @@ | ||
| 66 | { | 66 | { |
| 67 | CGFloat yStep = (_yValueMax - _yValueMin) / _yLabelNum; | 67 | CGFloat yStep = (_yValueMax - _yValueMin) / _yLabelNum; |
| 68 | CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; | 68 | CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; |
| 69 | + NSString *yLabelFormat = self.yLabelFormat ?: @"%1.f"; | ||
| 69 | 70 | ||
| 70 | - if (_showLabel) { | 71 | + if (yStep == 0.0) { |
| 72 | + PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight, _chartMargin, _yLabelHeight)]; | ||
| 73 | + minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; | ||
| 74 | + [self addSubview:minLabel]; | ||
| 75 | + | ||
| 76 | + PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight/2, _chartMargin, _yLabelHeight)]; | ||
| 77 | + midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax]; | ||
| 78 | + [self addSubview:midLabel]; | ||
| 71 | 79 | ||
| 80 | + PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _chartMargin, _yLabelHeight)]; | ||
| 81 | + maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2]; | ||
| 82 | + [self addSubview:maxLabel]; | ||
| 83 | + | ||
| 84 | + } else { | ||
| 72 | NSInteger index = 0; | 85 | NSInteger index = 0; |
| 73 | NSInteger num = _yLabelNum + 1; | 86 | NSInteger num = _yLabelNum + 1; |
| 74 | 87 | ||
| 75 | while (num > 0) { | 88 | while (num > 0) { |
| 76 | PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (_chartCavanHeight - index * yStepHeight), _chartMargin, _yLabelHeight)]; | 89 | PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (_chartCavanHeight - index * yStepHeight), _chartMargin, _yLabelHeight)]; |
| 77 | [label setTextAlignment:NSTextAlignmentRight]; | 90 | [label setTextAlignment:NSTextAlignmentRight]; |
| 78 | - NSString *yLabelFormat = self.yLabelFormat ? self.yLabelFormat : @"%1.f"; | ||
| 79 | label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)]; | 91 | label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)]; |
| 80 | [self addSubview:label]; | 92 | [self addSubview:label]; |
| 81 | index += 1; | 93 | index += 1; |
| @@ -193,20 +205,20 @@ | @@ -193,20 +205,20 @@ | ||
| 193 | PNLineChartData *chartData = self.chartData[lineIndex]; | 205 | PNLineChartData *chartData = self.chartData[lineIndex]; |
| 194 | CAShapeLayer *chartLine = (CAShapeLayer *)self.chartLineArray[lineIndex]; | 206 | CAShapeLayer *chartLine = (CAShapeLayer *)self.chartLineArray[lineIndex]; |
| 195 | CAShapeLayer *pointLayer = (CAShapeLayer *)self.chartPointArray[lineIndex]; | 207 | CAShapeLayer *pointLayer = (CAShapeLayer *)self.chartPointArray[lineIndex]; |
| 196 | - | 208 | + |
| 197 | CGFloat yValue; | 209 | CGFloat yValue; |
| 198 | CGFloat innerGrade; | 210 | CGFloat innerGrade; |
| 199 | 211 | ||
| 200 | UIGraphicsBeginImageContext(self.frame.size); | 212 | UIGraphicsBeginImageContext(self.frame.size); |
| 201 | - | 213 | + |
| 202 | UIBezierPath *progressline = [UIBezierPath bezierPath]; | 214 | UIBezierPath *progressline = [UIBezierPath bezierPath]; |
| 203 | [progressline setLineWidth:chartData.lineWidth]; | 215 | [progressline setLineWidth:chartData.lineWidth]; |
| 204 | [progressline setLineCapStyle:kCGLineCapRound]; | 216 | [progressline setLineCapStyle:kCGLineCapRound]; |
| 205 | [progressline setLineJoinStyle:kCGLineJoinRound]; | 217 | [progressline setLineJoinStyle:kCGLineJoinRound]; |
| 206 | - | 218 | + |
| 207 | UIBezierPath *pointPath = [UIBezierPath bezierPath]; | 219 | UIBezierPath *pointPath = [UIBezierPath bezierPath]; |
| 208 | [pointPath setLineWidth:chartData.lineWidth]; | 220 | [pointPath setLineWidth:chartData.lineWidth]; |
| 209 | - | 221 | + |
| 210 | [_chartPath addObject:progressline]; | 222 | [_chartPath addObject:progressline]; |
| 211 | [_pointPath addObject:pointPath]; | 223 | [_pointPath addObject:pointPath]; |
| 212 | 224 | ||
| @@ -222,86 +234,90 @@ | @@ -222,86 +234,90 @@ | ||
| 222 | int last_x = 0; | 234 | int last_x = 0; |
| 223 | int last_y = 0; | 235 | int last_y = 0; |
| 224 | CGFloat inflexionWidth = chartData.inflexionPointWidth; | 236 | CGFloat inflexionWidth = chartData.inflexionPointWidth; |
| 225 | - | 237 | + |
| 226 | for (NSUInteger i = 0; i < chartData.itemCount; i++) { | 238 | for (NSUInteger i = 0; i < chartData.itemCount; i++) { |
| 227 | - | 239 | + |
| 228 | yValue = chartData.getData(i).y; | 240 | yValue = chartData.getData(i).y; |
| 229 | 241 | ||
| 230 | - innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin); | 242 | + if (!(_yValueMax - _yValueMin)) { |
| 231 | - | 243 | + innerGrade = 0.5; |
| 244 | + } else { | ||
| 245 | + innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin); | ||
| 246 | + } | ||
| 247 | + | ||
| 232 | int x = 2 * _chartMargin + (i * _xLabelWidth); | 248 | int x = 2 * _chartMargin + (i * _xLabelWidth); |
| 233 | int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2); | 249 | int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2); |
| 234 | - | 250 | + |
| 235 | // cycle style point | 251 | // cycle style point |
| 236 | if (chartData.inflexionPointStyle == PNLineChartPointStyleCycle) { | 252 | if (chartData.inflexionPointStyle == PNLineChartPointStyleCycle) { |
| 237 | - | 253 | + |
| 238 | CGRect circleRect = CGRectMake(x-inflexionWidth/2, y-inflexionWidth/2, inflexionWidth,inflexionWidth); | 254 | CGRect circleRect = CGRectMake(x-inflexionWidth/2, y-inflexionWidth/2, inflexionWidth,inflexionWidth); |
| 239 | CGPoint circleCenter = CGPointMake(circleRect.origin.x + (circleRect.size.width / 2), circleRect.origin.y + (circleRect.size.height / 2)); | 255 | CGPoint circleCenter = CGPointMake(circleRect.origin.x + (circleRect.size.width / 2), circleRect.origin.y + (circleRect.size.height / 2)); |
| 240 | - | 256 | + |
| 241 | [pointPath moveToPoint:CGPointMake(circleCenter.x + (inflexionWidth/2), circleCenter.y)]; | 257 | [pointPath moveToPoint:CGPointMake(circleCenter.x + (inflexionWidth/2), circleCenter.y)]; |
| 242 | [pointPath addArcWithCenter:circleCenter radius:inflexionWidth/2 startAngle:0 endAngle:2*M_PI clockwise:YES]; | 258 | [pointPath addArcWithCenter:circleCenter radius:inflexionWidth/2 startAngle:0 endAngle:2*M_PI clockwise:YES]; |
| 243 | - | 259 | + |
| 244 | if ( i != 0 ) { | 260 | if ( i != 0 ) { |
| 245 | - | 261 | + |
| 246 | // calculate the point for line | 262 | // calculate the point for line |
| 247 | float distance = sqrt( pow(x-last_x, 2) + pow(y-last_y,2) ); | 263 | float distance = sqrt( pow(x-last_x, 2) + pow(y-last_y,2) ); |
| 248 | float last_x1 = last_x + (inflexionWidth/2) / distance * (x-last_x); | 264 | float last_x1 = last_x + (inflexionWidth/2) / distance * (x-last_x); |
| 249 | float last_y1 = last_y + (inflexionWidth/2) / distance * (y-last_y); | 265 | float last_y1 = last_y + (inflexionWidth/2) / distance * (y-last_y); |
| 250 | float x1 = x - (inflexionWidth/2) / distance * (x-last_x); | 266 | float x1 = x - (inflexionWidth/2) / distance * (x-last_x); |
| 251 | float y1 = y - (inflexionWidth/2) / distance * (y-last_y); | 267 | float y1 = y - (inflexionWidth/2) / distance * (y-last_y); |
| 252 | - | 268 | + |
| 253 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; | 269 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; |
| 254 | [progressline addLineToPoint:CGPointMake(x1, y1)]; | 270 | [progressline addLineToPoint:CGPointMake(x1, y1)]; |
| 255 | } | 271 | } |
| 256 | - | 272 | + |
| 257 | last_x = x; | 273 | last_x = x; |
| 258 | last_y = y; | 274 | last_y = y; |
| 259 | } | 275 | } |
| 260 | // Square style point | 276 | // Square style point |
| 261 | else if (chartData.inflexionPointStyle == PNLineChartPointStyleSquare) { | 277 | else if (chartData.inflexionPointStyle == PNLineChartPointStyleSquare) { |
| 262 | - | 278 | + |
| 263 | CGRect squareRect = CGRectMake(x-inflexionWidth/2, y-inflexionWidth/2, inflexionWidth,inflexionWidth); | 279 | CGRect squareRect = CGRectMake(x-inflexionWidth/2, y-inflexionWidth/2, inflexionWidth,inflexionWidth); |
| 264 | CGPoint squareCenter = CGPointMake(squareRect.origin.x + (squareRect.size.width / 2), squareRect.origin.y + (squareRect.size.height / 2)); | 280 | CGPoint squareCenter = CGPointMake(squareRect.origin.x + (squareRect.size.width / 2), squareRect.origin.y + (squareRect.size.height / 2)); |
| 265 | - | 281 | + |
| 266 | [pointPath moveToPoint:CGPointMake(squareCenter.x - (inflexionWidth/2), squareCenter.y - (inflexionWidth/2))]; | 282 | [pointPath moveToPoint:CGPointMake(squareCenter.x - (inflexionWidth/2), squareCenter.y - (inflexionWidth/2))]; |
| 267 | [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth/2), squareCenter.y - (inflexionWidth/2))]; | 283 | [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth/2), squareCenter.y - (inflexionWidth/2))]; |
| 268 | [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth/2), squareCenter.y + (inflexionWidth/2))]; | 284 | [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth/2), squareCenter.y + (inflexionWidth/2))]; |
| 269 | [pointPath addLineToPoint:CGPointMake(squareCenter.x - (inflexionWidth/2), squareCenter.y + (inflexionWidth/2))]; | 285 | [pointPath addLineToPoint:CGPointMake(squareCenter.x - (inflexionWidth/2), squareCenter.y + (inflexionWidth/2))]; |
| 270 | [pointPath closePath]; | 286 | [pointPath closePath]; |
| 271 | - | 287 | + |
| 272 | if ( i != 0 ) { | 288 | if ( i != 0 ) { |
| 273 | - | 289 | + |
| 274 | // calculate the point for line | 290 | // calculate the point for line |
| 275 | float distance = sqrt( pow(x-last_x, 2) + pow(y-last_y,2) ); | 291 | float distance = sqrt( pow(x-last_x, 2) + pow(y-last_y,2) ); |
| 276 | float last_x1 = last_x + (inflexionWidth/2); | 292 | float last_x1 = last_x + (inflexionWidth/2); |
| 277 | float last_y1 = last_y + (inflexionWidth/2) / distance * (y-last_y); | 293 | float last_y1 = last_y + (inflexionWidth/2) / distance * (y-last_y); |
| 278 | float x1 = x - (inflexionWidth/2); | 294 | float x1 = x - (inflexionWidth/2); |
| 279 | float y1 = y - (inflexionWidth/2) / distance * (y-last_y); | 295 | float y1 = y - (inflexionWidth/2) / distance * (y-last_y); |
| 280 | - | 296 | + |
| 281 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; | 297 | [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; |
| 282 | [progressline addLineToPoint:CGPointMake(x1, y1)]; | 298 | [progressline addLineToPoint:CGPointMake(x1, y1)]; |
| 283 | } | 299 | } |
| 284 | - | 300 | + |
| 285 | last_x = x; | 301 | last_x = x; |
| 286 | last_y = y; | 302 | last_y = y; |
| 287 | } | 303 | } |
| 288 | // Triangle style point | 304 | // Triangle style point |
| 289 | else if (chartData.inflexionPointStyle == PNLineChartPointStyleTriangle) { | 305 | else if (chartData.inflexionPointStyle == PNLineChartPointStyleTriangle) { |
| 290 | - | 306 | + |
| 291 | if ( i != 0 ) { | 307 | if ( i != 0 ) { |
| 292 | [progressline addLineToPoint:CGPointMake(x, y)]; | 308 | [progressline addLineToPoint:CGPointMake(x, y)]; |
| 293 | } | 309 | } |
| 294 | - | 310 | + |
| 295 | [progressline moveToPoint:CGPointMake(x, y)]; | 311 | [progressline moveToPoint:CGPointMake(x, y)]; |
| 296 | } else { | 312 | } else { |
| 297 | - | 313 | + |
| 298 | if ( i != 0 ) { | 314 | if ( i != 0 ) { |
| 299 | [progressline addLineToPoint:CGPointMake(x, y)]; | 315 | [progressline addLineToPoint:CGPointMake(x, y)]; |
| 300 | } | 316 | } |
| 301 | - | 317 | + |
| 302 | [progressline moveToPoint:CGPointMake(x, y)]; | 318 | [progressline moveToPoint:CGPointMake(x, y)]; |
| 303 | } | 319 | } |
| 304 | - | 320 | + |
| 305 | [linePointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; | 321 | [linePointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; |
| 306 | } | 322 | } |
| 307 | 323 | ||
| @@ -310,7 +326,6 @@ | @@ -310,7 +326,6 @@ | ||
| 310 | // setup the color of the chart line | 326 | // setup the color of the chart line |
| 311 | if (chartData.color) { | 327 | if (chartData.color) { |
| 312 | chartLine.strokeColor = [chartData.color CGColor]; | 328 | chartLine.strokeColor = [chartData.color CGColor]; |
| 313 | - pointLayer.strokeColor = [chartData.color CGColor]; | ||
| 314 | } | 329 | } |
| 315 | else { | 330 | else { |
| 316 | chartLine.strokeColor = [PNGreen CGColor]; | 331 | chartLine.strokeColor = [PNGreen CGColor]; |
| @@ -321,8 +336,8 @@ | @@ -321,8 +336,8 @@ | ||
| 321 | 336 | ||
| 322 | chartLine.path = progressline.CGPath; | 337 | chartLine.path = progressline.CGPath; |
| 323 | pointLayer.path = pointPath.CGPath; | 338 | pointLayer.path = pointPath.CGPath; |
| 324 | - | 339 | + |
| 325 | - | 340 | + |
| 326 | [CATransaction begin]; | 341 | [CATransaction begin]; |
| 327 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | 342 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; |
| 328 | pathAnimation.duration = 1.0; | 343 | pathAnimation.duration = 1.0; |
| @@ -332,12 +347,12 @@ | @@ -332,12 +347,12 @@ | ||
| 332 | 347 | ||
| 333 | [chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 348 | [chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 334 | chartLine.strokeEnd = 1.0; | 349 | chartLine.strokeEnd = 1.0; |
| 335 | - | 350 | + |
| 336 | // if you want cancel the point animation, conment this code, the point will show immediately | 351 | // if you want cancel the point animation, conment this code, the point will show immediately |
| 337 | if (chartData.inflexionPointStyle != PNLineChartPointStyleNone) { | 352 | if (chartData.inflexionPointStyle != PNLineChartPointStyleNone) { |
| 338 | [pointLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 353 | [pointLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 339 | } | 354 | } |
| 340 | - | 355 | + |
| 341 | [CATransaction setCompletionBlock:^{ | 356 | [CATransaction setCompletionBlock:^{ |
| 342 | //pointLayer.strokeEnd = 1.0f; // stroken point when animation end | 357 | //pointLayer.strokeEnd = 1.0f; // stroken point when animation end |
| 343 | }]; | 358 | }]; |
| @@ -387,7 +402,7 @@ | @@ -387,7 +402,7 @@ | ||
| 387 | pointLayer.lineWidth = chartData.lineWidth; | 402 | pointLayer.lineWidth = chartData.lineWidth; |
| 388 | [self.layer addSublayer:pointLayer]; | 403 | [self.layer addSublayer:pointLayer]; |
| 389 | [self.chartPointArray addObject:pointLayer]; | 404 | [self.chartPointArray addObject:pointLayer]; |
| 390 | - | 405 | + |
| 391 | for (NSUInteger i = 0; i < chartData.itemCount; i++) { | 406 | for (NSUInteger i = 0; i < chartData.itemCount; i++) { |
| 392 | yValue = chartData.getData(i).y; | 407 | yValue = chartData.getData(i).y; |
| 393 | [yLabelsArray addObject:[NSString stringWithFormat:@"%2f", yValue]]; | 408 | [yLabelsArray addObject:[NSString stringWithFormat:@"%2f", yValue]]; |
| @@ -423,9 +438,9 @@ | @@ -423,9 +438,9 @@ | ||
| 423 | - (void)drawRect:(CGRect)rect | 438 | - (void)drawRect:(CGRect)rect |
| 424 | { | 439 | { |
| 425 | if (self.isShowCoordinateAxis) { | 440 | if (self.isShowCoordinateAxis) { |
| 426 | - | 441 | + |
| 427 | CGFloat yAsixOffset = 10.f; | 442 | CGFloat yAsixOffset = 10.f; |
| 428 | - | 443 | + |
| 429 | CGContextRef ctx = UIGraphicsGetCurrentContext(); | 444 | CGContextRef ctx = UIGraphicsGetCurrentContext(); |
| 430 | UIGraphicsPushContext(ctx); | 445 | UIGraphicsPushContext(ctx); |
| 431 | CGContextSetLineWidth(ctx, self.axisWidth); | 446 | CGContextSetLineWidth(ctx, self.axisWidth); |
| @@ -433,13 +448,13 @@ | @@ -433,13 +448,13 @@ | ||
| 433 | 448 | ||
| 434 | CGFloat xAxisWidth = CGRectGetWidth(rect) - _chartMargin/2; | 449 | CGFloat xAxisWidth = CGRectGetWidth(rect) - _chartMargin/2; |
| 435 | CGFloat yAxisHeight = _chartMargin + _chartCavanHeight; | 450 | CGFloat yAxisHeight = _chartMargin + _chartCavanHeight; |
| 436 | - | 451 | + |
| 437 | // draw coordinate axis | 452 | // draw coordinate axis |
| 438 | CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset, 0); | 453 | CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset, 0); |
| 439 | CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, yAxisHeight); | 454 | CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, yAxisHeight); |
| 440 | CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); | 455 | CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); |
| 441 | CGContextStrokePath(ctx); | 456 | CGContextStrokePath(ctx); |
| 442 | - | 457 | + |
| 443 | // draw y axis arrow | 458 | // draw y axis arrow |
| 444 | CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset - 3, 6); | 459 | CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset - 3, 6); |
| 445 | CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, 0); | 460 | CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, 0); |
| @@ -451,9 +466,9 @@ | @@ -451,9 +466,9 @@ | ||
| 451 | CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); | 466 | CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight); |
| 452 | CGContextAddLineToPoint(ctx, xAxisWidth - 6, yAxisHeight + 3); | 467 | CGContextAddLineToPoint(ctx, xAxisWidth - 6, yAxisHeight + 3); |
| 453 | CGContextStrokePath(ctx); | 468 | CGContextStrokePath(ctx); |
| 454 | - | 469 | + |
| 455 | if (self.showLabel) { | 470 | if (self.showLabel) { |
| 456 | - | 471 | + |
| 457 | // draw x axis separator | 472 | // draw x axis separator |
| 458 | CGPoint point; | 473 | CGPoint point; |
| 459 | for (NSUInteger i = 0; i < [self.xLabels count]; i++) { | 474 | for (NSUInteger i = 0; i < [self.xLabels count]; i++) { |
| @@ -462,7 +477,7 @@ | @@ -462,7 +477,7 @@ | ||
| 462 | CGContextAddLineToPoint(ctx, point.x, point.y); | 477 | CGContextAddLineToPoint(ctx, point.x, point.y); |
| 463 | CGContextStrokePath(ctx); | 478 | CGContextStrokePath(ctx); |
| 464 | } | 479 | } |
| 465 | - | 480 | + |
| 466 | // draw y axis separator | 481 | // draw y axis separator |
| 467 | CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; | 482 | CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; |
| 468 | for (NSUInteger i = 0; i < [self.xLabels count]; i++) { | 483 | for (NSUInteger i = 0; i < [self.xLabels count]; i++) { |
| @@ -472,7 +487,7 @@ | @@ -472,7 +487,7 @@ | ||
| 472 | CGContextStrokePath(ctx); | 487 | CGContextStrokePath(ctx); |
| 473 | } | 488 | } |
| 474 | } | 489 | } |
| 475 | - | 490 | + |
| 476 | UIFont *font = [UIFont systemFontOfSize:11]; | 491 | UIFont *font = [UIFont systemFontOfSize:11]; |
| 477 | // draw y unit | 492 | // draw y unit |
| 478 | if ([self.yUnit length]) { | 493 | if ([self.yUnit length]) { |
| @@ -488,7 +503,7 @@ | @@ -488,7 +503,7 @@ | ||
| 488 | [self drawTextInContext:ctx text:self.xUnit inRect:drawRect font:font]; | 503 | [self drawTextInContext:ctx text:self.xUnit inRect:drawRect font:font]; |
| 489 | } | 504 | } |
| 490 | } | 505 | } |
| 491 | - | 506 | + |
| 492 | [super drawRect:rect]; | 507 | [super drawRect:rect]; |
| 493 | } | 508 | } |
| 494 | 509 | ||
| @@ -511,7 +526,7 @@ | @@ -511,7 +526,7 @@ | ||
| 511 | 526 | ||
| 512 | _chartCavanWidth = self.frame.size.width - _chartMargin * 2; | 527 | _chartCavanWidth = self.frame.size.width - _chartMargin * 2; |
| 513 | _chartCavanHeight = self.frame.size.height - _chartMargin * 2; | 528 | _chartCavanHeight = self.frame.size.height - _chartMargin * 2; |
| 514 | - | 529 | + |
| 515 | // Coordinate Axis Default Values | 530 | // Coordinate Axis Default Values |
| 516 | _showCoordinateAxis = NO; | 531 | _showCoordinateAxis = NO; |
| 517 | _axisColor = [UIColor colorWithRed:0.4f green:0.4f blue:0.4f alpha:1.f]; | 532 | _axisColor = [UIColor colorWithRed:0.4f green:0.4f blue:0.4f alpha:1.f]; |
| @@ -525,22 +540,22 @@ | @@ -525,22 +540,22 @@ | ||
| 525 | NSInteger ch; | 540 | NSInteger ch; |
| 526 | CGSize size = CGSizeMake(width, MAXFLOAT); | 541 | CGSize size = CGSizeMake(width, MAXFLOAT); |
| 527 | if ([text respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) | 542 | if ([text respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) |
| 528 | - { | 543 | + { |
| 529 | NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil]; | 544 | NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil]; |
| 530 | size =[text boundingRectWithSize:size | 545 | size =[text boundingRectWithSize:size |
| 531 | options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading | 546 | options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading |
| 532 | attributes:tdic | 547 | attributes:tdic |
| 533 | context:nil].size; | 548 | context:nil].size; |
| 534 | - } | 549 | + } |
| 535 | else | 550 | else |
| 536 | - { | 551 | + { |
| 537 | #pragma clang diagnostic push | 552 | #pragma clang diagnostic push |
| 538 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 553 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 539 | size = [text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping]; | 554 | size = [text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping]; |
| 540 | #pragma clang diagnostic pop | 555 | #pragma clang diagnostic pop |
| 541 | - } | 556 | + } |
| 542 | ch = size.height; | 557 | ch = size.height; |
| 543 | - | 558 | + |
| 544 | return ch; | 559 | return ch; |
| 545 | } | 560 | } |
| 546 | 561 | ||
| @@ -550,16 +565,16 @@ | @@ -550,16 +565,16 @@ | ||
| 550 | NSMutableParagraphStyle *priceParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; | 565 | NSMutableParagraphStyle *priceParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; |
| 551 | priceParagraphStyle.lineBreakMode = NSLineBreakByTruncatingTail; | 566 | priceParagraphStyle.lineBreakMode = NSLineBreakByTruncatingTail; |
| 552 | priceParagraphStyle.alignment = NSTextAlignmentLeft; | 567 | priceParagraphStyle.alignment = NSTextAlignmentLeft; |
| 553 | - | 568 | + |
| 554 | [text drawInRect:rect | 569 | [text drawInRect:rect |
| 555 | withAttributes:@{NSParagraphStyleAttributeName:priceParagraphStyle, NSFontAttributeName:font}]; | 570 | withAttributes:@{NSParagraphStyleAttributeName:priceParagraphStyle, NSFontAttributeName:font}]; |
| 556 | } else { | 571 | } else { |
| 557 | #pragma clang diagnostic push | 572 | #pragma clang diagnostic push |
| 558 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 573 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 559 | [text drawInRect:rect | 574 | [text drawInRect:rect |
| 560 | - withFont:font | 575 | + withFont:font |
| 561 | - lineBreakMode:NSLineBreakByTruncatingTail | 576 | + lineBreakMode:NSLineBreakByTruncatingTail |
| 562 | - alignment:NSTextAlignmentLeft]; | 577 | + alignment:NSTextAlignmentLeft]; |
| 563 | #pragma clang diagnostic pop | 578 | #pragma clang diagnostic pop |
| 564 | } | 579 | } |
| 565 | } | 580 | } |
-
Please register or login to post a comment