Gianmaria Dal Maistro

added feature: multiple selection on chart view

... ... @@ -46,6 +46,9 @@
@property (nonatomic, weak) id<PNChartDelegate> delegate;
/** Multiple selection */
@property (nonatomic, assign) BOOL enableMultipleSelection;
- (void)strokeChart;
@end
... ...
... ... @@ -23,6 +23,8 @@
@property (nonatomic) NSMutableArray *descriptionLabels;
@property (strong, nonatomic) CAShapeLayer *sectorHighlight;
@property (nonatomic, strong) NSMutableDictionary *selectedItems;
- (void)loadDefault;
- (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index;
... ... @@ -48,6 +50,7 @@
self = [self initWithFrame:frame];
if(self){
_items = [NSArray arrayWithArray:items];
_selectedItems = [NSMutableDictionary dictionary];
_outerCircleRadius = CGRectGetWidth(self.bounds) / 2;
_innerCircleRadius = CGRectGetWidth(self.bounds) / 6;
... ... @@ -57,6 +60,7 @@
_descriptionTextShadowOffset = CGSizeMake(0, 1);
_duration = 1.0;
_shouldHighlightSectorOnTouch = YES;
_enableMultipleSelection = NO;
[super setupDefaultValues];
[self loadDefault];
... ... @@ -284,9 +288,11 @@
[self.delegate userClickedOnPieIndexItem:index];
}
if (self.shouldHighlightSectorOnTouch) {
if (self.sectorHighlight) {
if (self.shouldHighlightSectorOnTouch)
{
if (!self.enableMultipleSelection)
{
if (self.sectorHighlight)
[self.sectorHighlight removeFromSuperlayer];
}
... ... @@ -300,14 +306,34 @@
CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];
CGFloat endPercentage = [self endPercentageForItemAtIndex:index];
self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
borderWidth:10
fillColor:[UIColor clearColor]
borderColor:newColor
startPercentage:startPercnetage
endPercentage:endPercentage];
if (self.enableMultipleSelection)
{
NSString *dictIndex = [NSString stringWithFormat:@"%d", index];
CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex];
if (indexShape)
{
[indexShape removeFromSuperlayer];
[self.selectedItems removeObjectForKey:dictIndex];
}
else
{
[self.selectedItems setObject:self.sectorHighlight forKey:dictIndex];
[_contentView.layer addSublayer:self.sectorHighlight];
}
}
else
{
[_contentView.layer addSublayer:self.sectorHighlight];
}
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
... ...