Merge pull request #229 from thedazed/master
Add prefix/suffix public property for y label values
Showing
4 changed files
with
34 additions
and
20 deletions
| @@ -46,6 +46,12 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | @@ -46,6 +46,12 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | ||
| 46 | /** Formats the ylabel text. */ | 46 | /** Formats the ylabel text. */ |
| 47 | @property (copy) PNYLabelFormatter yLabelFormatter; | 47 | @property (copy) PNYLabelFormatter yLabelFormatter; |
| 48 | 48 | ||
| 49 | +/** Prefix to y label values, none if unset. */ | ||
| 50 | +@property (nonatomic) NSString *yLabelPrefix; | ||
| 51 | + | ||
| 52 | +/** Suffix to y label values, none if unset. */ | ||
| 53 | +@property (nonatomic) NSString *yLabelSuffix; | ||
| 54 | + | ||
| 49 | @property (nonatomic) CGFloat chartMargin; | 55 | @property (nonatomic) CGFloat chartMargin; |
| 50 | 56 | ||
| 51 | /** Controls whether labels should be displayed. */ | 57 | /** Controls whether labels should be displayed. */ |
| @@ -119,7 +119,7 @@ | @@ -119,7 +119,7 @@ | ||
| 119 | label.font = _labelFont; | 119 | label.font = _labelFont; |
| 120 | label.textColor = _labelTextColor; | 120 | label.textColor = _labelTextColor; |
| 121 | [label setTextAlignment:NSTextAlignmentRight]; | 121 | [label setTextAlignment:NSTextAlignmentRight]; |
| 122 | - label.text = labelText; | 122 | + label.text = [NSString stringWithFormat:@"%@%@%@", _yLabelPrefix, labelText, _yLabelSuffix]; |
| 123 | [self addSubview:label]; | 123 | [self addSubview:label]; |
| 124 | 124 | ||
| 125 | [_yChartLabels addObject:label]; | 125 | [_yChartLabels addObject:label]; |
| @@ -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 |
-
Please register or login to post a comment