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
Emma Makinson
2015-12-18 10:32:49 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Edu Caselles
2015-12-18 13:26:18 +0100
Commit
bb476ee38e42fec6203afea536fe4db0d6d5ac95
bb476ee3
1 parent
8da75908
Makes animation optional on Bar Chart
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
19 deletions
PNChart/PNBar.h
PNChart/PNBar.m
PNChart/PNBarChart.h
PNChart/PNBarChart.m
PNChart/PNPieChart.h
PNChart/PNBar.h
View file @
bb476ee
...
...
@@ -31,4 +31,7 @@
@property
(
nonatomic
,
assign
)
BOOL
isNegative
;
//!< 是否是负数
@property
(
nonatomic
,
assign
)
BOOL
isShowNumber
;
//!< 是否显示numbers
/** Display the bar with or without animation. Default is YES. **/
@property
(
nonatomic
)
BOOL
displayAnimated
;
@end
...
...
PNChart/PNBar.m
View file @
bb476ee
...
...
@@ -55,6 +55,7 @@
[
progressline
setLineWidth
:
1
.
0
];
[
progressline
setLineCapStyle
:
kCGLineCapSquare
];
[
self
addAnimationIfNeededWithProgressLine
:
progressline
];
if
(
_barColor
)
{
...
...
@@ -66,20 +67,11 @@
if
(
_grade
)
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"path"
];
pathAnimation
.
fromValue
=
(
id
)
_chartLine
.
path
;
pathAnimation
.
toValue
=
(
id
)[
progressline
CGPath
];
pathAnimation
.
duration
=
0
.
5
f
;
pathAnimation
.
autoreverses
=
NO
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
_chartLine
.
path
=
progressline
.
CGPath
;
if
(
_barColorGradientStart
)
{
// Add gradient
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
self
.
gradientMask
.
path
=
progressline
.
CGPath
;
CABasicAnimation
*
opacityAnimation
=
[
self
fadeAnimation
];
...
...
@@ -88,13 +80,6 @@
}
}
else
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@0.0f
;
pathAnimation
.
toValue
=
@1.0f
;
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
_chartLine
.
strokeEnd
=
1
.
0
;
_chartLine
.
path
=
progressline
.
CGPath
;
...
...
@@ -109,7 +94,6 @@
self
.
gradientMask
.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
self
.
bounds
.
size
.
height
);
self
.
gradientMask
.
path
=
progressline
.
CGPath
;
CAGradientLayer
*
gradientLayer
=
[
CAGradientLayer
layer
];
gradientLayer
.
startPoint
=
CGPointMake
(
0
.
0
,
0
.
0
);
gradientLayer
.
endPoint
=
CGPointMake
(
1
.
0
,
0
.
0
);
...
...
@@ -127,7 +111,6 @@
[
_chartLine
addSublayer
:
gradientLayer
];
self
.
gradientMask
.
strokeEnd
=
1
.
0
;
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
CABasicAnimation
*
opacityAnimation
=
[
self
fadeAnimation
];
[
self
.
textLayer
addAnimation
:
opacityAnimation
forKey
:
nil
];
...
...
@@ -267,4 +250,31 @@
return
fadeAnimation
;
}
-
(
void
)
addAnimationIfNeededWithProgressLine
:
(
UIBezierPath
*
)
progressline
{
if
(
_displayAnimated
)
{
CABasicAnimation
*
pathAnimation
=
nil
;
if
(
_grade
)
{
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"path"
];
pathAnimation
.
fromValue
=
(
id
)
_chartLine
.
path
;
pathAnimation
.
toValue
=
(
id
)[
progressline
CGPath
];
pathAnimation
.
duration
=
0
.
5
f
;
pathAnimation
.
autoreverses
=
NO
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
}
else
{
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@0.0f
;
pathAnimation
.
toValue
=
@1.0f
;
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
}
}
@end
...
...
PNChart/PNBarChart.h
View file @
bb476ee
...
...
@@ -112,6 +112,9 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
/** Controls whether text for x-axis be straight or rotate 45 degree. */
@property
(
nonatomic
)
BOOL
rotateForXAxisText
;
/** Display the bar chart with or without animation. Default is YES. **/
@property
(
nonatomic
)
BOOL
displayAnimated
;
@property
(
nonatomic
,
weak
)
id
<
PNChartDelegate
>
delegate
;
/**whether show gradient bar*/
...
...
PNChart/PNBarChart.m
View file @
bb476ee
...
...
@@ -68,6 +68,7 @@
_rotateForXAxisText
=
false
;
_isGradientShow
=
YES
;
_isShowNumbers
=
YES
;
_displayAnimated
=
YES
;
_yLabelPrefix
=
@""
;
_yLabelSuffix
=
@""
;
_yLabelFormatter
=
^
(
CGFloat
yValue
){
...
...
@@ -241,6 +242,9 @@
//Change Bar Radius
bar
.
barRadius
=
_barRadius
;
//Set Bar Animation
bar
.
displayAnimated
=
_displayAnimated
;
//Change Bar Background color
bar
.
backgroundColor
=
_barBackgroundColor
;
...
...
PNChart/PNPieChart.h
View file @
bb476ee
...
...
@@ -53,7 +53,7 @@
@property
(
nonatomic
,
weak
)
id
<
PNChartDelegate
>
delegate
;
/** Display the pie chart with or wi
r
hout animation. Default is YES. **/
/** Display the pie chart with or wi
t
hout animation. Default is YES. **/
@property
(
nonatomic
)
BOOL
displayAnimated
;
/** Update chart items. Does not update chart itself. */
...
...
Please
register
or
login
to post a comment