Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
PNChart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
andi
2015-03-12 13:31:01 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a5352435330180d81eef8da1f3431b3dfefff2c2
a5352435
1 parent
cc4b5b3b
Interactive Pie, and delegation protocol improvement
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
8 deletions
PNChart/PNChartDelegate.h
PNChart/PNPieChart.m
PNChart/PNChartDelegate.h
View file @
a535243
...
...
@@ -29,4 +29,5 @@
-
(
void
)
userClickedOnPieIndexItem
:(
NSInteger
)
pieIndex
;
-
(
void
)
didUnselectPieItem
;
@end
...
...
PNChart/PNPieChart.m
View file @
a535243
...
...
@@ -21,7 +21,7 @@
@property
(
nonatomic
)
UIView
*
contentView
;
@property
(
nonatomic
)
CAShapeLayer
*
pieLayer
;
@property
(
nonatomic
)
NSMutableArray
*
descriptionLabels
;
@property
(
strong
,
nonatomic
)
CAShapeLayer
*
sectorHighlight
;
-
(
void
)
loadDefault
;
...
...
@@ -102,6 +102,7 @@
CGFloat
radius
=
_innerCircleRadius
+
(
_outerCircleRadius
-
_innerCircleRadius
)
/
2
;
CGFloat
borderWidth
=
_outerCircleRadius
-
_innerCircleRadius
;
CAShapeLayer
*
currentPieLayer
=
[
self
newCircleLayerWithRadius
:
radius
borderWidth
:
borderWidth
fillColor
:
[
UIColor
clearColor
]
...
...
@@ -252,17 +253,57 @@
}];
}
-
(
void
)
didTouchAt
:
(
CGPoint
)
touchLocation
{
CGPoint
circleCenter
=
CGPointMake
(
_contentView
.
bounds
.
size
.
width
/
2
,
_contentView
.
bounds
.
size
.
height
/
2
);
CGFloat
distanceFromCenter
=
sqrtf
(
powf
((
touchLocation
.
y
-
circleCenter
.
y
),
2
)
+
powf
((
touchLocation
.
x
-
circleCenter
.
x
),
2
));
if
(
distanceFromCenter
<
_innerCircleRadius
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
didUnselectPieItem
)])
{
[
self
.
delegate
didUnselectPieItem
];
}
[
self
.
sectorHighlight
removeFromSuperlayer
];
return
;
}
CGFloat
percentage
=
[
self
findPercentageOfAngleInCircle
:
circleCenter
fromPoint
:
touchLocation
];
int
index
=
0
;
while
(
percentage
>
[
self
endPercentageForItemAtIndex
:
index
])
{
index
++
;
}
if
([
self
.
delegate
respondsToSelector
:
@selector
(
userClickedOnPieIndexItem
:)])
{
[
self
.
delegate
userClickedOnPieIndexItem
:
index
];
}
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
startPercnetage
=
[
self
startPercentageForItemAtIndex
:
index
];
CGFloat
endPercentage
=
[
self
endPercentageForItemAtIndex
:
index
];
self
.
sectorHighlight
=
[
self
newCircleLayerWithRadius
:
_outerCircleRadius
+
5
borderWidth
:
10
fillColor
:
[
UIColor
clearColor
]
borderColor
:
newColor
startPercentage
:
startPercnetage
endPercentage
:
endPercentage
];
[
_contentView
.
layer
addSublayer
:
self
.
sectorHighlight
];
}
-
(
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
];
[
self
didTouchAt
:
touchLocation
];
}
}
...
...
Please
register
or
login
to post a comment