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 11:06:27 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Edu Caselles
2015-12-18 13:26:18 +0100
Commit
7a60702d8c49062392eacf728488a839b4f9a383
7a60702d
1 parent
bb476ee3
Makes animation optional on Circle Chart
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
15 deletions
PNChart/PNCircleChart.h
PNChart/PNCircleChart.m
PNChart/PNPieChart.h
PNChart/PNCircleChart.h
View file @
7a60702
...
...
@@ -64,11 +64,13 @@ displayCountingLabel:(BOOL)displayCountingLabel
@property
(
nonatomic
)
NSTimeInterval
duration
;
@property
(
nonatomic
)
PNChartFormatType
chartType
;
@property
(
nonatomic
)
CAShapeLayer
*
circle
;
@property
(
nonatomic
)
CAShapeLayer
*
gradientMask
;
@property
(
nonatomic
)
CAShapeLayer
*
circleBackground
;
@property
(
nonatomic
)
BOOL
displayCountingLabel
;
/** Display the circle chart with or without animation. Default is YES. **/
@property
(
nonatomic
)
BOOL
displayAnimated
;
@end
...
...
PNChart/PNCircleChart.m
View file @
7a60702
...
...
@@ -69,6 +69,7 @@ displayCountingLabel:(BOOL)displayCountingLabel
_strokeColor
=
PNFreshGreen
;
_duration
=
1
.
0
;
_chartType
=
PNChartFormatTypePercent
;
_displayAnimated
=
YES
;
_displayCountingLabel
=
displayCountingLabel
;
...
...
@@ -153,19 +154,8 @@ displayCountingLabel:(BOOL)displayCountingLabel
_circleBackground
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBackground
.
strokeEnd
=
1
.
0
;
_circle
.
strokeColor
=
_strokeColor
.
CGColor
;
// Add Animation
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
self
.
duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@0.0f
;
pathAnimation
.
toValue
=
@
([
_current
floatValue
]
/
[
_total
floatValue
]);
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
_circle
.
strokeEnd
=
[
_current
floatValue
]
/
[
_total
floatValue
];
[
_countingLabel
countFrom
:
0
to
:[
_current
floatValue
]
/
([
_total
floatValue
]
/
100
.
0
)
withDuration
:
self
.
duration
];
// Check if user wants to add a gradient from the start color to the bar color
if
(
_strokeColorGradientStart
)
{
...
...
@@ -195,9 +185,9 @@ displayCountingLabel:(BOOL)displayCountingLabel
[
_circle
addSublayer
:
gradientLayer
];
self
.
gradientMask
.
strokeEnd
=
[
_current
floatValue
]
/
[
_total
floatValue
];
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
[
self
addAnimationIfNeeded
];
}
...
...
@@ -241,4 +231,26 @@ displayCountingLabel:(BOOL)displayCountingLabel
_total
=
total
;
}
-
(
void
)
addAnimationIfNeeded
{
double
percentageValue
=
[
_current
floatValue
]
/
([
_total
floatValue
]
/
100
.
0
);
if
(
_displayAnimated
)
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
self
.
duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@
(
0
.
0
f
);
pathAnimation
.
toValue
=
@
([
_current
floatValue
]
/
[
_total
floatValue
]);
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
[
_countingLabel
countFrom
:
0
to
:
percentageValue
withDuration
:
self
.
duration
];
if
(
self
.
gradientMask
&&
_strokeColorGradientStart
)
{
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
}
else
{
[
_countingLabel
countFrom
:
percentageValue
to
:
percentageValue
withDuration
:
self
.
duration
];
}
}
@end
...
...
PNChart/PNPieChart.h
View file @
7a60702
...
...
@@ -52,7 +52,6 @@
@property
(
nonatomic
,
weak
)
id
<
PNChartDelegate
>
delegate
;
/** Display the pie chart with or without animation. Default is YES. **/
@property
(
nonatomic
)
BOOL
displayAnimated
;
...
...
Please
register
or
login
to post a comment