kevinzhow

Merge branch 'multiple-selection' of https://github.com/jerrygdm/PNChart into je…

…rrygdm-multiple-selection
@@ -46,6 +46,9 @@ @@ -46,6 +46,9 @@
46 46
47 @property (nonatomic, weak) id<PNChartDelegate> delegate; 47 @property (nonatomic, weak) id<PNChartDelegate> delegate;
48 48
  49 +/** Multiple selection */
  50 +@property (nonatomic, assign) BOOL enableMultipleSelection;
  51 +
49 - (void)strokeChart; 52 - (void)strokeChart;
50 53
51 @end 54 @end
@@ -23,6 +23,8 @@ @@ -23,6 +23,8 @@
23 @property (nonatomic) NSMutableArray *descriptionLabels; 23 @property (nonatomic) NSMutableArray *descriptionLabels;
24 @property (strong, nonatomic) CAShapeLayer *sectorHighlight; 24 @property (strong, nonatomic) CAShapeLayer *sectorHighlight;
25 25
  26 +@property (nonatomic, strong) NSMutableDictionary *selectedItems;
  27 +
26 - (void)loadDefault; 28 - (void)loadDefault;
27 29
28 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index; 30 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index;
@@ -48,6 +50,7 @@ @@ -48,6 +50,7 @@
48 self = [self initWithFrame:frame]; 50 self = [self initWithFrame:frame];
49 if(self){ 51 if(self){
50 _items = [NSArray arrayWithArray:items]; 52 _items = [NSArray arrayWithArray:items];
  53 + _selectedItems = [NSMutableDictionary dictionary];
51 _outerCircleRadius = CGRectGetWidth(self.bounds) / 2; 54 _outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
52 _innerCircleRadius = CGRectGetWidth(self.bounds) / 6; 55 _innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
53 56
@@ -57,6 +60,7 @@ @@ -57,6 +60,7 @@
57 _descriptionTextShadowOffset = CGSizeMake(0, 1); 60 _descriptionTextShadowOffset = CGSizeMake(0, 1);
58 _duration = 1.0; 61 _duration = 1.0;
59 _shouldHighlightSectorOnTouch = YES; 62 _shouldHighlightSectorOnTouch = YES;
  63 + _enableMultipleSelection = NO;
60 64
61 [super setupDefaultValues]; 65 [super setupDefaultValues];
62 [self loadDefault]; 66 [self loadDefault];
@@ -279,15 +283,17 @@ @@ -279,15 +283,17 @@
279 while (percentage > [self endPercentageForItemAtIndex:index]) { 283 while (percentage > [self endPercentageForItemAtIndex:index]) {
280 index ++; 284 index ++;
281 } 285 }
282 - 286 +
283 if ([self.delegate respondsToSelector:@selector(userClickedOnPieIndexItem:)]) { 287 if ([self.delegate respondsToSelector:@selector(userClickedOnPieIndexItem:)]) {
284 [self.delegate userClickedOnPieIndexItem:index]; 288 [self.delegate userClickedOnPieIndexItem:index];
285 } 289 }
286 290
287 - if (self.shouldHighlightSectorOnTouch) { 291 + if (self.shouldHighlightSectorOnTouch)
288 - 292 + {
289 - if (self.sectorHighlight) { 293 + if (!self.enableMultipleSelection)
290 - [self.sectorHighlight removeFromSuperlayer]; 294 + {
  295 + if (self.sectorHighlight)
  296 + [self.sectorHighlight removeFromSuperlayer];
291 } 297 }
292 298
293 PNPieChartDataItem *currentItem = [self dataItemForIndex:index]; 299 PNPieChartDataItem *currentItem = [self dataItemForIndex:index];
@@ -300,13 +306,33 @@ @@ -300,13 +306,33 @@
300 306
301 CGFloat startPercnetage = [self startPercentageForItemAtIndex:index]; 307 CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];
302 CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; 308 CGFloat endPercentage = [self endPercentageForItemAtIndex:index];
303 - self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 309 +
  310 + self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
304 borderWidth:10 311 borderWidth:10
305 fillColor:[UIColor clearColor] 312 fillColor:[UIColor clearColor]
306 borderColor:newColor 313 borderColor:newColor
307 startPercentage:startPercnetage 314 startPercentage:startPercnetage
308 endPercentage:endPercentage]; 315 endPercentage:endPercentage];
309 - [_contentView.layer addSublayer:self.sectorHighlight]; 316 +
  317 + if (self.enableMultipleSelection)
  318 + {
  319 + NSString *dictIndex = [NSString stringWithFormat:@"%d", index];
  320 + CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex];
  321 + if (indexShape)
  322 + {
  323 + [indexShape removeFromSuperlayer];
  324 + [self.selectedItems removeObjectForKey:dictIndex];
  325 + }
  326 + else
  327 + {
  328 + [self.selectedItems setObject:self.sectorHighlight forKey:dictIndex];
  329 + [_contentView.layer addSublayer:self.sectorHighlight];
  330 + }
  331 + }
  332 + else
  333 + {
  334 + [_contentView.layer addSublayer:self.sectorHighlight];
  335 + }
310 } 336 }
311 } 337 }
312 338
@@ -397,7 +423,7 @@ @@ -397,7 +423,7 @@
397 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + beforeLabel; 423 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + beforeLabel;
398 y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0; 424 y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0;
399 425
400 - 426 +
401 totalHeight = self.legendStyle == PNLegendItemStyleSerial ? fmaxf(totalHeight, rowMaxHeight + y) : totalHeight + labelsize.height; 427 totalHeight = self.legendStyle == PNLegendItemStyleSerial ? fmaxf(totalHeight, rowMaxHeight + y) : totalHeight + labelsize.height;
402 [legendViews addObject:label]; 428 [legendViews addObject:label];
403 counter ++; 429 counter ++;
@@ -422,7 +448,7 @@ @@ -422,7 +448,7 @@
422 CGContextRef context = UIGraphicsGetCurrentContext(); 448 CGContextRef context = UIGraphicsGetCurrentContext();
423 449
424 CGContextAddArc(context, size/2, size/ 2, size/2, 0, M_PI*2, YES); 450 CGContextAddArc(context, size/2, size/ 2, size/2, 0, M_PI*2, YES);
425 - 451 +
426 452
427 //Set some fill color 453 //Set some fill color
428 CGContextSetFillColorWithColor(context, color.CGColor); 454 CGContextSetFillColorWithColor(context, color.CGColor);
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
@@ -344,6 +344,15 @@ @@ -344,6 +344,15 @@
344 } 344 }
345 } 345 }
346 346
  347 +- (IBAction)centerSwitchChanged:(id)sender
  348 +{
  349 + if (self.pieChart)
  350 + {
  351 + [self.pieChart setEnableMultipleSelection:self.centerSwitch.on];
  352 + [self.pieChart strokeChart];
  353 + }
  354 +}
  355 +
347 - (IBAction)leftSwitchChanged:(id)sender { 356 - (IBAction)leftSwitchChanged:(id)sender {
348 if ([self.title isEqualToString:@"Pie Chart"]){ 357 if ([self.title isEqualToString:@"Pie Chart"]){
349 UISwitch *showRelative = (UISwitch*) sender; 358 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.35.0