Showing
2 changed files
with
38 additions
and
9 deletions
| @@ -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); |
-
Please register or login to post a comment