kevinzhow

Merge branch 'jerrygdm-multiple-selection'

@@ -55,6 +55,9 @@ @@ -55,6 +55,9 @@
55 /** Update chart items. Does not update chart itself. */ 55 /** Update chart items. Does not update chart itself. */
56 - (void)updateChartData:(NSArray *)data; 56 - (void)updateChartData:(NSArray *)data;
57 57
  58 +/** Multiple selection */
  59 +@property (nonatomic, assign) BOOL enableMultipleSelection;
  60 +
58 - (void)strokeChart; 61 - (void)strokeChart;
59 62
60 - (void)recompute; 63 - (void)recompute;
@@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
20 @property (nonatomic) NSMutableArray *descriptionLabels; 20 @property (nonatomic) NSMutableArray *descriptionLabels;
21 @property (strong, nonatomic) CAShapeLayer *sectorHighlight; 21 @property (strong, nonatomic) CAShapeLayer *sectorHighlight;
22 22
  23 +@property (nonatomic, strong) NSMutableDictionary *selectedItems;
  24 +
23 - (void)loadDefault; 25 - (void)loadDefault;
24 26
25 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index; 27 - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index;
@@ -45,12 +47,16 @@ @@ -45,12 +47,16 @@
45 self = [self initWithFrame:frame]; 47 self = [self initWithFrame:frame];
46 if(self){ 48 if(self){
47 _items = [NSArray arrayWithArray:items]; 49 _items = [NSArray arrayWithArray:items];
  50 + _selectedItems = [NSMutableDictionary dictionary];
  51 + _outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
  52 + _innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
48 _descriptionTextColor = [UIColor whiteColor]; 53 _descriptionTextColor = [UIColor whiteColor];
49 _descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0]; 54 _descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:18.0];
50 _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; 55 _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
51 _descriptionTextShadowOffset = CGSizeMake(0, 1); 56 _descriptionTextShadowOffset = CGSizeMake(0, 1);
52 _duration = 1.0; 57 _duration = 1.0;
53 _shouldHighlightSectorOnTouch = YES; 58 _shouldHighlightSectorOnTouch = YES;
  59 + _enableMultipleSelection = NO;
54 60
55 [super setupDefaultValues]; 61 [super setupDefaultValues];
56 [self loadDefault]; 62 [self loadDefault];
@@ -285,15 +291,17 @@ @@ -285,15 +291,17 @@
285 while (percentage > [self endPercentageForItemAtIndex:index]) { 291 while (percentage > [self endPercentageForItemAtIndex:index]) {
286 index ++; 292 index ++;
287 } 293 }
288 - 294 +
289 if ([self.delegate respondsToSelector:@selector(userClickedOnPieIndexItem:)]) { 295 if ([self.delegate respondsToSelector:@selector(userClickedOnPieIndexItem:)]) {
290 [self.delegate userClickedOnPieIndexItem:index]; 296 [self.delegate userClickedOnPieIndexItem:index];
291 } 297 }
292 298
293 - if (self.shouldHighlightSectorOnTouch) { 299 + if (self.shouldHighlightSectorOnTouch)
294 - 300 + {
295 - if (self.sectorHighlight) { 301 + if (!self.enableMultipleSelection)
296 - [self.sectorHighlight removeFromSuperlayer]; 302 + {
  303 + if (self.sectorHighlight)
  304 + [self.sectorHighlight removeFromSuperlayer];
297 } 305 }
298 306
299 PNPieChartDataItem *currentItem = [self dataItemForIndex:index]; 307 PNPieChartDataItem *currentItem = [self dataItemForIndex:index];
@@ -306,13 +314,33 @@ @@ -306,13 +314,33 @@
306 314
307 CGFloat startPercnetage = [self startPercentageForItemAtIndex:index]; 315 CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];
308 CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; 316 CGFloat endPercentage = [self endPercentageForItemAtIndex:index];
309 - self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 317 +
  318 + self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
310 borderWidth:10 319 borderWidth:10
311 fillColor:[UIColor clearColor] 320 fillColor:[UIColor clearColor]
312 borderColor:newColor 321 borderColor:newColor
313 startPercentage:startPercnetage 322 startPercentage:startPercnetage
314 endPercentage:endPercentage]; 323 endPercentage:endPercentage];
315 - [_contentView.layer addSublayer:self.sectorHighlight]; 324 +
  325 + if (self.enableMultipleSelection)
  326 + {
  327 + NSString *dictIndex = [NSString stringWithFormat:@"%d", index];
  328 + CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex];
  329 + if (indexShape)
  330 + {
  331 + [indexShape removeFromSuperlayer];
  332 + [self.selectedItems removeObjectForKey:dictIndex];
  333 + }
  334 + else
  335 + {
  336 + [self.selectedItems setObject:self.sectorHighlight forKey:dictIndex];
  337 + [_contentView.layer addSublayer:self.sectorHighlight];
  338 + }
  339 + }
  340 + else
  341 + {
  342 + [_contentView.layer addSublayer:self.sectorHighlight];
  343 + }
316 } 344 }
317 } 345 }
318 346
@@ -403,7 +431,7 @@ @@ -403,7 +431,7 @@
403 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + beforeLabel; 431 x += self.legendStyle == PNLegendItemStyleStacked ? 0 : labelsize.width + beforeLabel;
404 y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0; 432 y += self.legendStyle == PNLegendItemStyleStacked ? labelsize.height : 0;
405 433
406 - 434 +
407 totalHeight = self.legendStyle == PNLegendItemStyleSerial ? fmaxf(totalHeight, rowMaxHeight + y) : totalHeight + labelsize.height; 435 totalHeight = self.legendStyle == PNLegendItemStyleSerial ? fmaxf(totalHeight, rowMaxHeight + y) : totalHeight + labelsize.height;
408 [legendViews addObject:label]; 436 [legendViews addObject:label];
409 counter ++; 437 counter ++;
@@ -428,7 +456,7 @@ @@ -428,7 +456,7 @@
428 CGContextRef context = UIGraphicsGetCurrentContext(); 456 CGContextRef context = UIGraphicsGetCurrentContext();
429 457
430 CGContextAddArc(context, size/2, size/ 2, size/2, 0, M_PI*2, YES); 458 CGContextAddArc(context, size/2, size/ 2, size/2, 0, M_PI*2, YES);
431 - 459 +
432 460
433 //Set some fill color 461 //Set some fill color
434 CGContextSetFillColorWithColor(context, color.CGColor); 462 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