Karol Magier

Add public BOOL property for sector highlight on touch (pie chart)

@@ -38,6 +38,9 @@ @@ -38,6 +38,9 @@
38 /** Show absolute values not relative i.e. percentages */ 38 /** Show absolute values not relative i.e. percentages */
39 @property (nonatomic) BOOL showAbsoluteValues; 39 @property (nonatomic) BOOL showAbsoluteValues;
40 40
  41 +/** Default YES. */
  42 +@property (nonatomic) BOOL shouldHighlightSectorOnTouch;
  43 +
41 @property (nonatomic, weak) id<PNChartDelegate> delegate; 44 @property (nonatomic, weak) id<PNChartDelegate> delegate;
42 45
43 - (void)strokeChart; 46 - (void)strokeChart;
@@ -56,6 +56,7 @@ @@ -56,6 +56,7 @@
56 _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; 56 _descriptionTextShadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
57 _descriptionTextShadowOffset = CGSizeMake(0, 1); 57 _descriptionTextShadowOffset = CGSizeMake(0, 1);
58 _duration = 1.0; 58 _duration = 1.0;
  59 + _shouldHighlightSectorOnTouch = YES;
59 60
60 [super setupDefaultValues]; 61 [super setupDefaultValues];
61 [self loadDefault]; 62 [self loadDefault];
@@ -277,26 +278,30 @@ @@ -277,26 +278,30 @@
277 [self.delegate userClickedOnPieIndexItem:index]; 278 [self.delegate userClickedOnPieIndexItem:index];
278 } 279 }
279 280
280 - if (self.sectorHighlight) { 281 + if (self.shouldHighlightSectorOnTouch) {
281 - [self.sectorHighlight removeFromSuperlayer]; 282 +
  283 + if (self.sectorHighlight) {
  284 + [self.sectorHighlight removeFromSuperlayer];
  285 + }
  286 +
  287 + PNPieChartDataItem *currentItem = [self dataItemForIndex:index];
  288 +
  289 + CGFloat red,green,blue,alpha;
  290 + UIColor *old = currentItem.color;
  291 + [old getRed:&red green:&green blue:&blue alpha:&alpha];
  292 + alpha /= 2;
  293 + UIColor *newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
  294 +
  295 + CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];
  296 + CGFloat endPercentage = [self endPercentageForItemAtIndex:index];
  297 + self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5
  298 + borderWidth:10
  299 + fillColor:[UIColor clearColor]
  300 + borderColor:newColor
  301 + startPercentage:startPercnetage
  302 + endPercentage:endPercentage];
  303 + [_contentView.layer addSublayer:self.sectorHighlight];
282 } 304 }
283 - PNPieChartDataItem *currentItem = [self dataItemForIndex:index];  
284 -  
285 - CGFloat red,green,blue,alpha;  
286 - UIColor *old = currentItem.color;  
287 - [old getRed:&red green:&green blue:&blue alpha:&alpha];  
288 - alpha /= 2;  
289 - UIColor *newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];  
290 -  
291 - CGFloat startPercnetage = [self startPercentageForItemAtIndex:index];  
292 - CGFloat endPercentage = [self endPercentageForItemAtIndex:index];  
293 - self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5  
294 - borderWidth:10  
295 - fillColor:[UIColor clearColor]  
296 - borderColor:newColor  
297 - startPercentage:startPercnetage  
298 - endPercentage:endPercentage];  
299 - [_contentView.layer addSublayer:self.sectorHighlight];  
300 } 305 }
301 306
302 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 307 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event