From 9d145656150ef1a33338e3dcd916948d0274d921 Mon Sep 17 00:00:00 2001 From: Afonso Cavaco Neto Date: Thu, 10 Mar 2016 10:58:50 +0000 Subject: [PATCH 1/3] highlightSectorAtIndex highlightSectorAtIndex added --- PNChart/PNPieChart.h | 2 ++ PNChart/PNPieChart.m | 79 +++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/PNChart/PNPieChart.h b/PNChart/PNPieChart.h index 204afb53..c539815b 100644 --- a/PNChart/PNPieChart.h +++ b/PNChart/PNPieChart.h @@ -65,4 +65,6 @@ - (void)recompute; +-(void)highlightSectorAtIndex:(NSInteger)index; + @end diff --git a/PNChart/PNPieChart.m b/PNChart/PNPieChart.m index 07154677..12f553ed 100644 --- a/PNChart/PNPieChart.m +++ b/PNChart/PNPieChart.m @@ -307,52 +307,55 @@ - (void)didTouchAt:(CGPoint)touchLocation [self.delegate userClickedOnPieIndexItem:index]; } - if (self.shouldHighlightSectorOnTouch) + if (self.shouldHighlightSectorOnTouch) { + [self highlightSectorAtIndex:index]; + + } +} + +-(void)highlightSectorAtIndex:(NSInteger)index { + if (!self.enableMultipleSelection) { + if (self.sectorHighlight) + [self.sectorHighlight removeFromSuperlayer]; + } + + PNPieChartDataItem *currentItem = [self dataItemForIndex:index]; + + CGFloat red,green,blue,alpha; + UIColor *old = currentItem.color; + [old getRed:&red green:&green blue:&blue alpha:&alpha]; + alpha /= 2; + UIColor *newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; + + CGFloat startPercentage = [self startPercentageForItemAtIndex:index]; + CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; + + self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 + borderWidth:10 + fillColor:[UIColor clearColor] + borderColor:newColor + startPercentage:startPercentage + endPercentage:endPercentage]; + + if (self.enableMultipleSelection) { - if (!self.enableMultipleSelection) + NSString *dictIndex = [NSString stringWithFormat:@"%d", index]; + CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex]; + if (indexShape) { - if (self.sectorHighlight) - [self.sectorHighlight removeFromSuperlayer]; - } - - PNPieChartDataItem *currentItem = [self dataItemForIndex:index]; - - CGFloat red,green,blue,alpha; - UIColor *old = currentItem.color; - [old getRed:&red green:&green blue:&blue alpha:&alpha]; - alpha /= 2; - UIColor *newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; - - CGFloat startPercentage = [self startPercentageForItemAtIndex:index]; - CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; - - self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 - borderWidth:10 - fillColor:[UIColor clearColor] - borderColor:newColor - startPercentage:startPercentage - 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]; - } + [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 From e7deadf9b627a8336aa48e960b1842c84790471d Mon Sep 17 00:00:00 2001 From: Afonso Cavaco Neto Date: Thu, 10 Mar 2016 12:47:11 +0000 Subject: [PATCH 2/3] Highlight Sector at index Highlight Sector at index implemented --- PNChart/PNPieChart.h | 1 + 1 file changed, 1 insertion(+) diff --git a/PNChart/PNPieChart.h b/PNChart/PNPieChart.h index c539815b..665c8653 100644 --- a/PNChart/PNPieChart.h +++ b/PNChart/PNPieChart.h @@ -65,6 +65,7 @@ - (void)recompute; +/** highlights sector **/ -(void)highlightSectorAtIndex:(NSInteger)index; @end From 0845b9de7eb0a41dce0f72e0178d0497cc1d96c2 Mon Sep 17 00:00:00 2001 From: Afonso Cavaco Neto Date: Mon, 14 Mar 2016 14:31:06 +0000 Subject: [PATCH 3/3] remove un-selection on middle touch remove un-selection on middle touch --- PNChart/PNPieChart.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PNChart/PNPieChart.m b/PNChart/PNPieChart.m index 12f553ed..3850d325 100644 --- a/PNChart/PNPieChart.m +++ b/PNChart/PNPieChart.m @@ -293,7 +293,7 @@ - (void)didTouchAt:(CGPoint)touchLocation if ([self.delegate respondsToSelector:@selector(didUnselectPieItem)]) { [self.delegate didUnselectPieItem]; } - [self.sectorHighlight removeFromSuperlayer]; + // [self.sectorHighlight removeFromSuperlayer]; return; }