Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #273

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions PNChart/PNPieChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@

- (void)recompute;

/** highlights sector **/
-(void)highlightSectorAtIndex:(NSInteger)index;

@end
81 changes: 42 additions & 39 deletions PNChart/PNPieChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ - (void)didTouchAt:(CGPoint)touchLocation
if ([self.delegate respondsToSelector:@selector(didUnselectPieItem)]) {
[self.delegate didUnselectPieItem];
}
[self.sectorHighlight removeFromSuperlayer];
// [self.sectorHighlight removeFromSuperlayer];
return;
}

Expand All @@ -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
Expand Down