Gianmaria Dal Maistro

Merge branch 'master' of github.com:jerrygdm/PNChart into HideValues-PieChart

Conflicts:
	PNChart/PNPieChart.h
	PNChart/PNPieChart.m
@@ -16,7 +16,7 @@ Pod::Spec.new do |s| @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16 # 16 #
17 17
18 s.name = "PNChart" 18 s.name = "PNChart"
19 - s.version = "0.8.5" 19 + s.version = "0.8.6"
20 s.summary = "A simple and beautiful chart lib with animation used in Piner for iOS" 20 s.summary = "A simple and beautiful chart lib with animation used in Piner for iOS"
21 21
22 s.description = <<-DESC 22 s.description = <<-DESC
@@ -90,7 +90,7 @@ Pod::Spec.new do |s| @@ -90,7 +90,7 @@ Pod::Spec.new do |s|
90 # Supports git, hg, bzr, svn and HTTP. 90 # Supports git, hg, bzr, svn and HTTP.
91 # 91 #
92 92
93 - s.source = { :git => "https://github.com/kevinzhow/PNChart.git", :tag => "0.8.5" } 93 + s.source = { :git => "https://github.com/kevinzhow/PNChart.git", :tag => s.version }
94 94
95 95
96 # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 96 # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
@@ -26,6 +26,9 @@ @@ -26,6 +26,9 @@
26 @property (nonatomic) CAShapeLayer *gradeLayer; 26 @property (nonatomic) CAShapeLayer *gradeLayer;
27 @property (nonatomic) CATextLayer* textLayer; 27 @property (nonatomic) CATextLayer* textLayer;
28 28
  29 +/** Text color for all bars in the chart. */
  30 +@property (nonatomic) UIColor * labelTextColor;
  31 +
29 @property (nonatomic, assign) BOOL isNegative; //!< 是否是负数 32 @property (nonatomic, assign) BOOL isNegative; //!< 是否是负数
30 @property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers 33 @property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers
31 @end 34 @end
@@ -181,7 +181,7 @@ @@ -181,7 +181,7 @@
181 _textLayer = [[CATextLayer alloc]init]; 181 _textLayer = [[CATextLayer alloc]init];
182 [_textLayer setString:@"0"]; 182 [_textLayer setString:@"0"];
183 [_textLayer setAlignmentMode:kCAAlignmentCenter]; 183 [_textLayer setAlignmentMode:kCAAlignmentCenter];
184 - [_textLayer setForegroundColor:[[UIColor colorWithRed:178/255.0 green:178/255. blue:178/255.0 alpha:1.0] CGColor]]; 184 + [_textLayer setForegroundColor:[_labelTextColor CGColor]];
185 _textLayer.hidden = YES; 185 _textLayer.hidden = YES;
186 186
187 } 187 }
@@ -189,6 +189,11 @@ @@ -189,6 +189,11 @@
189 return _textLayer; 189 return _textLayer;
190 } 190 }
191 191
  192 +- (void) setLabelTextColor:(UIColor *)labelTextColor {
  193 + _labelTextColor = labelTextColor;
  194 + [_textLayer setForegroundColor:[_labelTextColor CGColor]];
  195 +}
  196 +
192 -(void)setGradeFrame:(CGFloat)grade startPosY:(CGFloat)startPosY 197 -(void)setGradeFrame:(CGFloat)grade startPosY:(CGFloat)startPosY
193 { 198 {
194 CGFloat textheigt = self.bounds.size.height*self.grade; 199 CGFloat textheigt = self.bounds.size.height*self.grade;
@@ -52,7 +52,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); @@ -52,7 +52,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
52 /** Suffix to y label values, none if unset. */ 52 /** Suffix to y label values, none if unset. */
53 @property (nonatomic) NSString *yLabelSuffix; 53 @property (nonatomic) NSString *yLabelSuffix;
54 54
55 -@property (nonatomic) CGFloat chartMargin; 55 +@property (nonatomic) CGFloat chartMarginLeft;
  56 +@property (nonatomic) CGFloat chartMarginRight;
  57 +@property (nonatomic) CGFloat chartMarginTop;
  58 +@property (nonatomic) CGFloat chartMarginBottom;
56 59
57 /** Controls whether labels should be displayed. */ 60 /** Controls whether labels should be displayed. */
58 @property (nonatomic) BOOL showLabel; 61 @property (nonatomic) BOOL showLabel;
@@ -60,6 +63,8 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); @@ -60,6 +63,8 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
60 /** Controls whether the chart border line should be displayed. */ 63 /** Controls whether the chart border line should be displayed. */
61 @property (nonatomic) BOOL showChartBorder; 64 @property (nonatomic) BOOL showChartBorder;
62 65
  66 +@property (nonatomic) UIColor *chartBorderColor;
  67 +
63 /** Controls whether the chart Horizontal separator should be displayed. */ 68 /** Controls whether the chart Horizontal separator should be displayed. */
64 @property (nonatomic, assign) BOOL showLevelLine; 69 @property (nonatomic, assign) BOOL showLevelLine;
65 70
@@ -56,9 +56,13 @@ @@ -56,9 +56,13 @@
56 _xLabelSkip = 1; 56 _xLabelSkip = 1;
57 _yLabelSum = 4; 57 _yLabelSum = 4;
58 _labelMarginTop = 0; 58 _labelMarginTop = 0;
59 - _chartMargin = 25.0; 59 + _chartMarginLeft = 25.0;
  60 + _chartMarginRight = 25.0;
  61 + _chartMarginTop = 25.0;
  62 + _chartMarginBottom = 25.0;
60 _barRadius = 2.0; 63 _barRadius = 2.0;
61 _showChartBorder = NO; 64 _showChartBorder = NO;
  65 + _chartBorderColor = PNLightGrey;
62 _showLevelLine = NO; 66 _showLevelLine = NO;
63 _yChartLabelWidth = 18; 67 _yChartLabelWidth = 18;
64 _rotateForXAxisText = false; 68 _rotateForXAxisText = false;
@@ -106,7 +110,8 @@ @@ -106,7 +110,8 @@
106 110
107 [self processYMaxValue]; 111 [self processYMaxValue];
108 112
109 - float sectionHeight = (self.frame.size.height - _chartMargin * 2 - kXLabelHeight) / _yLabelSum; 113 + float sectionHeight = (self.frame.size.height - _chartMarginTop - _chartMarginBottom - kXLabelHeight) / _yLabelSum;
  114 +
110 for (int i = 0; i <= _yLabelSum; i++) { 115 for (int i = 0; i <= _yLabelSum; i++) {
111 NSString *labelText; 116 NSString *labelText;
112 if (_yLabels) { 117 if (_yLabels) {
@@ -116,14 +121,16 @@ @@ -116,14 +121,16 @@
116 labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - i) / (float)_yLabelSum )); 121 labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - i) / (float)_yLabelSum ));
117 } 122 }
118 123
119 - CGRect frame = (CGRect){0, sectionHeight * i + _chartMargin - kYLabelHeight/2.0, _yChartLabelWidth, kYLabelHeight}; 124 + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectZero];
120 - PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:frame];  
121 label.font = _labelFont; 125 label.font = _labelFont;
122 label.textColor = _labelTextColor; 126 label.textColor = _labelTextColor;
123 [label setTextAlignment:NSTextAlignmentRight]; 127 [label setTextAlignment:NSTextAlignmentRight];
124 label.text = [NSString stringWithFormat:@"%@%@%@", _yLabelPrefix, labelText, _yLabelSuffix]; 128 label.text = [NSString stringWithFormat:@"%@%@%@", _yLabelPrefix, labelText, _yLabelSuffix];
  129 +
125 [self addSubview:label]; 130 [self addSubview:label];
126 131
  132 + label.frame = (CGRect){0, sectionHeight * i + _chartMarginTop - kYLabelHeight/2.0, _yChartLabelWidth, kYLabelHeight};
  133 +
127 [_yChartLabels addObject:label]; 134 [_yChartLabels addObject:label];
128 } 135 }
129 } 136 }
@@ -155,7 +162,7 @@ @@ -155,7 +162,7 @@
155 _xChartLabels = [NSMutableArray new]; 162 _xChartLabels = [NSMutableArray new];
156 } 163 }
157 164
158 - _xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [xLabels count]; 165 + _xLabelWidth = (self.frame.size.width - _chartMarginLeft - _chartMarginRight) / [xLabels count];
159 166
160 if (_showLabel) { 167 if (_showLabel) {
161 int labelAddCount = 0; 168 int labelAddCount = 0;
@@ -173,13 +180,13 @@ @@ -173,13 +180,13 @@
173 CGFloat labelXPosition; 180 CGFloat labelXPosition;
174 if (_rotateForXAxisText){ 181 if (_rotateForXAxisText){
175 label.transform = CGAffineTransformMakeRotation(M_PI / 4); 182 label.transform = CGAffineTransformMakeRotation(M_PI / 4);
176 - labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /1.5); 183 + labelXPosition = (index * _xLabelWidth + _chartMarginLeft + _xLabelWidth /1.5);
177 } 184 }
178 else{ 185 else{
179 - labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 ); 186 + labelXPosition = (index * _xLabelWidth + _chartMarginLeft + _xLabelWidth /2.0 );
180 } 187 }
181 label.center = CGPointMake(labelXPosition, 188 label.center = CGPointMake(labelXPosition,
182 - self.frame.size.height - kXLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop); 189 + self.frame.size.height - kXLabelHeight - _chartMarginTop + label.frame.size.height /2.0 + _labelMarginTop);
183 labelAddCount = 0; 190 labelAddCount = 0;
184 191
185 [_xChartLabels addObject:label]; 192 [_xChartLabels addObject:label];
@@ -199,7 +206,7 @@ @@ -199,7 +206,7 @@
199 { 206 {
200 207
201 //Add bars 208 //Add bars
202 - CGFloat chartCavanHeight = self.frame.size.height - _chartMargin * 2 - kXLabelHeight; 209 + CGFloat chartCavanHeight = self.frame.size.height - _chartMarginTop - _chartMarginBottom - kXLabelHeight;
203 NSInteger index = 0; 210 NSInteger index = 0;
204 211
205 for (NSNumber *valueString in _yValues) { 212 for (NSNumber *valueString in _yValues) {
@@ -214,9 +221,9 @@ @@ -214,9 +221,9 @@
214 221
215 if (_barWidth) { 222 if (_barWidth) {
216 barWidth = _barWidth; 223 barWidth = _barWidth;
217 - barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 - _barWidth /2.0; 224 + barXPosition = index * _xLabelWidth + _chartMarginLeft + _xLabelWidth /2.0 - _barWidth /2.0;
218 }else{ 225 }else{
219 - barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth * 0.25; 226 + barXPosition = index * _xLabelWidth + _chartMarginLeft + _xLabelWidth * 0.25;
220 if (_showLabel) { 227 if (_showLabel) {
221 barWidth = _xLabelWidth * 0.5; 228 barWidth = _xLabelWidth * 0.5;
222 229
@@ -228,7 +235,7 @@ @@ -228,7 +235,7 @@
228 } 235 }
229 236
230 bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position 237 bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position
231 - self.frame.size.height - chartCavanHeight - kXLabelHeight - _chartMargin , //Bar Y position 238 + self.frame.size.height - chartCavanHeight - kXLabelHeight - _chartMarginBottom + _chartMarginTop , //Bar Y position
232 barWidth, // Bar witdh 239 barWidth, // Bar witdh
233 self.showLevelLine ? chartCavanHeight/2.0:chartCavanHeight)]; //Bar height 240 self.showLevelLine ? chartCavanHeight/2.0:chartCavanHeight)]; //Bar height
234 241
@@ -244,6 +251,10 @@ @@ -244,6 +251,10 @@
244 bar.barColor = [self barColorAtIndex:index]; 251 bar.barColor = [self barColorAtIndex:index];
245 } 252 }
246 253
  254 + if (self.labelTextColor) {
  255 + bar.labelTextColor = self.labelTextColor;
  256 + }
  257 +
247 // Add gradient 258 // Add gradient
248 if (self.isGradientShow) { 259 if (self.isGradientShow) {
249 bar.barColorGradientStart = bar.barColor; 260 bar.barColorGradientStart = bar.barColor;
@@ -303,13 +314,13 @@ @@ -303,13 +314,13 @@
303 314
304 UIBezierPath *progressline = [UIBezierPath bezierPath]; 315 UIBezierPath *progressline = [UIBezierPath bezierPath];
305 316
306 - [progressline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - kXLabelHeight - _chartMargin)]; 317 + [progressline moveToPoint:CGPointMake(_chartMarginLeft, self.frame.size.height - kXLabelHeight - _chartMarginBottom + _chartMarginTop)];
307 - [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, self.frame.size.height - kXLabelHeight - _chartMargin)]; 318 + [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMarginRight, self.frame.size.height - kXLabelHeight - _chartMarginBottom + _chartMarginTop)];
308 319
309 [progressline setLineWidth:1.0]; 320 [progressline setLineWidth:1.0];
310 [progressline setLineCapStyle:kCGLineCapSquare]; 321 [progressline setLineCapStyle:kCGLineCapSquare];
311 _chartBottomLine.path = progressline.CGPath; 322 _chartBottomLine.path = progressline.CGPath;
312 - _chartBottomLine.strokeColor = PNLightGrey.CGColor; 323 + _chartBottomLine.strokeColor = [_chartBorderColor CGColor];;
313 324
314 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 325 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
315 pathAnimation.duration = 0.5; 326 pathAnimation.duration = 0.5;
@@ -332,13 +343,13 @@ @@ -332,13 +343,13 @@
332 343
333 UIBezierPath *progressLeftline = [UIBezierPath bezierPath]; 344 UIBezierPath *progressLeftline = [UIBezierPath bezierPath];
334 345
335 - [progressLeftline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - kXLabelHeight - _chartMargin)]; 346 + [progressLeftline moveToPoint:CGPointMake(_chartMarginLeft, self.frame.size.height - kXLabelHeight - _chartMarginBottom + _chartMarginTop)];
336 - [progressLeftline addLineToPoint:CGPointMake(_chartMargin, _chartMargin)]; 347 + [progressLeftline addLineToPoint:CGPointMake(_chartMarginLeft, _chartMarginTop)];
337 348
338 [progressLeftline setLineWidth:1.0]; 349 [progressLeftline setLineWidth:1.0];
339 [progressLeftline setLineCapStyle:kCGLineCapSquare]; 350 [progressLeftline setLineCapStyle:kCGLineCapSquare];
340 _chartLeftLine.path = progressLeftline.CGPath; 351 _chartLeftLine.path = progressLeftline.CGPath;
341 - _chartLeftLine.strokeColor = PNLightGrey.CGColor; 352 + _chartLeftLine.strokeColor = [_chartBorderColor CGColor];
342 353
343 CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 354 CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
344 pathLeftAnimation.duration = 0.5; 355 pathLeftAnimation.duration = 0.5;
@@ -362,8 +373,8 @@ @@ -362,8 +373,8 @@
362 373
363 UIBezierPath *progressline = [UIBezierPath bezierPath]; 374 UIBezierPath *progressline = [UIBezierPath bezierPath];
364 375
365 - [progressline moveToPoint:CGPointMake(_chartMargin, (self.frame.size.height - kXLabelHeight )/2.0)]; 376 + [progressline moveToPoint:CGPointMake(_chartMarginLeft, (self.frame.size.height - kXLabelHeight )/2.0)];
366 - [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, (self.frame.size.height - kXLabelHeight )/2.0)]; 377 + [progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMarginLeft - _chartMarginRight, (self.frame.size.height - kXLabelHeight )/2.0)];
367 378
368 [progressline setLineWidth:1.0]; 379 [progressline setLineWidth:1.0];
369 [progressline setLineCapStyle:kCGLineCapSquare]; 380 [progressline setLineCapStyle:kCGLineCapSquare];
@@ -13,7 +13,9 @@ @@ -13,7 +13,9 @@
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 + PNChartFormatTypeDecimal,
  18 + PNChartFormatTypeDecimalTwoPlaces,
17 }; 19 };
18 20
19 #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) 21 #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
@@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
46 current:current 46 current:current
47 clockwise:clockwise 47 clockwise:clockwise
48 shadow:shadow 48 shadow:shadow
49 - shadowColor:PNGreen 49 + shadowColor:backgroundShadowColor
50 displayCountingLabel:displayCountingLabel 50 displayCountingLabel:displayCountingLabel
51 overrideLineWidth:@8.0f]; 51 overrideLineWidth:@8.0f];
52 52
@@ -131,6 +131,12 @@ displayCountingLabel:(BOOL)displayCountingLabel @@ -131,6 +131,12 @@ displayCountingLabel:(BOOL)displayCountingLabel
131 case PNChartFormatTypeDollar: 131 case PNChartFormatTypeDollar:
132 format = @"$%d"; 132 format = @"$%d";
133 break; 133 break;
  134 + case PNChartFormatTypeDecimal:
  135 + format = @"%.1f";
  136 + break;
  137 + case PNChartFormatTypeDecimalTwoPlaces:
  138 + format = @"%.2f";
  139 + break;
134 case PNChartFormatTypeNone: 140 case PNChartFormatTypeNone:
135 default: 141 default:
136 format = @"%d"; 142 format = @"%d";
@@ -45,11 +45,14 @@ @@ -45,11 +45,14 @@
45 @property (nonatomic) UIColor *yLabelColor; 45 @property (nonatomic) UIColor *yLabelColor;
46 @property (nonatomic) CGFloat chartCavanHeight; 46 @property (nonatomic) CGFloat chartCavanHeight;
47 @property (nonatomic) CGFloat chartCavanWidth; 47 @property (nonatomic) CGFloat chartCavanWidth;
48 -@property (nonatomic) CGFloat chartMargin;  
49 @property (nonatomic) BOOL showLabel; 48 @property (nonatomic) BOOL showLabel;
50 @property (nonatomic) BOOL showGenYLabels; 49 @property (nonatomic) BOOL showGenYLabels;
51 @property (nonatomic) BOOL thousandsSeparator; 50 @property (nonatomic) BOOL thousandsSeparator;
52 51
  52 +@property (nonatomic) CGFloat chartMarginLeft;
  53 +@property (nonatomic) CGFloat chartMarginRight;
  54 +@property (nonatomic) CGFloat chartMarginTop;
  55 +@property (nonatomic) CGFloat chartMarginBottom;
53 56
54 /** 57 /**
55 * Controls whether to show the coordinate axis. Default is NO. 58 * Controls whether to show the coordinate axis. Default is NO.
This diff is collapsed. Click to expand it.
@@ -25,6 +25,11 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item); @@ -25,6 +25,11 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item);
25 @property (copy) LCLineChartDataGetter getData; 25 @property (copy) LCLineChartDataGetter getData;
26 @property (strong, nonatomic) NSString *dataTitle; 26 @property (strong, nonatomic) NSString *dataTitle;
27 27
  28 +@property (nonatomic) BOOL showPointLabel;
  29 +@property (nonatomic) UIColor *pointLabelColor;
  30 +@property (nonatomic) UIFont *pointLabelFont;
  31 +@property (nonatomic) NSString *pointLabelFormat;
  32 +
28 @property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle; 33 @property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle;
29 34
30 /** 35 /**
@@ -23,6 +23,9 @@ @@ -23,6 +23,9 @@
23 _inflexionPointWidth = 6.f; 23 _inflexionPointWidth = 6.f;
24 _lineWidth = 2.f; 24 _lineWidth = 2.f;
25 _alpha = 1.f; 25 _alpha = 1.f;
  26 + _showPointLabel = NO;
  27 + _pointLabelColor = [UIColor blackColor];
  28 + _pointLabelFormat = @"%1.f";
26 } 29 }
27 30
28 @end 31 @end
@@ -9,7 +9,9 @@ @@ -9,7 +9,9 @@
9 @interface PNLineChartDataItem : NSObject 9 @interface PNLineChartDataItem : NSObject
10 10
11 + (PNLineChartDataItem *)dataItemWithY:(CGFloat)y; 11 + (PNLineChartDataItem *)dataItemWithY:(CGFloat)y;
  12 ++ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y andRawY:(CGFloat)rawY;
12 13
13 @property (readonly) CGFloat y; // should be within the y range 14 @property (readonly) CGFloat y; // should be within the y range
  15 +@property (readonly) CGFloat rawY; // this is the raw value, used for point label.
14 16
15 @end 17 @end
@@ -7,9 +7,10 @@ @@ -7,9 +7,10 @@
7 7
8 @interface PNLineChartDataItem () 8 @interface PNLineChartDataItem ()
9 9
10 -- (id)initWithY:(CGFloat)y; 10 +- (id)initWithY:(CGFloat)y andRawY:(CGFloat)rawY;
11 11
12 @property (readwrite) CGFloat y; // should be within the y range 12 @property (readwrite) CGFloat y; // should be within the y range
  13 +@property (readwrite) CGFloat rawY; // this is the raw value, used for point label.
13 14
14 @end 15 @end
15 16
@@ -17,13 +18,18 @@ @@ -17,13 +18,18 @@
17 18
18 + (PNLineChartDataItem *)dataItemWithY:(CGFloat)y 19 + (PNLineChartDataItem *)dataItemWithY:(CGFloat)y
19 { 20 {
20 - return [[PNLineChartDataItem alloc] initWithY:y]; 21 + return [[PNLineChartDataItem alloc] initWithY:y andRawY:y];
21 } 22 }
22 23
23 -- (id)initWithY:(CGFloat)y 24 ++ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y andRawY:(CGFloat)rawY {
  25 + return [[PNLineChartDataItem alloc] initWithY:y andRawY:rawY];
  26 +}
  27 +
  28 +- (id)initWithY:(CGFloat)y andRawY:(CGFloat)rawY
24 { 29 {
25 if ((self = [super init])) { 30 if ((self = [super init])) {
26 self.y = y; 31 self.y = y;
  32 + self.rawY = rawY;
27 } 33 }
28 34
29 return self; 35 return self;
@@ -32,9 +32,6 @@ @@ -32,9 +32,6 @@
32 /** Default is 1.0. */ 32 /** Default is 1.0. */
33 @property (nonatomic) NSTimeInterval duration; 33 @property (nonatomic) NSTimeInterval duration;
34 34
35 -/** show only tiles, not values or percentage */  
36 -@property (nonatomic) BOOL hideValues;  
37 -  
38 /** Show only values, this is useful when legend is present */ 35 /** Show only values, this is useful when legend is present */
39 @property (nonatomic) BOOL showOnlyValues; 36 @property (nonatomic) BOOL showOnlyValues;
40 37
@@ -47,11 +44,29 @@ @@ -47,11 +44,29 @@
47 /** Default YES. */ 44 /** Default YES. */
48 @property (nonatomic) BOOL shouldHighlightSectorOnTouch; 45 @property (nonatomic) BOOL shouldHighlightSectorOnTouch;
49 46
  47 +/** Current outer radius. Override recompute() to change this. **/
  48 +@property (nonatomic) CGFloat outerCircleRadius;
  49 +
  50 +/** Current inner radius. Override recompute() to change this. **/
  51 +@property (nonatomic) CGFloat innerCircleRadius;
  52 +
50 @property (nonatomic, weak) id<PNChartDelegate> delegate; 53 @property (nonatomic, weak) id<PNChartDelegate> delegate;
51 54
  55 +/** Update chart items. Does not update chart itself. */
  56 +- (void)updateChartData:(NSArray *)data;
  57 +
52 /** Multiple selection */ 58 /** Multiple selection */
53 @property (nonatomic, assign) BOOL enableMultipleSelection; 59 @property (nonatomic, assign) BOOL enableMultipleSelection;
54 60
  61 +/** show only tiles, not values or percentage */
  62 +@property (nonatomic) BOOL hideValues;
  63 +
55 - (void)strokeChart; 64 - (void)strokeChart;
56 65
  66 +- (void)recompute;
  67 +
  68 +<<<<<<< Updated upstream
  69 +@end
  70 +=======
57 @end 71 @end
  72 +>>>>>>> Stashed changes
@@ -15,14 +15,13 @@ @@ -15,14 +15,13 @@
15 @property (nonatomic) NSArray *items; 15 @property (nonatomic) NSArray *items;
16 @property (nonatomic) NSArray *endPercentages; 16 @property (nonatomic) NSArray *endPercentages;
17 17
18 -@property (nonatomic) CGFloat outerCircleRadius;  
19 -@property (nonatomic) CGFloat innerCircleRadius;  
20 -  
21 @property (nonatomic) UIView *contentView; 18 @property (nonatomic) UIView *contentView;
22 @property (nonatomic) CAShapeLayer *pieLayer; 19 @property (nonatomic) CAShapeLayer *pieLayer;
23 @property (nonatomic) NSMutableArray *descriptionLabels; 20 @property (nonatomic) NSMutableArray *descriptionLabels;
24 @property (strong, nonatomic) CAShapeLayer *sectorHighlight; 21 @property (strong, nonatomic) CAShapeLayer *sectorHighlight;
25 22
  23 +@property (nonatomic, strong) NSMutableDictionary *selectedItems;
  24 +
26 - (void)loadDefault; 25 - (void)loadDefault;
27 26
28 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index; 27 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index;
@@ -48,9 +47,9 @@ @@ -48,9 +47,9 @@
48 self = [self initWithFrame:frame]; 47 self = [self initWithFrame:frame];
49 if(self){ 48 if(self){
50 _items = [NSArray arrayWithArray:items]; 49 _items = [NSArray arrayWithArray:items];
  50 + _selectedItems = [NSMutableDictionary dictionary];
51 _outerCircleRadius = CGRectGetWidth(self.bounds) / 2; 51 _outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
52 _innerCircleRadius = CGRectGetWidth(self.bounds) / 6; 52 _innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
53 -  
54 _descriptionTextColor = [UIColor whiteColor]; 53 _descriptionTextColor = [UIColor whiteColor];
55 _descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0]; 54 _descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0];
56 _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; 55 _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
@@ -88,12 +87,20 @@ @@ -88,12 +87,20 @@
88 87
89 _pieLayer = [CAShapeLayer layer]; 88 _pieLayer = [CAShapeLayer layer];
90 [_contentView.layer addSublayer:_pieLayer]; 89 [_contentView.layer addSublayer:_pieLayer];
  90 +
  91 +}
  92 +
  93 +/** Override this to change how inner attributes are computed. **/
  94 +- (void)recompute {
  95 + self.outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
  96 + self.innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
91 } 97 }
92 98
93 #pragma mark - 99 #pragma mark -
94 100
95 - (void)strokeChart{ 101 - (void)strokeChart{
96 [self loadDefault]; 102 [self loadDefault];
  103 + [self recompute];
97 104
98 PNPieChartDataItem *currentItem; 105 PNPieChartDataItem *currentItem;
99 for (int i = 0; i < _items.count; i++) { 106 for (int i = 0; i < _items.count; i++) {
@@ -174,6 +181,10 @@ @@ -174,6 +181,10 @@
174 return descriptionLabel; 181 return descriptionLabel;
175 } 182 }
176 183
  184 +- (void)updateChartData:(NSArray *)items {
  185 + self.items = items;
  186 +}
  187 +
177 - (PNPieChartDataItem *)dataItemForIndex:(NSUInteger)index{ 188 - (PNPieChartDataItem *)dataItemForIndex:(NSUInteger)index{
178 return self.items[index]; 189 return self.items[index];
179 } 190 }
@@ -289,9 +300,11 @@ @@ -289,9 +300,11 @@
289 [self.delegate userClickedOnPieIndexItem:index]; 300 [self.delegate userClickedOnPieIndexItem:index];
290 } 301 }
291 302
292 - if (self.shouldHighlightSectorOnTouch) { 303 + if (self.shouldHighlightSectorOnTouch)
293 - 304 + {
294 - if (self.sectorHighlight) { 305 + if (!self.enableMultipleSelection)
  306 + {
  307 + if (self.sectorHighlight)
295 [self.sectorHighlight removeFromSuperlayer]; 308 [self.sectorHighlight removeFromSuperlayer];
296 } 309 }
297 310
@@ -305,14 +318,34 @@ @@ -305,14 +318,34 @@
305 318
306 CGFloat startPercnetage = [self startPercentageForItemAtIndex:index]; 319 CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];
307 CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; 320 CGFloat endPercentage = [self endPercentageForItemAtIndex:index];
  321 +
308 self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 322 self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
309 borderWidth:10 323 borderWidth:10
310 fillColor:[UIColor clearColor] 324 fillColor:[UIColor clearColor]
311 borderColor:newColor 325 borderColor:newColor
312 startPercentage:startPercnetage 326 startPercentage:startPercnetage
313 endPercentage:endPercentage]; 327 endPercentage:endPercentage];
  328 +
  329 + if (self.enableMultipleSelection)
  330 + {
  331 + NSString *dictIndex = [NSString stringWithFormat:@"%d", index];
  332 + CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex];
  333 + if (indexShape)
  334 + {
  335 + [indexShape removeFromSuperlayer];
  336 + [self.selectedItems removeObjectForKey:dictIndex];
  337 + }
  338 + else
  339 + {
  340 + [self.selectedItems setObject:self.sectorHighlight forKey:dictIndex];
  341 + [_contentView.layer addSublayer:self.sectorHighlight];
  342 + }
  343 + }
  344 + else
  345 + {
314 [_contentView.layer addSublayer:self.sectorHighlight]; 346 [_contentView.layer addSublayer:self.sectorHighlight];
315 } 347 }
  348 + }
316 } 349 }
317 350
318 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 351 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
@@ -448,4 +481,11 @@ @@ -448,4 +481,11 @@
448 [squareImageView setFrame:CGRectMake(originX, originY, size, size)]; 481 [squareImageView setFrame:CGRectMake(originX, originY, size, size)];
449 return squareImageView; 482 return squareImageView;
450 } 483 }
  484 +
  485 +/* Redraw the chart on autolayout */
  486 +-(void)layoutSubviews {
  487 + [super layoutSubviews];
  488 + [self strokeChart];
  489 +}
  490 +
451 @end 491 @end
1 -<?xml version='1.0' encoding='UTF-8'?><Workspace version='1.0'><FileRef location='group:PNChartDemo.xcodeproj'/><FileRef location='group:Pods/Pods.xcodeproj'/></Workspace> 1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<Workspace
  3 + version = "1.0">
  4 + <FileRef
  5 + location = "group:PNChartDemo.xcodeproj">
  6 + </FileRef>
  7 + <FileRef
  8 + location = "group:Pods/Pods.xcodeproj">
  9 + </FileRef>
  10 +</Workspace>
This diff is collapsed. Click to expand it.
@@ -25,12 +25,13 @@ @@ -25,12 +25,13 @@
25 @property (weak, nonatomic) IBOutlet UIButton *changeValueButton; 25 @property (weak, nonatomic) IBOutlet UIButton *changeValueButton;
26 26
27 @property (weak, nonatomic) IBOutlet UISwitch *leftSwitch; 27 @property (weak, nonatomic) IBOutlet UISwitch *leftSwitch;
  28 +@property (weak, nonatomic) IBOutlet UISwitch *centerSwitch;
28 @property (weak, nonatomic) IBOutlet UISwitch *rightSwitch; 29 @property (weak, nonatomic) IBOutlet UISwitch *rightSwitch;
29 @property (weak, nonatomic) IBOutlet UILabel *leftLabel; 30 @property (weak, nonatomic) IBOutlet UILabel *leftLabel;
30 @property (weak, nonatomic) IBOutlet UILabel *rightLabel; 31 @property (weak, nonatomic) IBOutlet UILabel *rightLabel;
31 32
32 - (IBAction)rightSwitchChanged:(id)sender; 33 - (IBAction)rightSwitchChanged:(id)sender;
33 - (IBAction)leftSwitchChanged:(id)sender; 34 - (IBAction)leftSwitchChanged:(id)sender;
34 - 35 +- (IBAction)rightSwitchChanged:(id)sender;
35 36
36 @end 37 @end
@@ -91,20 +91,34 @@ @@ -91,20 +91,34 @@
91 } 91 }
92 else if ([self.title isEqualToString:@"Bar Chart"]) 92 else if ([self.title isEqualToString:@"Bar Chart"])
93 { 93 {
  94 + static NSNumberFormatter *barChartFormatter;
  95 + if (!barChartFormatter){
  96 + barChartFormatter = [[NSNumberFormatter alloc] init];
  97 + barChartFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
  98 + barChartFormatter.allowsFloats = NO;
  99 + barChartFormatter.maximumFractionDigits = 0;
  100 + }
94 self.titleLabel.text = @"Bar Chart"; 101 self.titleLabel.text = @"Bar Chart";
95 102
96 self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)]; 103 self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
97 // self.barChart.showLabel = NO; 104 // self.barChart.showLabel = NO;
98 self.barChart.backgroundColor = [UIColor clearColor]; 105 self.barChart.backgroundColor = [UIColor clearColor];
99 self.barChart.yLabelFormatter = ^(CGFloat yValue){ 106 self.barChart.yLabelFormatter = ^(CGFloat yValue){
100 - CGFloat yValueParsed = yValue; 107 + return [barChartFormatter stringFromNumber:[NSNumber numberWithFloat:yValue]];
101 - NSString * labelText = [NSString stringWithFormat:@"%0.f",yValueParsed];  
102 - return labelText;  
103 }; 108 };
  109 +
  110 + self.barChart.yChartLabelWidth = 20.0;
  111 + self.barChart.chartMarginLeft = 30.0;
  112 + self.barChart.chartMarginRight = 10.0;
  113 + self.barChart.chartMarginTop = 5.0;
  114 + self.barChart.chartMarginBottom = 10.0;
  115 +
  116 +
104 self.barChart.labelMarginTop = 5.0; 117 self.barChart.labelMarginTop = 5.0;
105 self.barChart.showChartBorder = YES; 118 self.barChart.showChartBorder = YES;
106 [self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]]; 119 [self.barChart setXLabels:@[@"2",@"3",@"4",@"5",@"2",@"3",@"4",@"5"]];
107 // self.barChart.yLabels = @[@-10,@0,@10]; 120 // self.barChart.yLabels = @[@-10,@0,@10];
  121 +// [self.barChart setYValues:@[@10000.0,@30000.0,@10000.0,@100000.0,@500000.0,@1000000.0,@1150000.0,@2150000.0]];
108 [self.barChart setYValues:@[@10.82,@1.88,@6.96,@33.93,@10.82,@1.88,@6.96,@33.93]]; 122 [self.barChart setYValues:@[@10.82,@1.88,@6.96,@33.93,@10.82,@1.88,@6.96,@33.93]];
109 [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]]; 123 [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen,PNGreen,PNGreen,PNRed,PNGreen]];
110 self.barChart.isGradientShow = NO; 124 self.barChart.isGradientShow = NO;
@@ -344,6 +358,15 @@ @@ -344,6 +358,15 @@
344 } 358 }
345 } 359 }
346 360
  361 +- (IBAction)centerSwitchChanged:(id)sender
  362 +{
  363 + if (self.pieChart)
  364 + {
  365 + [self.pieChart setEnableMultipleSelection:self.centerSwitch.on];
  366 + [self.pieChart strokeChart];
  367 + }
  368 +}
  369 +
347 - (IBAction)leftSwitchChanged:(id)sender { 370 - (IBAction)leftSwitchChanged:(id)sender {
348 if ([self.title isEqualToString:@"Pie Chart"]){ 371 if ([self.title isEqualToString:@"Pie Chart"]){
349 UISwitch *showRelative = (UISwitch*) sender; 372 UISwitch *showRelative = (UISwitch*) sender;
1 PODS: 1 PODS:
2 - - Expecta (0.4.2) 2 + - Expecta (1.0.2)
3 - UICountingLabel (1.2.0) 3 - UICountingLabel (1.2.0)
4 4
5 DEPENDENCIES: 5 DEPENDENCIES:
@@ -7,7 +7,7 @@ DEPENDENCIES: @@ -7,7 +7,7 @@ DEPENDENCIES:
7 - UICountingLabel (~> 1.2.0) 7 - UICountingLabel (~> 1.2.0)
8 8
9 SPEC CHECKSUMS: 9 SPEC CHECKSUMS:
10 - Expecta: 78b4e8b0c8291fa4524d7f74016b6065c2e391ec 10 + Expecta: 54e8a3530add08f4f0208c111355eda7cde74a53
11 UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa 11 UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa
12 12
13 COCOAPODS: 0.38.2 13 COCOAPODS: 0.38.2
@@ -10,7 +10,10 @@ A simple and beautiful chart lib with **animation** used in [Piner](https://itun @@ -10,7 +10,10 @@ A simple and beautiful chart lib with **animation** used in [Piner](https://itun
10 10
11 ## Requirements 11 ## Requirements
12 12
13 -PNChart works on iOS 6.0 (Begin with 0.8.2 supports iOS 8 and Later only, if you are working with iOS 6 and iOS 7, use 0.8.1 instead.) and later version and is compatible with ARC projects. It depends on the following Apple frameworks, which should already be included with most Xcode templates: 13 +PNChart works on iOS 7.0+ and is compatible with ARC projects.
  14 +If you need support for iOS 6, use PNChart <= 0.8.1. Note that 0.8.2 supports iOS 8.0+ only, 0.8.3 and newer supports iOS 7.0+.
  15 +
  16 +It depends on the following Apple frameworks, which should already be included with most Xcode templates:
14 17
15 * Foundation.framework 18 * Foundation.framework
16 * UIKit.framework 19 * UIKit.framework