Kevin

Merge pull request #48 from orlandoaleman/master

FIX related with XLabels 
@@ -11,12 +11,9 @@ @@ -11,12 +11,9 @@
11 11
12 @interface PNBar : UIView 12 @interface PNBar : UIView
13 13
14 -@property (nonatomic) float grade; 14 +- (void)rollBack;
15 -  
16 -@property (nonatomic,strong) CAShapeLayer * chartLine;  
17 -  
18 -@property (nonatomic, strong) UIColor * barColor;  
19 -  
20 --(void)rollBack;  
21 15
  16 +@property (nonatomic) float grade;
  17 +@property (nonatomic) CAShapeLayer *chartLine;
  18 +@property (nonatomic) UIColor *barColor;
22 @end 19 @end
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 - (id)initWithFrame:(CGRect)frame 14 - (id)initWithFrame:(CGRect)frame
15 { 15 {
16 self = [super initWithFrame:frame]; 16 self = [super initWithFrame:frame];
  17 +
17 if (self) { 18 if (self) {
18 // Initialization code 19 // Initialization code
19 _chartLine = [CAShapeLayer layer]; 20 _chartLine = [CAShapeLayer layer];
@@ -22,57 +23,61 @@ @@ -22,57 +23,61 @@
22 _chartLine.lineWidth = self.frame.size.width; 23 _chartLine.lineWidth = self.frame.size.width;
23 _chartLine.strokeEnd = 0.0; 24 _chartLine.strokeEnd = 0.0;
24 self.clipsToBounds = YES; 25 self.clipsToBounds = YES;
25 - [self.layer addSublayer:_chartLine]; 26 + [self.layer addSublayer:_chartLine];
26 self.layer.cornerRadius = 2.0; 27 self.layer.cornerRadius = 2.0;
27 } 28 }
  29 +
28 return self; 30 return self;
29 } 31 }
30 32
31 --(void)setGrade:(float)grade 33 +
  34 +- (void)setGrade:(float)grade
32 { 35 {
33 - _grade = grade; 36 + _grade = grade;
34 - UIBezierPath *progressline = [UIBezierPath bezierPath]; 37 + UIBezierPath *progressline = [UIBezierPath bezierPath];
35 - 38 +
36 - [progressline moveToPoint:CGPointMake(self.frame.size.width/2.0, self.frame.size.height)]; 39 + [progressline moveToPoint:CGPointMake(self.frame.size.width / 2.0, self.frame.size.height)];
37 - [progressline addLineToPoint:CGPointMake(self.frame.size.width/2.0, (1 - grade) * self.frame.size.height)]; 40 + [progressline addLineToPoint:CGPointMake(self.frame.size.width / 2.0, (1 - grade) * self.frame.size.height)];
38 - 41 +
39 [progressline setLineWidth:1.0]; 42 [progressline setLineWidth:1.0];
40 [progressline setLineCapStyle:kCGLineCapSquare]; 43 [progressline setLineCapStyle:kCGLineCapSquare];
41 - _chartLine.path = progressline.CGPath; 44 + _chartLine.path = progressline.CGPath;
42 - 45 +
43 - if (_barColor) { 46 + if (_barColor) {
44 - _chartLine.strokeColor = [_barColor CGColor]; 47 + _chartLine.strokeColor = [_barColor CGColor];
45 - }else{ 48 + }
46 - _chartLine.strokeColor = [PNGreen CGColor]; 49 + else {
47 - } 50 + _chartLine.strokeColor = [PNGreen CGColor];
48 - 51 + }
  52 +
49 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 53 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
50 pathAnimation.duration = 1.0; 54 pathAnimation.duration = 1.0;
51 pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 55 pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
52 pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; 56 pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
53 pathAnimation.toValue = [NSNumber numberWithFloat:1.0f]; 57 pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
54 [_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; 58 [_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
55 - 59 +
56 _chartLine.strokeEnd = 1.0; 60 _chartLine.strokeEnd = 1.0;
57 } 61 }
58 62
59 --(void)rollBack{ 63 +
60 - [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 64 +- (void)rollBack
  65 +{
  66 + [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations: ^{
61 _chartLine.strokeColor = [UIColor clearColor].CGColor; 67 _chartLine.strokeColor = [UIColor clearColor].CGColor;
62 } completion:nil]; 68 } completion:nil];
63 -  
64 -  
65 } 69 }
  70 +
  71 +
66 // Only override drawRect: if you perform custom drawing. 72 // Only override drawRect: if you perform custom drawing.
67 // An empty implementation adversely affects performance during animation. 73 // An empty implementation adversely affects performance during animation.
68 - (void)drawRect:(CGRect)rect 74 - (void)drawRect:(CGRect)rect
69 { 75 {
70 - //Draw BG 76 + //Draw BG
71 CGContextRef context = UIGraphicsGetCurrentContext(); 77 CGContextRef context = UIGraphicsGetCurrentContext();
72 - 78 +
73 CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor); 79 CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
74 - CGContextFillRect(context, rect); 80 + CGContextFillRect(context, rect);
75 -  
76 } 81 }
77 82
78 83
@@ -8,10 +8,11 @@ @@ -8,10 +8,11 @@
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
10 10
11 -#define chartMargin 10 11 +#define chartMargin 10
12 -#define xLabelMargin 15 12 +#define xLabelMargin 15
13 -#define yLabelMargin 15 13 +#define yLabelMargin 15
14 -#define yLabelHeight 11 14 +#define yLabelHeight 11
  15 +#define xLabelHeight 20
15 16
16 @interface PNBarChart : UIView 17 @interface PNBarChart : UIView
17 18
@@ -19,24 +20,16 @@ @@ -19,24 +20,16 @@
19 * This method will call and stroke the line in animation 20 * This method will call and stroke the line in animation
20 */ 21 */
21 22
22 --(void)strokeChart; 23 +- (void)strokeChart;
23 -  
24 -@property (strong, nonatomic) NSArray * xLabels;  
25 -  
26 -@property (strong, nonatomic) NSArray * yLabels;  
27 -  
28 -@property (strong, nonatomic) NSArray * yValues;  
29 24
  25 +@property (nonatomic) NSArray *xLabels;
  26 +@property (nonatomic) NSArray *yLabels;
  27 +@property (nonatomic) NSArray *yValues;
30 @property (nonatomic) CGFloat xLabelWidth; 28 @property (nonatomic) CGFloat xLabelWidth;
31 -  
32 @property (nonatomic) int yValueMax; 29 @property (nonatomic) int yValueMax;
33 - 30 +@property (nonatomic) UIColor *strokeColor;
34 -@property (nonatomic, strong) UIColor * strokeColor; 31 +@property (nonatomic) NSArray *strokeColors;
35 - 32 +@property (nonatomic) UIColor *barBackgroundColor;
36 -@property (nonatomic, strong) NSArray * strokeColors;  
37 -  
38 -@property (nonatomic, strong) UIColor * barBackgroundColor;  
39 -  
40 @property (nonatomic) BOOL showLabel; 33 @property (nonatomic) BOOL showLabel;
41 34
42 @end 35 @end
@@ -11,9 +11,9 @@ @@ -11,9 +11,9 @@
11 #import "PNChartLabel.h" 11 #import "PNChartLabel.h"
12 #import "PNBar.h" 12 #import "PNBar.h"
13 13
14 -@interface PNBarChart() { 14 +@interface PNBarChart () {
15 - NSMutableArray* _bars; 15 + NSMutableArray *_bars;
16 - NSMutableArray* _labels; 16 + NSMutableArray *_labels;
17 } 17 }
18 18
19 - (UIColor *)barColorAtIndex:(NSUInteger)index; 19 - (UIColor *)barColorAtIndex:(NSUInteger)index;
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 - (id)initWithFrame:(CGRect)frame 24 - (id)initWithFrame:(CGRect)frame
25 { 25 {
26 self = [super initWithFrame:frame]; 26 self = [super initWithFrame:frame];
  27 +
27 if (self) { 28 if (self) {
28 // Initialization code 29 // Initialization code
29 self.backgroundColor = [UIColor whiteColor]; 30 self.backgroundColor = [UIColor whiteColor];
@@ -37,23 +38,26 @@ @@ -37,23 +38,26 @@
37 return self; 38 return self;
38 } 39 }
39 40
40 --(void)setYValues:(NSArray *)yValues 41 +
  42 +- (void)setYValues:(NSArray *)yValues
41 { 43 {
42 _yValues = yValues; 44 _yValues = yValues;
43 [self setYLabels:yValues]; 45 [self setYLabels:yValues];
44 46
45 - _xLabelWidth = (self.frame.size.width - chartMargin*2)/[_yValues count]; 47 + _xLabelWidth = (self.frame.size.width - chartMargin * 2) / [_yValues count];
46 } 48 }
47 49
48 --(void)setYLabels:(NSArray *)yLabels 50 +
  51 +- (void)setYLabels:(NSArray *)yLabels
49 { 52 {
50 NSInteger max = 0; 53 NSInteger max = 0;
51 - for (NSString * valueString in yLabels) { 54 +
  55 + for (NSString *valueString in yLabels) {
52 NSInteger value = [valueString integerValue]; 56 NSInteger value = [valueString integerValue];
  57 +
53 if (value > max) { 58 if (value > max) {
54 max = value; 59 max = value;
55 } 60 }
56 -  
57 } 61 }
58 62
59 //Min value for Y label 63 //Min value for Y label
@@ -64,47 +68,54 @@ @@ -64,47 +68,54 @@
64 _yValueMax = (int)max; 68 _yValueMax = (int)max;
65 } 69 }
66 70
67 --(void)setXLabels:(NSArray *)xLabels 71 +
  72 +- (void)setXLabels:(NSArray *)xLabels
68 { 73 {
69 - [self viewCleanupForCollection:_labels];  
70 _xLabels = xLabels; 74 _xLabels = xLabels;
71 75
72 if (_showLabel) { 76 if (_showLabel) {
73 - _xLabelWidth = (self.frame.size.width - chartMargin*2)/[xLabels count]; 77 + _xLabelWidth = (self.frame.size.width - chartMargin * 2) / [xLabels count];
74 -  
75 - for(int index = 0; index < xLabels.count; index++)  
76 - {  
77 - NSString* labelText = xLabels[index];  
78 - PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin), self.frame.size.height - 30.0, _xLabelWidth, 20.0)];  
79 - [label setTextAlignment:NSTextAlignmentCenter];  
80 - label.text = labelText;  
81 - [_labels addObject:label];  
82 - [self addSubview:label];  
83 - }  
84 } 78 }
85 } 79 }
86 80
87 --(void)setStrokeColor:(UIColor *)strokeColor 81 +
  82 +- (void)setStrokeColor:(UIColor *)strokeColor
88 { 83 {
89 - _strokeColor = strokeColor; 84 + _strokeColor = strokeColor;
90 } 85 }
91 86
92 --(void)strokeChart 87 +
  88 +- (void)strokeChart
93 { 89 {
  90 + [self viewCleanupForCollection:_labels];
  91 +
  92 + for (int index = 0; index < _xLabels.count; index++) {
  93 + NSString *labelText = _xLabels[index];
  94 + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin), self.frame.size.height - xLabelHeight - chartMargin, _xLabelWidth, xLabelHeight)];
  95 + [label setTextAlignment:NSTextAlignmentCenter];
  96 + label.text = labelText;
  97 + [_labels addObject:label];
  98 + [self addSubview:label];
  99 + }
  100 +
94 [self viewCleanupForCollection:_bars]; 101 [self viewCleanupForCollection:_bars];
95 - CGFloat chartCavanHeight = self.frame.size.height - chartMargin * 2 - 40.0; 102 +
  103 + CGFloat chartCavanHeight = self.frame.size.height - chartMargin * 2 - xLabelHeight * 2;
96 NSInteger index = 0; 104 NSInteger index = 0;
97 105
98 - for (NSString * valueString in _yValues) { 106 + for (NSString *valueString in _yValues) {
99 float value = [valueString floatValue]; 107 float value = [valueString floatValue];
100 108
101 float grade = (float)value / (float)_yValueMax; 109 float grade = (float)value / (float)_yValueMax;
102 - PNBar * bar; 110 + PNBar *bar;
  111 +
103 if (_showLabel) { 112 if (_showLabel) {
104 - bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight - 30.0, _xLabelWidth * 0.5, chartCavanHeight)]; 113 + bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight - xLabelHeight - chartMargin, _xLabelWidth * 0.5, chartCavanHeight)];
105 - }else{ 114 + }
106 - bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight , _xLabelWidth * 0.6, chartCavanHeight)]; 115 + else {
  116 + bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight, _xLabelWidth * 0.6, chartCavanHeight)];
107 } 117 }
  118 +
108 bar.backgroundColor = _barBackgroundColor; 119 bar.backgroundColor = _barBackgroundColor;
109 bar.barColor = [self barColorAtIndex:index]; 120 bar.barColor = [self barColorAtIndex:index];
110 bar.grade = grade; 121 bar.grade = grade;
@@ -115,7 +126,8 @@ @@ -115,7 +126,8 @@
115 } 126 }
116 } 127 }
117 128
118 -- (void)viewCleanupForCollection:(NSMutableArray*)array 129 +
  130 +- (void)viewCleanupForCollection:(NSMutableArray *)array
119 { 131 {
120 if (array.count) { 132 if (array.count) {
121 [array makeObjectsPerformSelector:@selector(removeFromSuperview)]; 133 [array makeObjectsPerformSelector:@selector(removeFromSuperview)];
@@ -123,15 +135,18 @@ @@ -123,15 +135,18 @@
123 } 135 }
124 } 136 }
125 137
  138 +
126 #pragma mark - Class extension methods 139 #pragma mark - Class extension methods
127 140
128 - (UIColor *)barColorAtIndex:(NSUInteger)index 141 - (UIColor *)barColorAtIndex:(NSUInteger)index
129 { 142 {
130 if ([self.strokeColors count] == [self.yValues count]) { 143 if ([self.strokeColors count] == [self.yValues count]) {
131 return self.strokeColors[index]; 144 return self.strokeColors[index];
132 - } else { 145 + }
  146 + else {
133 return self.strokeColor; 147 return self.strokeColor;
134 } 148 }
135 } 149 }
136 150
  151 +
137 @end 152 @end
@@ -14,13 +14,13 @@ @@ -14,13 +14,13 @@
14 * When user click on the chart line 14 * When user click on the chart line
15 * 15 *
16 */ 16 */
17 -- (void)userClickedOnLinePoint:(CGPoint )point lineIndex:(NSInteger)lineIndex; 17 +- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex;
18 18
19 /** 19 /**
20 * When user click on the chart line key point 20 * When user click on the chart line key point
21 * 21 *
22 */ 22 */
23 -- (void)userClickedOnLineKeyPoint:(CGPoint )point lineIndex:(NSInteger)lineIndex andPointIndex:(NSInteger)pointIndex; 23 +- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex andPointIndex:(NSInteger)pointIndex;
24 24
25 25
26 @end 26 @end
@@ -14,27 +14,20 @@ @@ -14,27 +14,20 @@
14 - (id)initWithFrame:(CGRect)frame 14 - (id)initWithFrame:(CGRect)frame
15 { 15 {
16 self = [super initWithFrame:frame]; 16 self = [super initWithFrame:frame];
  17 +
17 if (self) { 18 if (self) {
18 // Initialization code 19 // Initialization code
19 [self setLineBreakMode:NSLineBreakByWordWrapping]; 20 [self setLineBreakMode:NSLineBreakByWordWrapping];
20 [self setMinimumScaleFactor:11.0f]; 21 [self setMinimumScaleFactor:11.0f];
21 [self setNumberOfLines:0]; 22 [self setNumberOfLines:0];
22 [self setFont:[UIFont boldSystemFontOfSize:11.0f]]; 23 [self setFont:[UIFont boldSystemFontOfSize:11.0f]];
23 - [self setTextColor: PNDeepGrey]; 24 + [self setTextColor:PNDeepGrey];
24 self.backgroundColor = [UIColor clearColor]; 25 self.backgroundColor = [UIColor clearColor];
25 [self setTextAlignment:NSTextAlignmentLeft]; 26 [self setTextAlignment:NSTextAlignmentLeft];
26 self.userInteractionEnabled = YES; 27 self.userInteractionEnabled = YES;
27 } 28 }
28 - return self;  
29 -}  
30 29
31 -/* 30 + return self;
32 -// Only override drawRect: if you perform custom drawing.  
33 -// An empty implementation adversely affects performance during animation.  
34 -- (void)drawRect:(CGRect)rect  
35 -{  
36 - // Drawing code  
37 } 31 }
38 -*/  
39 32
40 @end 33 @end
@@ -14,17 +14,17 @@ @@ -14,17 +14,17 @@
14 14
15 @interface PNCircleChart : UIView 15 @interface PNCircleChart : UIView
16 16
17 --(void)strokeChart; 17 +- (void)strokeChart;
18 - (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise; 18 - (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise;
19 19
20 -@property (nonatomic, strong) UIColor *strokeColor; 20 +@property (nonatomic) UIColor *strokeColor;
21 -@property (nonatomic, strong) UIColor *labelColor; 21 +@property (nonatomic) UIColor *labelColor;
22 -@property (nonatomic, strong) NSNumber * total; 22 +@property (nonatomic) NSNumber *total;
23 -@property (nonatomic, strong) NSNumber * current; 23 +@property (nonatomic) NSNumber *current;
24 -@property (nonatomic, strong) NSNumber * lineWidth; 24 +@property (nonatomic) NSNumber *lineWidth;
25 @property (nonatomic) BOOL clockwise; 25 @property (nonatomic) BOOL clockwise;
26 26
27 -@property(nonatomic,strong) CAShapeLayer * circle; 27 +@property (nonatomic) CAShapeLayer *circle;
28 -@property(nonatomic,strong) CAShapeLayer * circleBG; 28 +@property (nonatomic) CAShapeLayer *circleBG;
29 29
30 @end 30 @end
@@ -22,25 +22,27 @@ @@ -22,25 +22,27 @@
22 if (!_labelColor) { 22 if (!_labelColor) {
23 _labelColor = PNDeepGrey; 23 _labelColor = PNDeepGrey;
24 } 24 }
  25 +
25 return _labelColor; 26 return _labelColor;
26 } 27 }
27 28
28 29
29 -- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise { 30 +- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise
  31 +{
30 self = [super initWithFrame:frame]; 32 self = [super initWithFrame:frame];
31 - 33 +
32 if (self) { 34 if (self) {
33 _total = total; 35 _total = total;
34 _current = current; 36 _current = current;
35 _strokeColor = PNFreshGreen; 37 _strokeColor = PNFreshGreen;
36 - _clockwise = clockwise; 38 + _clockwise = clockwise;
37 - 39 +
38 - CGFloat startAngle = clockwise ? -90.0f : 270.0f; 40 + CGFloat startAngle = clockwise ? -90.0f : 270.0f;
39 - CGFloat endAngle = clockwise ? -90.01f : 270.01f; 41 + CGFloat endAngle = clockwise ? -90.01f : 270.01f;
40 - 42 +
41 _lineWidth = [NSNumber numberWithFloat:8.0]; 43 _lineWidth = [NSNumber numberWithFloat:8.0];
42 - UIBezierPath* circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x,self.center.y) radius:self.frame.size.height*0.5 startAngle:DEGREES_TO_RADIANS(startAngle) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:clockwise]; 44 + UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y) radius:self.frame.size.height * 0.5 startAngle:DEGREES_TO_RADIANS(startAngle) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:clockwise];
43 - 45 +
44 _circle = [CAShapeLayer layer]; 46 _circle = [CAShapeLayer layer];
45 _circle.path = circlePath.CGPath; 47 _circle.path = circlePath.CGPath;
46 _circle.lineCap = kCALineCapRound; 48 _circle.lineCap = kCALineCapRound;
@@ -56,50 +58,49 @@ @@ -56,50 +58,49 @@
56 _circleBG.strokeColor = PNLightYellow.CGColor; 58 _circleBG.strokeColor = PNLightYellow.CGColor;
57 _circleBG.strokeEnd = 1.0; 59 _circleBG.strokeEnd = 1.0;
58 _circleBG.zPosition = -1; 60 _circleBG.zPosition = -1;
59 - 61 +
60 [self.layer addSublayer:_circle]; 62 [self.layer addSublayer:_circle];
61 [self.layer addSublayer:_circleBG]; 63 [self.layer addSublayer:_circleBG];
62 64
63 - _gradeLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(0, 0, 50.0, 50.0)]; 65 + _gradeLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(0, 0, 50.0, 50.0)];
64 -  
65 } 66 }
66 - 67 +
67 return self; 68 return self;
68 -  
69 } 69 }
70 70
71 --(void)strokeChart 71 +
  72 +- (void)strokeChart
72 { 73 {
73 //Add count label 74 //Add count label
74 - 75 +
75 [_gradeLabel setTextAlignment:NSTextAlignmentCenter]; 76 [_gradeLabel setTextAlignment:NSTextAlignmentCenter];
76 [_gradeLabel setFont:[UIFont boldSystemFontOfSize:13.0f]]; 77 [_gradeLabel setFont:[UIFont boldSystemFontOfSize:13.0f]];
77 [_gradeLabel setTextColor:self.labelColor]; 78 [_gradeLabel setTextColor:self.labelColor];
78 - [_gradeLabel setCenter:CGPointMake(self.center.x,self.center.y)]; 79 + [_gradeLabel setCenter:CGPointMake(self.center.x, self.center.y)];
79 _gradeLabel.method = UILabelCountingMethodEaseInOut; 80 _gradeLabel.method = UILabelCountingMethodEaseInOut;
80 _gradeLabel.format = @"%d%%"; 81 _gradeLabel.format = @"%d%%";
81 - 82 +
82 - 83 +
83 [self addSubview:_gradeLabel]; 84 [self addSubview:_gradeLabel];
84 - 85 +
85 //Add circle params 86 //Add circle params
86 - 87 +
87 _circle.lineWidth = [_lineWidth floatValue]; 88 _circle.lineWidth = [_lineWidth floatValue];
88 _circleBG.lineWidth = [_lineWidth floatValue]; 89 _circleBG.lineWidth = [_lineWidth floatValue];
89 _circleBG.strokeEnd = 1.0; 90 _circleBG.strokeEnd = 1.0;
90 _circle.strokeColor = _strokeColor.CGColor; 91 _circle.strokeColor = _strokeColor.CGColor;
91 - 92 +
92 //Add Animation 93 //Add Animation
93 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 94 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
94 pathAnimation.duration = 1.0; 95 pathAnimation.duration = 1.0;
95 pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 96 pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
96 pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; 97 pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
97 - pathAnimation.toValue = [NSNumber numberWithFloat:[_current floatValue]/[_total floatValue]]; 98 + pathAnimation.toValue = [NSNumber numberWithFloat:[_current floatValue] / [_total floatValue]];
98 [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; 99 [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
99 - _circle.strokeEnd = [_current floatValue]/[_total floatValue]; 100 + _circle.strokeEnd = [_current floatValue] / [_total floatValue];
100 - 101 +
101 - [_gradeLabel countFrom:0 to:[_current floatValue]/[_total floatValue]*100 withDuration:1.0]; 102 + [_gradeLabel countFrom:0 to:[_current floatValue] / [_total floatValue] * 100 withDuration:1.0];
102 -  
103 } 103 }
104 104
  105 +
105 @end 106 @end
@@ -7,45 +7,44 @@ @@ -7,45 +7,44 @@
7 // 7 //
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
  10 +
10 /* 11 /*
11 * System Versioning Preprocessor Macros 12 * System Versioning Preprocessor Macros
12 */ 13 */
13 14
14 -#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) 15 +#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
15 - 16 +
16 -#define PNGrey [UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1.0f] 17 +#define PNGrey [UIColor colorWithRed:246.0 / 255.0 green:246.0 / 255.0 blue:246.0 / 255.0 alpha:1.0f]
17 -#define PNLightBlue [UIColor colorWithRed:94.0/255.0 green:147.0/255.0 blue:196.0/255.0 alpha:1.0f] 18 +#define PNLightBlue [UIColor colorWithRed:94.0 / 255.0 green:147.0 / 255.0 blue:196.0 / 255.0 alpha:1.0f]
18 -#define PNGreen [UIColor colorWithRed:77.0/255.0 green:186.0/255.0 blue:122.0/255.0 alpha:1.0f] 19 +#define PNGreen [UIColor colorWithRed:77.0 / 255.0 green:186.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]
19 -#define PNTitleColor [UIColor colorWithRed:0.0/255.0 green:189.0/255.0 blue:113.0/255.0 alpha:1.0f] 20 +#define PNTitleColor [UIColor colorWithRed:0.0 / 255.0 green:189.0 / 255.0 blue:113.0 / 255.0 alpha:1.0f]
20 -#define PNButtonGrey [UIColor colorWithRed:141.0/255.0 green:141.0/255.0 blue:141.0/255.0 alpha:1.0f] 21 +#define PNButtonGrey [UIColor colorWithRed:141.0 / 255.0 green:141.0 / 255.0 blue:141.0 / 255.0 alpha:1.0f]
21 -#define PNFreshGreen [UIColor colorWithRed:77.0/255.0 green:196.0/255.0 blue:122.0/255.0 alpha:1.0f] 22 +#define PNFreshGreen [UIColor colorWithRed:77.0 / 255.0 green:196.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]
22 -#define PNRed [UIColor colorWithRed:245.0/255.0 green:94.0/255.0 blue:78.0/255.0 alpha:1.0f] 23 +#define PNRed [UIColor colorWithRed:245.0 / 255.0 green:94.0 / 255.0 blue:78.0 / 255.0 alpha:1.0f]
23 -#define PNMauve [UIColor colorWithRed:88.0/255.0 green:75.0/255.0 blue:103.0/255.0 alpha:1.0f] 24 +#define PNMauve [UIColor colorWithRed:88.0 / 255.0 green:75.0 / 255.0 blue:103.0 / 255.0 alpha:1.0f]
24 -#define PNBrown [UIColor colorWithRed:119.0/255.0 green:107.0/255.0 blue:95.0/255.0 alpha:1.0f] 25 +#define PNBrown [UIColor colorWithRed:119.0 / 255.0 green:107.0 / 255.0 blue:95.0 / 255.0 alpha:1.0f]
25 -#define PNBlue [UIColor colorWithRed:82.0/255.0 green:116.0/255.0 blue:188.0/255.0 alpha:1.0f] 26 +#define PNBlue [UIColor colorWithRed:82.0 / 255.0 green:116.0 / 255.0 blue:188.0 / 255.0 alpha:1.0f]
26 -#define PNDarkBlue [UIColor colorWithRed:121.0/255.0 green:134.0/255.0 blue:142.0/255.0 alpha:1.0f] 27 +#define PNDarkBlue [UIColor colorWithRed:121.0 / 255.0 green:134.0 / 255.0 blue:142.0 / 255.0 alpha:1.0f]
27 -#define PNYellow [UIColor colorWithRed:242.0/255.0 green:197.0/255.0 blue:117.0/255.0 alpha:1.0f] 28 +#define PNYellow [UIColor colorWithRed:242.0 / 255.0 green:197.0 / 255.0 blue:117.0 / 255.0 alpha:1.0f]
28 -#define PNWhite [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0f] 29 +#define PNWhite [UIColor colorWithRed:255.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:1.0f]
29 -#define PNDeepGrey [UIColor colorWithRed:99.0/255.0 green:99.0/255.0 blue:99.0/255.0 alpha:1.0f] 30 +#define PNDeepGrey [UIColor colorWithRed:99.0 / 255.0 green:99.0 / 255.0 blue:99.0 / 255.0 alpha:1.0f]
30 -#define PNPinkGrey [UIColor colorWithRed:200.0/255.0 green:193.0/255.0 blue:193.0/255.0 alpha:1.0f] 31 +#define PNPinkGrey [UIColor colorWithRed:200.0 / 255.0 green:193.0 / 255.0 blue:193.0 / 255.0 alpha:1.0f]
31 -#define PNHealYellow [UIColor colorWithRed:245.0/255.0 green:242.0/255.0 blue:238.0/255.0 alpha:1.0f] 32 +#define PNHealYellow [UIColor colorWithRed:245.0 / 255.0 green:242.0 / 255.0 blue:238.0 / 255.0 alpha:1.0f]
32 -#define PNLightGrey [UIColor colorWithRed:225.0/255.0 green:225.0/255.0 blue:225.0/255.0 alpha:1.0f] 33 +#define PNLightGrey [UIColor colorWithRed:225.0 / 255.0 green:225.0 / 255.0 blue:225.0 / 255.0 alpha:1.0f]
33 -#define PNCleanGrey [UIColor colorWithRed:251.0/255.0 green:251.0/255.0 blue:251.0/255.0 alpha:1.0f] 34 +#define PNCleanGrey [UIColor colorWithRed:251.0 / 255.0 green:251.0 / 255.0 blue:251.0 / 255.0 alpha:1.0f]
34 -#define PNLightYellow [UIColor colorWithRed:241.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0f] 35 +#define PNLightYellow [UIColor colorWithRed:241.0 / 255.0 green:240.0 / 255.0 blue:240.0 / 255.0 alpha:1.0f]
35 -#define PNDarkYellow [UIColor colorWithRed:152.0/255.0 green:150.0/255.0 blue:159.0/255.0 alpha:1.0f] 36 +#define PNDarkYellow [UIColor colorWithRed:152.0 / 255.0 green:150.0 / 255.0 blue:159.0 / 255.0 alpha:1.0f]
36 -#define PNPinkDark [UIColor colorWithRed:170.0/255.0 green:165.0/255.0 blue:165.0/255.0 alpha:1.0f] 37 +#define PNPinkDark [UIColor colorWithRed:170.0 / 255.0 green:165.0 / 255.0 blue:165.0 / 255.0 alpha:1.0f]
37 -#define PNCloudWhite [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0f] 38 +#define PNCloudWhite [UIColor colorWithRed:244.0 / 255.0 green:244.0 / 255.0 blue:244.0 / 255.0 alpha:1.0f]
38 -#define PNBlack [UIColor colorWithRed:45.0/255.0 green:45.0/255.0 blue:45.0/255.0 alpha:1.0f] 39 +#define PNBlack [UIColor colorWithRed:45.0 / 255.0 green:45.0 / 255.0 blue:45.0 / 255.0 alpha:1.0f]
39 -#define PNStarYellow [UIColor colorWithRed:252.0/255.0 green:223.0/255.0 blue:101.0/255.0 alpha:1.0f] 40 +#define PNStarYellow [UIColor colorWithRed:252.0 / 255.0 green:223.0 / 255.0 blue:101.0 / 255.0 alpha:1.0f]
40 -#define PNTwitterColor [UIColor colorWithRed:0.0/255.0 green:171.0/255.0 blue:243.0/255.0 alpha:1.0] 41 +#define PNTwitterColor [UIColor colorWithRed:0.0 / 255.0 green:171.0 / 255.0 blue:243.0 / 255.0 alpha:1.0]
41 -#define PNWeiboColor [UIColor colorWithRed:250.0/255.0 green:0.0/255.0 blue:33.0/255.0 alpha:1.0] 42 +#define PNWeiboColor [UIColor colorWithRed:250.0 / 255.0 green:0.0 / 255.0 blue:33.0 / 255.0 alpha:1.0]
42 -#define PNiOSGreenColor [UIColor colorWithRed:98.0/255.0 green:247.0/255.0 blue:77.0/255.0 alpha:1.0] 43 +#define PNiOSGreenColor [UIColor colorWithRed:98.0 / 255.0 green:247.0 / 255.0 blue:77.0 / 255.0 alpha:1.0]
43 44
44 45
45 @interface PNColor : NSObject 46 @interface PNColor : NSObject
46 47
47 -  
48 - (UIImage *)imageFromColor:(UIColor *)color; 48 - (UIImage *)imageFromColor:(UIColor *)color;
49 49
50 -  
51 @end 50 @end
@@ -10,19 +10,10 @@ @@ -10,19 +10,10 @@
10 10
11 @implementation PNColor 11 @implementation PNColor
12 12
13 --(id)init{ 13 +- (UIImage *)imageFromColor:(UIColor *)color
14 - if (self = [super init]) {  
15 -  
16 -  
17 - }  
18 - return self;  
19 -}  
20 -  
21 -  
22 -  
23 --(UIImage *)imageFromColor:(UIColor*)color  
24 { 14 {
25 CGRect rect = CGRectMake(0, 0, 1, 1); 15 CGRect rect = CGRectMake(0, 0, 1, 1);
  16 +
26 UIGraphicsBeginImageContext(rect.size); 17 UIGraphicsBeginImageContext(rect.size);
27 CGContextRef context = UIGraphicsGetCurrentContext(); 18 CGContextRef context = UIGraphicsGetCurrentContext();
28 CGContextSetFillColorWithColor(context, 19 CGContextSetFillColorWithColor(context,
@@ -35,6 +26,4 @@ @@ -35,6 +26,4 @@
35 } 26 }
36 27
37 28
38 -  
39 -  
40 @end 29 @end
@@ -6,14 +6,11 @@ @@ -6,14 +6,11 @@
6 // Copyright (c) 2013年 kevinzhow. All rights reserved. 6 // Copyright (c) 2013年 kevinzhow. All rights reserved.
7 // 7 //
8 8
9 -  
10 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
11 #import <QuartzCore/QuartzCore.h> 10 #import <QuartzCore/QuartzCore.h>
12 #import "PNChartDelegate.h" 11 #import "PNChartDelegate.h"
13 12
14 13
15 -  
16 -  
17 @interface PNLineChart : UIView 14 @interface PNLineChart : UIView
18 15
19 /** 16 /**
@@ -22,18 +19,18 @@ @@ -22,18 +19,18 @@
22 19
23 - (void)strokeChart; 20 - (void)strokeChart;
24 21
25 -@property(nonatomic,retain) id<PNChartDelegate> delegate; 22 +@property (nonatomic, retain) id<PNChartDelegate> delegate;
26 23
27 -@property (strong, nonatomic) NSArray * xLabels; 24 +@property (nonatomic) NSArray *xLabels;
28 25
29 -@property (strong, nonatomic) NSArray * yLabels; 26 +@property (nonatomic) NSArray *yLabels;
30 27
31 /** 28 /**
32 * Array of `LineChartData` objects, one for each line. 29 * Array of `LineChartData` objects, one for each line.
33 */ 30 */
34 -@property (strong, nonatomic) NSArray *chartData; 31 +@property (nonatomic) NSArray *chartData;
35 32
36 -@property (strong, nonatomic) NSMutableArray * pathPoints; 33 +@property (nonatomic) NSMutableArray *pathPoints;
37 34
38 @property (nonatomic) CGFloat xLabelWidth; 35 @property (nonatomic) CGFloat xLabelWidth;
39 36
This diff is collapsed. Click to expand it.
@@ -7,18 +7,12 @@ @@ -7,18 +7,12 @@
7 7
8 @class PNLineChartDataItem; 8 @class PNLineChartDataItem;
9 9
10 -  
11 typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item); 10 typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item);
12 11
13 -/** 12 +
14 -*  
15 -*/  
16 @interface PNLineChartData : NSObject 13 @interface PNLineChartData : NSObject
17 14
18 @property (strong) UIColor *color; 15 @property (strong) UIColor *color;
19 -  
20 @property NSUInteger itemCount; 16 @property NSUInteger itemCount;
21 -  
22 @property (copy) LCLineChartDataGetter getData; 17 @property (copy) LCLineChartDataGetter getData;
23 -  
24 @end 18 @end
@@ -5,10 +5,10 @@ @@ -5,10 +5,10 @@
5 5
6 #import <Foundation/Foundation.h> 6 #import <Foundation/Foundation.h>
7 7
8 -@interface PNLineChartDataItem : NSObject  
9 8
10 -@property (readonly) CGFloat y; // should be within the y range 9 +@interface PNLineChartDataItem : NSObject
11 10
12 + (PNLineChartDataItem *)dataItemWithY:(CGFloat)y; 11 + (PNLineChartDataItem *)dataItemWithY:(CGFloat)y;
13 12
  13 +@property (readonly) CGFloat y; // should be within the y range
14 @end 14 @end
@@ -5,30 +5,35 @@ @@ -5,30 +5,35 @@
5 5
6 #import "PNLineChartDataItem.h" 6 #import "PNLineChartDataItem.h"
7 7
  8 +
8 //------------------------------------------------------------------------------------------------ 9 //------------------------------------------------------------------------------------------------
9 // private interface declaration 10 // private interface declaration
10 //------------------------------------------------------------------------------------------------ 11 //------------------------------------------------------------------------------------------------
11 @interface PNLineChartDataItem () 12 @interface PNLineChartDataItem ()
  13 +- (id)initWithY:(CGFloat)y;
12 14
13 @property (readwrite) CGFloat y; // should be within the y range 15 @property (readwrite) CGFloat y; // should be within the y range
  16 +@end
14 17
15 -- (id)initWithY:(CGFloat)y;  
16 18
17 -@end  
18 19
19 //------------------------------------------------------------------------------------------------ 20 //------------------------------------------------------------------------------------------------
20 // public interface implementation 21 // public interface implementation
21 //------------------------------------------------------------------------------------------------ 22 //------------------------------------------------------------------------------------------------
22 @implementation PNLineChartDataItem 23 @implementation PNLineChartDataItem
23 24
24 -+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y { 25 ++ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y
  26 +{
25 return [[PNLineChartDataItem alloc] initWithY:y]; 27 return [[PNLineChartDataItem alloc] initWithY:y];
26 } 28 }
27 29
28 -- (id)initWithY:(CGFloat)y { 30 +
  31 +- (id)initWithY:(CGFloat)y
  32 +{
29 if ((self = [super init])) { 33 if ((self = [super init])) {
30 self.y = y; 34 self.y = y;
31 } 35 }
  36 +
32 return self; 37 return self;
33 } 38 }
34 39
@@ -7,4 +7,4 @@ DEPENDENCIES: @@ -7,4 +7,4 @@ DEPENDENCIES:
7 SPEC CHECKSUMS: 7 SPEC CHECKSUMS:
8 UICountingLabel: bb976960c0130785a600aac592954c23eb395096 8 UICountingLabel: bb976960c0130785a600aac592954c23eb395096
9 9
10 -COCOAPODS: 0.29.0 10 +COCOAPODS: 0.32.1