Kevin

Merge pull request #95 from Antoine4011/custom-style

Label customization in PNLineChart
1 Pod::Spec.new do |s| 1 Pod::Spec.new do |s|
2 s.name = "PNChart" 2 s.name = "PNChart"
3 - s.version = "0.2.2" 3 + s.version = "0.6.0"
4 s.summary = "A simple and beautiful chart lib with animation used in Piner for iOS" 4 s.summary = "A simple and beautiful chart lib with animation used in Piner for iOS"
5 5
6 s.homepage = "https://github.com/kevinzhow/PNChart" 6 s.homepage = "https://github.com/kevinzhow/PNChart"
@@ -8,12 +8,12 @@ @@ -8,12 +8,12 @@
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 #import "PNColor.h" 10 #import "PNColor.h"
11 -#import "UICountingLabel.h" 11 +#import <UICountingLabel/UICountingLabel.h>
12 12
13 -typedef NS_ENUM(NSUInteger, PNChartFormatType) { 13 +typedef NS_ENUM (NSUInteger, PNChartFormatType) {
14 - PNChartFormatTypePercent, 14 + PNChartFormatTypePercent,
15 - PNChartFormatTypeDollar, 15 + PNChartFormatTypeDollar,
16 - PNChartFormatTypeNone 16 + PNChartFormatTypeNone
17 }; 17 };
18 18
19 #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) 19 #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
@@ -33,6 +33,10 @@ @@ -33,6 +33,10 @@
33 33
34 @property (nonatomic) CGFloat xLabelWidth; 34 @property (nonatomic) CGFloat xLabelWidth;
35 35
  36 +@property (nonatomic) UIFont *xLabelFont;
  37 +
  38 +@property (nonatomic) UIColor *xLabelColor;
  39 +
36 @property (nonatomic) CGFloat yValueMax; 40 @property (nonatomic) CGFloat yValueMax;
37 41
38 @property (nonatomic) CGFloat yValueMin; 42 @property (nonatomic) CGFloat yValueMin;
@@ -41,6 +45,10 @@ @@ -41,6 +45,10 @@
41 45
42 @property (nonatomic) CGFloat yLabelHeight; 46 @property (nonatomic) CGFloat yLabelHeight;
43 47
  48 +@property (nonatomic) UIFont *yLabelFont;
  49 +
  50 +@property (nonatomic) UIColor *yLabelColor;
  51 +
44 @property (nonatomic) CGFloat chartCavanHeight; 52 @property (nonatomic) CGFloat chartCavanHeight;
45 53
46 @property (nonatomic) CGFloat chartCavanWidth; 54 @property (nonatomic) CGFloat chartCavanWidth;
@@ -49,7 +57,6 @@ @@ -49,7 +57,6 @@
49 57
50 @property (nonatomic) BOOL showLabel; 58 @property (nonatomic) BOOL showLabel;
51 59
52 -  
53 /** 60 /**
54 * show CoordinateAxis ornot, Default is not 61 * show CoordinateAxis ornot, Default is not
55 */ 62 */
@@ -65,4 +72,6 @@ @@ -65,4 +72,6 @@
65 */ 72 */
66 @property (nonatomic, strong) NSString *yLabelFormat; 73 @property (nonatomic, strong) NSString *yLabelFormat;
67 74
  75 +- (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width;
  76 +
68 @end 77 @end
@@ -12,10 +12,9 @@ @@ -12,10 +12,9 @@
12 #import "PNLineChartData.h" 12 #import "PNLineChartData.h"
13 #import "PNLineChartDataItem.h" 13 #import "PNLineChartDataItem.h"
14 14
15 - 15 +// ------------------------------------------------------------------------------------------------
16 -//------------------------------------------------------------------------------------------------  
17 // private interface declaration 16 // private interface declaration
18 -//------------------------------------------------------------------------------------------------ 17 +// ------------------------------------------------------------------------------------------------
19 @interface PNLineChart () 18 @interface PNLineChart ()
20 19
21 @property (nonatomic) NSMutableArray *chartLineArray; // Array[CAShapeLayer] 20 @property (nonatomic) NSMutableArray *chartLineArray; // Array[CAShapeLayer]
@@ -28,10 +27,9 @@ @@ -28,10 +27,9 @@
28 27
29 @end 28 @end
30 29
31 - 30 +// ------------------------------------------------------------------------------------------------
32 -//------------------------------------------------------------------------------------------------  
33 // public interface implementation 31 // public interface implementation
34 -//------------------------------------------------------------------------------------------------ 32 +// ------------------------------------------------------------------------------------------------
35 @implementation PNLineChart 33 @implementation PNLineChart
36 34
37 #pragma mark initialization 35 #pragma mark initialization
@@ -47,7 +45,6 @@ @@ -47,7 +45,6 @@
47 return self; 45 return self;
48 } 46 }
49 47
50 -  
51 - (id)initWithFrame:(CGRect)frame 48 - (id)initWithFrame:(CGRect)frame
52 { 49 {
53 self = [super initWithFrame:frame]; 50 self = [super initWithFrame:frame];
@@ -59,36 +56,40 @@ @@ -59,36 +56,40 @@
59 return self; 56 return self;
60 } 57 }
61 58
62 -  
63 #pragma mark instance methods 59 #pragma mark instance methods
64 60
65 - (void)setYLabels:(NSArray *)yLabels 61 - (void)setYLabels:(NSArray *)yLabels
66 { 62 {
67 CGFloat yStep = (_yValueMax - _yValueMin) / _yLabelNum; 63 CGFloat yStep = (_yValueMax - _yValueMin) / _yLabelNum;
68 CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; 64 CGFloat yStepHeight = _chartCavanHeight / _yLabelNum;
69 - NSString *yLabelFormat = self.yLabelFormat ?: @"%1.f"; 65 + NSString *yLabelFormat = self.yLabelFormat ? : @"%1.f";
70 66
71 if (yStep == 0.0) { 67 if (yStep == 0.0) {
72 PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight, _chartMargin, _yLabelHeight)]; 68 PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight, _chartMargin, _yLabelHeight)];
73 minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; 69 minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0];
  70 + [self setCustomStyleForYLabel:minLabel];
74 [self addSubview:minLabel]; 71 [self addSubview:minLabel];
75 72
76 - PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight/2, _chartMargin, _yLabelHeight)]; 73 + PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight / 2, _chartMargin, _yLabelHeight)];
77 midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax]; 74 midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax];
  75 + [self setCustomStyleForYLabel:midLabel];
78 [self addSubview:midLabel]; 76 [self addSubview:midLabel];
79 77
80 PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _chartMargin, _yLabelHeight)]; 78 PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _chartMargin, _yLabelHeight)];
81 maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2]; 79 maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2];
  80 + [self setCustomStyleForYLabel:maxLabel];
82 [self addSubview:maxLabel]; 81 [self addSubview:maxLabel];
83 82
84 } else { 83 } else {
85 NSInteger index = 0; 84 NSInteger index = 0;
86 NSInteger num = _yLabelNum + 1; 85 NSInteger num = _yLabelNum + 1;
87 86
88 - while (num > 0) { 87 + while (num > 0)
  88 + {
89 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)];
90 [label setTextAlignment:NSTextAlignmentRight]; 90 [label setTextAlignment:NSTextAlignmentRight];
91 label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)]; 91 label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)];
  92 + [self setCustomStyleForYLabel:label];
92 [self addSubview:label]; 93 [self addSubview:label];
93 index += 1; 94 index += 1;
94 num -= 1; 95 num -= 1;
@@ -96,28 +97,63 @@ @@ -96,28 +97,63 @@
96 } 97 }
97 } 98 }
98 99
99 -  
100 - (void)setXLabels:(NSArray *)xLabels 100 - (void)setXLabels:(NSArray *)xLabels
101 { 101 {
  102 + CGFloat xLabelWidth;
  103 +
  104 + if (_showLabel) {
  105 + xLabelWidth = _chartCavanWidth / [xLabels count];
  106 + } else {
  107 + xLabelWidth = (self.frame.size.width) / [xLabels count];
  108 + }
  109 +
  110 + return [self setXLabels:xLabels withWidth:xLabelWidth];
  111 +}
  112 +
  113 +- (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width
  114 +{
102 _xLabels = xLabels; 115 _xLabels = xLabels;
  116 + _xLabelWidth = width;
  117 +
103 NSString *labelText; 118 NSString *labelText;
104 119
105 if (_showLabel) { 120 if (_showLabel) {
106 - _xLabelWidth = _chartCavanWidth / [xLabels count];  
107 -  
108 for (int index = 0; index < xLabels.count; index++) { 121 for (int index = 0; index < xLabels.count; index++) {
109 labelText = xLabels[index]; 122 labelText = xLabels[index];
110 - PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2), _chartMargin + _chartCavanHeight, _xLabelWidth, _chartMargin)]; 123 +
  124 + NSInteger x = 2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2);
  125 + NSInteger y = _chartMargin + _chartCavanHeight;
  126 +
  127 + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(x, y, _xLabelWidth, _chartMargin)];
111 [label setTextAlignment:NSTextAlignmentCenter]; 128 [label setTextAlignment:NSTextAlignmentCenter];
112 label.text = labelText; 129 label.text = labelText;
  130 + [self setCustomStyleForXLabel:label];
113 [self addSubview:label]; 131 [self addSubview:label];
114 } 132 }
115 } 133 }
116 - else { 134 +}
117 - _xLabelWidth = (self.frame.size.width) / [xLabels count]; 135 +
  136 +- (void)setCustomStyleForXLabel:(UILabel *)label
  137 +{
  138 + if (_xLabelFont) {
  139 + label.font = _xLabelFont;
  140 + }
  141 +
  142 + if (_xLabelColor) {
  143 + label.textColor = _xLabelColor;
118 } 144 }
119 } 145 }
120 146
  147 +- (void)setCustomStyleForYLabel:(UILabel *)label
  148 +{
  149 + if (_yLabelFont) {
  150 + label.font = _yLabelFont;
  151 + }
  152 +
  153 + if (_yLabelColor) {
  154 + label.textColor = _yLabelColor;
  155 + }
  156 +}
121 157
122 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 158 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
123 { 159 {
@@ -125,17 +161,15 @@ @@ -125,17 +161,15 @@
125 [self touchKeyPoint:touches withEvent:event]; 161 [self touchKeyPoint:touches withEvent:event];
126 } 162 }
127 163
128 -  
129 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 164 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
130 { 165 {
131 [self touchPoint:touches withEvent:event]; 166 [self touchPoint:touches withEvent:event];
132 [self touchKeyPoint:touches withEvent:event]; 167 [self touchKeyPoint:touches withEvent:event];
133 } 168 }
134 169
135 -  
136 - (void)touchPoint:(NSSet *)touches withEvent:(UIEvent *)event 170 - (void)touchPoint:(NSSet *)touches withEvent:(UIEvent *)event
137 { 171 {
138 - //Get the point user touched 172 + // Get the point user touched
139 UITouch *touch = [touches anyObject]; 173 UITouch *touch = [touches anyObject];
140 CGPoint touchPoint = [touch locationInView:self]; 174 CGPoint touchPoint = [touch locationInView:self];
141 175
@@ -157,6 +191,7 @@ @@ -157,6 +191,7 @@
157 191
158 if (pointContainsPath) { 192 if (pointContainsPath) {
159 [_delegate userClickedOnLinePoint:touchPoint lineIndex:[_chartPath indexOfObject:path]]; 193 [_delegate userClickedOnLinePoint:touchPoint lineIndex:[_chartPath indexOfObject:path]];
  194 +
160 return; 195 return;
161 } 196 }
162 } 197 }
@@ -165,10 +200,9 @@ @@ -165,10 +200,9 @@
165 } 200 }
166 } 201 }
167 202
168 -  
169 - (void)touchKeyPoint:(NSSet *)touches withEvent:(UIEvent *)event 203 - (void)touchKeyPoint:(NSSet *)touches withEvent:(UIEvent *)event
170 { 204 {
171 - //Get the point user touched 205 + // Get the point user touched
172 UITouch *touch = [touches anyObject]; 206 UITouch *touch = [touches anyObject];
173 CGPoint touchPoint = [touch locationInView:self]; 207 CGPoint touchPoint = [touch locationInView:self];
174 208
@@ -188,19 +222,19 @@ @@ -188,19 +222,19 @@
188 [_delegate userClickedOnLineKeyPoint:touchPoint 222 [_delegate userClickedOnLineKeyPoint:touchPoint
189 lineIndex:p 223 lineIndex:p
190 andPointIndex:(distance == distanceToP2 ? i + 1 : i)]; 224 andPointIndex:(distance == distanceToP2 ? i + 1 : i)];
  225 +
191 return; 226 return;
192 } 227 }
193 } 228 }
194 } 229 }
195 } 230 }
196 231
197 -  
198 - (void)strokeChart 232 - (void)strokeChart
199 { 233 {
200 _chartPath = [[NSMutableArray alloc] init]; 234 _chartPath = [[NSMutableArray alloc] init];
201 _pointPath = [[NSMutableArray alloc] init]; 235 _pointPath = [[NSMutableArray alloc] init];
202 236
203 - //Draw each line 237 + // Draw each line
204 for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) { 238 for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) {
205 PNLineChartData *chartData = self.chartData[lineIndex]; 239 PNLineChartData *chartData = self.chartData[lineIndex];
206 CAShapeLayer *chartLine = (CAShapeLayer *)self.chartLineArray[lineIndex]; 240 CAShapeLayer *chartLine = (CAShapeLayer *)self.chartLineArray[lineIndex];
@@ -245,26 +279,28 @@ @@ -245,26 +279,28 @@
245 innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin); 279 innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin);
246 } 280 }
247 281
248 - int x = 2 * _chartMargin + (i * _xLabelWidth); 282 + CGFloat offSetX = (_chartCavanWidth) / (chartData.itemCount);
  283 +
  284 + int x = 2 * _chartMargin + (i * offSetX);
249 int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2); 285 int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2);
250 286
251 // cycle style point 287 // cycle style point
252 if (chartData.inflexionPointStyle == PNLineChartPointStyleCycle) { 288 if (chartData.inflexionPointStyle == PNLineChartPointStyleCycle) {
253 289
254 - CGRect circleRect = CGRectMake(x-inflexionWidth/2, y-inflexionWidth/2, inflexionWidth,inflexionWidth); 290 + CGRect circleRect = CGRectMake(x - inflexionWidth / 2, y - inflexionWidth / 2, inflexionWidth, inflexionWidth);
255 CGPoint circleCenter = CGPointMake(circleRect.origin.x + (circleRect.size.width / 2), circleRect.origin.y + (circleRect.size.height / 2)); 291 CGPoint circleCenter = CGPointMake(circleRect.origin.x + (circleRect.size.width / 2), circleRect.origin.y + (circleRect.size.height / 2));
256 292
257 - [pointPath moveToPoint:CGPointMake(circleCenter.x + (inflexionWidth/2), circleCenter.y)]; 293 + [pointPath moveToPoint:CGPointMake(circleCenter.x + (inflexionWidth / 2), circleCenter.y)];
258 - [pointPath addArcWithCenter:circleCenter radius:inflexionWidth/2 startAngle:0 endAngle:2*M_PI clockwise:YES]; 294 + [pointPath addArcWithCenter:circleCenter radius:inflexionWidth / 2 startAngle:0 endAngle:2 * M_PI clockwise:YES];
259 295
260 if ( i != 0 ) { 296 if ( i != 0 ) {
261 297
262 // calculate the point for line 298 // calculate the point for line
263 - float distance = sqrt( pow(x-last_x, 2) + pow(y-last_y,2) ); 299 + float distance = sqrt(pow(x - last_x, 2) + pow(y - last_y, 2) );
264 - float last_x1 = last_x + (inflexionWidth/2) / distance * (x-last_x); 300 + float last_x1 = last_x + (inflexionWidth / 2) / distance * (x - last_x);
265 - float last_y1 = last_y + (inflexionWidth/2) / distance * (y-last_y); 301 + float last_y1 = last_y + (inflexionWidth / 2) / distance * (y - last_y);
266 - float x1 = x - (inflexionWidth/2) / distance * (x-last_x); 302 + float x1 = x - (inflexionWidth / 2) / distance * (x - last_x);
267 - float y1 = y - (inflexionWidth/2) / distance * (y-last_y); 303 + float y1 = y - (inflexionWidth / 2) / distance * (y - last_y);
268 304
269 [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; 305 [progressline moveToPoint:CGPointMake(last_x1, last_y1)];
270 [progressline addLineToPoint:CGPointMake(x1, y1)]; 306 [progressline addLineToPoint:CGPointMake(x1, y1)];
@@ -276,23 +312,23 @@ @@ -276,23 +312,23 @@
276 // Square style point 312 // Square style point
277 else if (chartData.inflexionPointStyle == PNLineChartPointStyleSquare) { 313 else if (chartData.inflexionPointStyle == PNLineChartPointStyleSquare) {
278 314
279 - CGRect squareRect = CGRectMake(x-inflexionWidth/2, y-inflexionWidth/2, inflexionWidth,inflexionWidth); 315 + CGRect squareRect = CGRectMake(x - inflexionWidth / 2, y - inflexionWidth / 2, inflexionWidth, inflexionWidth);
280 CGPoint squareCenter = CGPointMake(squareRect.origin.x + (squareRect.size.width / 2), squareRect.origin.y + (squareRect.size.height / 2)); 316 CGPoint squareCenter = CGPointMake(squareRect.origin.x + (squareRect.size.width / 2), squareRect.origin.y + (squareRect.size.height / 2));
281 317
282 - [pointPath moveToPoint:CGPointMake(squareCenter.x - (inflexionWidth/2), squareCenter.y - (inflexionWidth/2))]; 318 + [pointPath moveToPoint:CGPointMake(squareCenter.x - (inflexionWidth / 2), squareCenter.y - (inflexionWidth / 2))];
283 - [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth/2), squareCenter.y - (inflexionWidth/2))]; 319 + [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth / 2), squareCenter.y - (inflexionWidth / 2))];
284 - [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth/2), squareCenter.y + (inflexionWidth/2))]; 320 + [pointPath addLineToPoint:CGPointMake(squareCenter.x + (inflexionWidth / 2), squareCenter.y + (inflexionWidth / 2))];
285 - [pointPath addLineToPoint:CGPointMake(squareCenter.x - (inflexionWidth/2), squareCenter.y + (inflexionWidth/2))]; 321 + [pointPath addLineToPoint:CGPointMake(squareCenter.x - (inflexionWidth / 2), squareCenter.y + (inflexionWidth / 2))];
286 [pointPath closePath]; 322 [pointPath closePath];
287 323
288 if ( i != 0 ) { 324 if ( i != 0 ) {
289 325
290 // calculate the point for line 326 // calculate the point for line
291 - float distance = sqrt( pow(x-last_x, 2) + pow(y-last_y,2) ); 327 + float distance = sqrt(pow(x - last_x, 2) + pow(y - last_y, 2) );
292 - float last_x1 = last_x + (inflexionWidth/2); 328 + float last_x1 = last_x + (inflexionWidth / 2);
293 - float last_y1 = last_y + (inflexionWidth/2) / distance * (y-last_y); 329 + float last_y1 = last_y + (inflexionWidth / 2) / distance * (y - last_y);
294 - float x1 = x - (inflexionWidth/2); 330 + float x1 = x - (inflexionWidth / 2);
295 - float y1 = y - (inflexionWidth/2) / distance * (y-last_y); 331 + float y1 = y - (inflexionWidth / 2) / distance * (y - last_y);
296 332
297 [progressline moveToPoint:CGPointMake(last_x1, last_y1)]; 333 [progressline moveToPoint:CGPointMake(last_x1, last_y1)];
298 [progressline addLineToPoint:CGPointMake(x1, y1)]; 334 [progressline addLineToPoint:CGPointMake(x1, y1)];
@@ -326,8 +362,7 @@ @@ -326,8 +362,7 @@
326 // setup the color of the chart line 362 // setup the color of the chart line
327 if (chartData.color) { 363 if (chartData.color) {
328 chartLine.strokeColor = [chartData.color CGColor]; 364 chartLine.strokeColor = [chartData.color CGColor];
329 - } 365 + } else {
330 - else {  
331 chartLine.strokeColor = [PNGreen CGColor]; 366 chartLine.strokeColor = [PNGreen CGColor];
332 pointLayer.strokeColor = [PNGreen CGColor]; 367 pointLayer.strokeColor = [PNGreen CGColor];
333 } 368 }
@@ -337,7 +372,6 @@ @@ -337,7 +372,6 @@
337 chartLine.path = progressline.CGPath; 372 chartLine.path = progressline.CGPath;
338 pointLayer.path = pointPath.CGPath; 373 pointLayer.path = pointPath.CGPath;
339 374
340 -  
341 [CATransaction begin]; 375 [CATransaction begin];
342 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 376 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
343 pathAnimation.duration = 1.0; 377 pathAnimation.duration = 1.0;
@@ -354,8 +388,8 @@ @@ -354,8 +388,8 @@
354 } 388 }
355 389
356 [CATransaction setCompletionBlock:^{ 390 [CATransaction setCompletionBlock:^{
357 - //pointLayer.strokeEnd = 1.0f; // stroken point when animation end 391 + // pointLayer.strokeEnd = 1.0f; // stroken point when animation end
358 - }]; 392 + }];
359 [CATransaction commit]; 393 [CATransaction commit];
360 394
361 UIGraphicsEndImageContext(); 395 UIGraphicsEndImageContext();
@@ -446,7 +480,7 @@ @@ -446,7 +480,7 @@
446 CGContextSetLineWidth(ctx, self.axisWidth); 480 CGContextSetLineWidth(ctx, self.axisWidth);
447 CGContextSetStrokeColorWithColor(ctx, [self.axisColor CGColor]); 481 CGContextSetStrokeColorWithColor(ctx, [self.axisColor CGColor]);
448 482
449 - CGFloat xAxisWidth = CGRectGetWidth(rect) - _chartMargin/2; 483 + CGFloat xAxisWidth = CGRectGetWidth(rect) - _chartMargin / 2;
450 CGFloat yAxisHeight = _chartMargin + _chartCavanHeight; 484 CGFloat yAxisHeight = _chartMargin + _chartCavanHeight;
451 485
452 // draw coordinate axis 486 // draw coordinate axis
@@ -481,7 +515,7 @@ @@ -481,7 +515,7 @@
481 // draw y axis separator 515 // draw y axis separator
482 CGFloat yStepHeight = _chartCavanHeight / _yLabelNum; 516 CGFloat yStepHeight = _chartCavanHeight / _yLabelNum;
483 for (NSUInteger i = 0; i < [self.xLabels count]; i++) { 517 for (NSUInteger i = 0; i < [self.xLabels count]; i++) {
484 - point = CGPointMake(_chartMargin + yAsixOffset, (_chartCavanHeight - i * yStepHeight + _yLabelHeight/2)); 518 + point = CGPointMake(_chartMargin + yAsixOffset, (_chartCavanHeight - i * yStepHeight + _yLabelHeight / 2));
485 CGContextMoveToPoint(ctx, point.x, point.y); 519 CGContextMoveToPoint(ctx, point.x, point.y);
486 CGContextAddLineToPoint(ctx, point.x + 2, point.y); 520 CGContextAddLineToPoint(ctx, point.x + 2, point.y);
487 CGContextStrokePath(ctx); 521 CGContextStrokePath(ctx);
@@ -489,6 +523,7 @@ @@ -489,6 +523,7 @@
489 } 523 }
490 524
491 UIFont *font = [UIFont systemFontOfSize:11]; 525 UIFont *font = [UIFont systemFontOfSize:11];
  526 +
492 // draw y unit 527 // draw y unit
493 if ([self.yUnit length]) { 528 if ([self.yUnit length]) {
494 CGFloat height = [PNLineChart heightOfString:self.yUnit withWidth:30.f font:font]; 529 CGFloat height = [PNLineChart heightOfString:self.yUnit withWidth:30.f font:font];
@@ -499,7 +534,7 @@ @@ -499,7 +534,7 @@
499 // draw x unit 534 // draw x unit
500 if ([self.xUnit length]) { 535 if ([self.xUnit length]) {
501 CGFloat height = [PNLineChart heightOfString:self.xUnit withWidth:30.f font:font]; 536 CGFloat height = [PNLineChart heightOfString:self.xUnit withWidth:30.f font:font];
502 - CGRect drawRect = CGRectMake(CGRectGetWidth(rect) - _chartMargin + 5, _chartMargin + _chartCavanHeight - height/2, 25.f, height); 537 + CGRect drawRect = CGRectMake(CGRectGetWidth(rect) - _chartMargin + 5, _chartMargin + _chartCavanHeight - height / 2, 25.f, height);
503 [self drawTextInContext:ctx text:self.xUnit inRect:drawRect font:font]; 538 [self drawTextInContext:ctx text:self.xUnit inRect:drawRect font:font];
504 } 539 }
505 } 540 }
@@ -539,21 +574,19 @@ @@ -539,21 +574,19 @@
539 { 574 {
540 NSInteger ch; 575 NSInteger ch;
541 CGSize size = CGSizeMake(width, MAXFLOAT); 576 CGSize size = CGSizeMake(width, MAXFLOAT);
542 - if ([text respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) 577 +
543 - { 578 + if ([text respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
544 - NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil]; 579 + NSDictionary *tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
545 - size =[text boundingRectWithSize:size 580 + size = [text boundingRectWithSize:size
546 - options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading 581 + options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
547 - attributes:tdic 582 + attributes:tdic
548 - context:nil].size; 583 + context:nil].size;
549 - } 584 + } else {
550 - else  
551 - {  
552 #pragma clang diagnostic push 585 #pragma clang diagnostic push
553 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 586 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
554 size = [text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping]; 587 size = [text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
555 #pragma clang diagnostic pop 588 #pragma clang diagnostic pop
556 - } 589 + }
557 ch = size.height; 590 ch = size.height;
558 591
559 return ch; 592 return ch;
@@ -567,7 +600,7 @@ @@ -567,7 +600,7 @@
567 priceParagraphStyle.alignment = NSTextAlignmentLeft; 600 priceParagraphStyle.alignment = NSTextAlignmentLeft;
568 601
569 [text drawInRect:rect 602 [text drawInRect:rect
570 - withAttributes:@{NSParagraphStyleAttributeName:priceParagraphStyle, NSFontAttributeName:font}]; 603 + withAttributes:@{ NSParagraphStyleAttributeName:priceParagraphStyle, NSFontAttributeName:font }];
571 } else { 604 } else {
572 #pragma clang diagnostic push 605 #pragma clang diagnostic push
573 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 606 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -579,5 +612,4 @@ @@ -579,5 +612,4 @@
579 } 612 }
580 } 613 }
581 614
582 -  
583 @end 615 @end
@@ -7,4 +7,4 @@ DEPENDENCIES: @@ -7,4 +7,4 @@ DEPENDENCIES:
7 SPEC CHECKSUMS: 7 SPEC CHECKSUMS:
8 UICountingLabel: 0a0e9e34bf4690dbd127aaec552d19ed938087a9 8 UICountingLabel: 0a0e9e34bf4690dbd127aaec552d19ed938087a9
9 9
10 -COCOAPODS: 0.32.1 10 +COCOAPODS: 0.33.1