Showing
3 changed files
with
26 additions
and
1 deletions
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | #import <UIKit/UIKit.h> | 9 | #import <UIKit/UIKit.h> |
| 10 | #import "PNPieChartDataItem.h" | 10 | #import "PNPieChartDataItem.h" |
| 11 | #import "PNGenericChart.h" | 11 | #import "PNGenericChart.h" |
| 12 | +#import "PNChartDelegate.h" | ||
| 12 | 13 | ||
| 13 | @interface PNPieChart : PNGenericChart | 14 | @interface PNPieChart : PNGenericChart |
| 14 | 15 | ||
| @@ -34,10 +35,11 @@ | @@ -34,10 +35,11 @@ | ||
| 34 | /** Show only values, this is useful when legend is present */ | 35 | /** Show only values, this is useful when legend is present */ |
| 35 | @property (nonatomic) BOOL showOnlyValues; | 36 | @property (nonatomic) BOOL showOnlyValues; |
| 36 | 37 | ||
| 37 | - | ||
| 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 | +@property (nonatomic, weak) id<PNChartDelegate> delegate; | ||
| 42 | + | ||
| 41 | - (void)strokeChart; | 43 | - (void)strokeChart; |
| 42 | 44 | ||
| 43 | @end | 45 | @end |
| @@ -252,6 +252,27 @@ | @@ -252,6 +252,27 @@ | ||
| 252 | }]; | 252 | }]; |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | ||
| 256 | +{ | ||
| 257 | + for (UITouch *touch in touches) { | ||
| 258 | + CGPoint touchLocation = [touch locationInView:_contentView]; | ||
| 259 | + CGPoint circleCenter = CGPointMake(_contentView.bounds.size.width/2, _contentView.bounds.size.height/2); | ||
| 260 | + CGFloat percentage = [self findPercentageOfAngleInCircle:circleCenter fromPoint:touchLocation]; | ||
| 261 | + int index = 0; | ||
| 262 | + while (percentage > [self endPercentageForItemAtIndex:index]) { | ||
| 263 | + index ++; | ||
| 264 | + } | ||
| 265 | + [self.delegate userClickedOnPieIndexItem:index]; | ||
| 266 | + } | ||
| 267 | +} | ||
| 268 | + | ||
| 269 | +- (CGFloat) findPercentageOfAngleInCircle:(CGPoint)center fromPoint:(CGPoint)reference{ | ||
| 270 | + //Find angle of line Passing In Reference And Center | ||
| 271 | + CGFloat angleOfLine = atanf((reference.y - center.y) / (reference.x - center.x)); | ||
| 272 | + CGFloat percentage = (angleOfLine + M_PI/2)/(2 * M_PI); | ||
| 273 | + return (reference.x - center.x) > 0 ? percentage : percentage + .5; | ||
| 274 | +} | ||
| 275 | + | ||
| 255 | - (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{ | 276 | - (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{ |
| 256 | if ([self.items count] < 1) { | 277 | if ([self.items count] < 1) { |
| 257 | return nil; | 278 | return nil; |
-
Please register or login to post a comment