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-12-18 16:26:31 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
57a4ba64f3518dd42d12e6fbd08ec4b1eb32b4a5
57a4ba64
1 parent
9f9058d7
Makes animation optional on Scatter Chart
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
11 deletions
PNChart/PNScatterChart.m
PNChart/PNScatterChart.m
View file @
57a4ba6
...
...
@@ -81,6 +81,8 @@
-
(
void
)
setupDefaultValues
{
[
super
setupDefaultValues
];
// Initialization code
self
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
clipsToBounds
=
YES
;
...
...
@@ -231,16 +233,11 @@
{
__block
CGFloat
yFinilizeValue
,
xFinilizeValue
;
__block
CGFloat
yValue
,
xValue
;
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"opacity"
];
pathAnimation
.
duration
=
_duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@
(
0
.
0
f
);
pathAnimation
.
toValue
=
@
(
1
.
0
f
);
pathAnimation
.
fillMode
=
kCAFillModeForwards
;
self
.
layer
.
opacity
=
1
;
dispatch_async
(
dispatch_get_global_queue
(
DISPATCH_QUEUE_PRIORITY_DEFAULT
,
0
),
^
{
if
(
self
.
displayAnimated
)
{
[
NSThread
sleepForTimeInterval
:
1
];
}
// update UI on the main thread
dispatch_async
(
dispatch_get_main_queue
(),
^
{
for
(
PNScatterChartData
*
chartData
in
data
)
{
...
...
@@ -256,13 +253,28 @@
CAShapeLayer
*
shape
=
[
self
drawingPointsForChartData
:
chartData
AndWithX
:
xFinilizeValue
AndWithY
:
yFinilizeValue
];
self
.
pathLayer
=
shape
;
[
self
.
layer
addSublayer
:
self
.
pathLayer
];
[
self
.
pathLayer
addAnimation
:
pathAnimation
forKey
:
@"fade"
];
[
self
addAnimationIfNeeded
];
}
}
});
});
}
-
(
void
)
addAnimationIfNeeded
{
if
(
self
.
displayAnimated
)
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"opacity"
];
pathAnimation
.
duration
=
_duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@
(
0
.
0
f
);
pathAnimation
.
toValue
=
@
(
1
.
0
f
);
pathAnimation
.
fillMode
=
kCAFillModeForwards
;
self
.
layer
.
opacity
=
1
;
[
self
.
pathLayer
addAnimation
:
pathAnimation
forKey
:
@"fade"
];
}
}
-
(
CGFloat
)
mappingIsForAxisX
:
(
BOOL
)
isForAxisX
WithValue
:
(
CGFloat
)
value
{
if
(
isForAxisX
)
{
...
...
@@ -393,7 +405,9 @@
// call the same method on a background thread
dispatch_async
(
dispatch_get_global_queue
(
DISPATCH_QUEUE_PRIORITY_DEFAULT
,
0
),
^
{
if
(
self
.
displayAnimated
)
{
[
NSThread
sleepForTimeInterval
:
2
];
}
// calculating start and end point
__block
CGFloat
startX
=
[
self
mappingIsForAxisX
:
true
WithValue
:
startPoint
.
x
];
__block
CGFloat
startY
=
[
self
mappingIsForAxisX
:
false
WithValue
:
startPoint
.
y
];
...
...
@@ -411,14 +425,21 @@
shapeLayer
.
lineWidth
=
lineWidth
;
shapeLayer
.
fillColor
=
[
color
CGColor
];
// adding animation to path
[
self
addStrokeEndAnimationIfNeededToLayer
:
shapeLayer
];
[
self
.
layer
addSublayer
:
shapeLayer
];
});
});
}
-
(
void
)
addStrokeEndAnimationIfNeededToLayer
:
(
CAShapeLayer
*
)
shapeLayer
{
if
(
self
.
displayAnimated
)
{
CABasicAnimation
*
animateStrokeEnd
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
animateStrokeEnd
.
duration
=
_duration
;
animateStrokeEnd
.
fromValue
=
[
NSNumber
numberWithFloat
:
0
.
0
f
];
animateStrokeEnd
.
toValue
=
[
NSNumber
numberWithFloat
:
1
.
0
f
];
[
shapeLayer
addAnimation
:
animateStrokeEnd
forKey
:
nil
];
[
self
.
layer
addSublayer
:
shapeLayer
];
});
});
}
}
@end
...
...
Please
register
or
login
to post a comment