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-09 21:48:42 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cc4b5b3b9fa4a594eabcfd54f85ff4890d937739
cc4b5b3b
1 parent
a3ef6814
added callback when user taps on pie
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletions
PNChart/PNChartDelegate.h
PNChart/PNPieChart.h
PNChart/PNPieChart.m
PNChart/PNChartDelegate.h
View file @
cc4b5b3
...
...
@@ -27,4 +27,6 @@
*/
-
(
void
)
userClickedOnBarAtIndex
:(
NSInteger
)
barIndex
;
-
(
void
)
userClickedOnPieIndexItem
:(
NSInteger
)
pieIndex
;
@end
...
...
PNChart/PNPieChart.h
View file @
cc4b5b3
...
...
@@ -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
...
...
PNChart/PNPieChart.m
View file @
cc4b5b3
...
...
@@ -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
;
...
...
Please
register
or
login
to post a comment