andi

added callback when user taps on pie

... ... @@ -27,4 +27,6 @@
*/
- (void)userClickedOnBarAtIndex:(NSInteger)barIndex;
- (void)userClickedOnPieIndexItem:(NSInteger)pieIndex;
@end
... ...
... ... @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
#import "PNPieChartDataItem.h"
#import "PNGenericChart.h"
#import "PNChartDelegate.h"
@interface PNPieChart : PNGenericChart
... ... @@ -34,10 +35,11 @@
/** Show only values, this is useful when legend is present */
@property (nonatomic) BOOL showOnlyValues;
/** Show absolute values not relative i.e. percentages */
@property (nonatomic) BOOL showAbsoluteValues;
@property (nonatomic, weak) id<PNChartDelegate> delegate;
- (void)strokeChart;
@end
... ...
... ... @@ -252,6 +252,27 @@
}];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
CGPoint touchLocation = [touch locationInView:_contentView];
CGPoint circleCenter = CGPointMake(_contentView.bounds.size.width/2, _contentView.bounds.size.height/2);
CGFloat percentage = [self findPercentageOfAngleInCircle:circleCenter fromPoint:touchLocation];
int index = 0;
while (percentage > [self endPercentageForItemAtIndex:index]) {
index ++;
}
[self.delegate userClickedOnPieIndexItem:index];
}
}
- (CGFloat) findPercentageOfAngleInCircle:(CGPoint)center fromPoint:(CGPoint)reference{
//Find angle of line Passing In Reference And Center
CGFloat angleOfLine = atanf((reference.y - center.y) / (reference.x - center.x));
CGFloat percentage = (angleOfLine + M_PI/2)/(2 * M_PI);
return (reference.x - center.x) > 0 ? percentage : percentage + .5;
}
- (UIView*) getLegendWithMaxWidth:(CGFloat)mWidth{
if ([self.items count] < 1) {
return nil;
... ...