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
Edu Caselles
2015-11-10 17:15:06 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Edu Caselles
2015-12-18 13:26:18 +0100
Commit
9ac26e45458ad9f221f1f526c224afcabf29986f
9ac26e45
1 parent
44a83a99
Adds property to disable animations when drawing the pie chart.
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
22 deletions
PNChart/PNPieChart.h
PNChart/PNPieChart.m
PNChart/PNPieChart.h
View file @
9ac26e4
...
...
@@ -52,6 +52,10 @@
@property
(
nonatomic
,
weak
)
id
<
PNChartDelegate
>
delegate
;
/** Display the pie chart with or wirhout animation. Default is YES. **/
@property
(
nonatomic
)
BOOL
displayAnimated
;
/** Update chart items. Does not update chart itself. */
-
(
void
)
updateChartData
:(
NSArray
*
)
data
;
...
...
PNChart/PNPieChart.m
View file @
9ac26e4
...
...
@@ -47,25 +47,34 @@
self
=
[
self
initWithFrame
:
frame
];
if
(
self
){
_items
=
[
NSArray
arrayWithArray
:
items
];
_selectedItems
=
[
NSMutableDictionary
dictionary
];
_outerCircleRadius
=
CGRectGetWidth
(
self
.
bounds
)
/
2
;
_innerCircleRadius
=
CGRectGetWidth
(
self
.
bounds
)
/
6
;
_descriptionTextColor
=
[
UIColor
whiteColor
];
_descriptionTextFont
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
18
.
0
];
_descriptionTextShadowColor
=
[[
UIColor
blackColor
]
colorWithAlphaComponent
:
0
.
4
];
_descriptionTextShadowOffset
=
CGSizeMake
(
0
,
1
);
_duration
=
1
.
0
;
_shouldHighlightSectorOnTouch
=
YES
;
_enableMultipleSelection
=
NO
;
_hideValues
=
NO
;
[
super
setupDefaultValues
];
[
self
loadDefault
];
[
self
baseInit
];
}
return
self
;
}
-
(
void
)
awakeFromNib
{
[
self
baseInit
];
}
-
(
void
)
baseInit
{
_selectedItems
=
[
NSMutableDictionary
dictionary
];
_outerCircleRadius
=
CGRectGetWidth
(
self
.
bounds
)
/
2
;
_innerCircleRadius
=
CGRectGetWidth
(
self
.
bounds
)
/
6
;
_descriptionTextColor
=
[
UIColor
whiteColor
];
_descriptionTextFont
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
18
.
0
];
_descriptionTextShadowColor
=
[[
UIColor
blackColor
]
colorWithAlphaComponent
:
0
.
4
];
_descriptionTextShadowOffset
=
CGSizeMake
(
0
,
1
);
_duration
=
1
.
0
;
_shouldHighlightSectorOnTouch
=
YES
;
_enableMultipleSelection
=
NO
;
_hideValues
=
NO
;
_displayAnimated
=
YES
;
[
super
setupDefaultValues
];
[
self
loadDefault
];
}
-
(
void
)
loadDefault
{
__block
CGFloat
currentTotal
=
0
;
CGFloat
total
=
[[
self
.
items
valueForKeyPath
:
@"@sum.value"
]
floatValue
];
...
...
@@ -129,6 +138,8 @@
[
_contentView
addSubview
:
descriptionLabel
];
[
_descriptionLabels
addObject
:
descriptionLabel
];
}
[
self
addAnimationIfNeeded
];
}
-
(
UILabel
*
)
descriptionLabelForItemAtIndex
:
(
NSUInteger
)
index
{
...
...
@@ -244,14 +255,25 @@
endPercentage
:
1
];
_pieLayer
.
mask
=
maskLayer
;
CABasicAnimation
*
animation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
animation
.
duration
=
_duration
;
animation
.
fromValue
=
@0
;
animation
.
toValue
=
@1
;
animation
.
delegate
=
self
;
animation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
animation
.
removedOnCompletion
=
YES
;
[
maskLayer
addAnimation
:
animation
forKey
:
@"circleAnimation"
];
}
-
(
void
)
addAnimationIfNeeded
{
if
(
_displayAnimated
)
{
CABasicAnimation
*
animation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
animation
.
duration
=
_duration
;
animation
.
fromValue
=
@0
;
animation
.
toValue
=
@1
;
animation
.
delegate
=
self
;
animation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
animation
.
removedOnCompletion
=
YES
;
[
_pieLayer
.
mask
addAnimation
:
animation
forKey
:
@"circleAnimation"
];
}
else
{
// Add description labels since no animation is required
[
_descriptionLabels
enumerateObjectsUsingBlock
:
^
(
id
obj
,
NSUInteger
idx
,
BOOL
*
stop
)
{
[
obj
setAlpha
:
1
];
}];
}
}
-
(
void
)
createArcAnimationForLayer
:
(
CAShapeLayer
*
)
layer
...
...
Please
register
or
login
to post a comment