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
MrWooJ
2014-12-14 18:34:01 +0330
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd1e0fed6db517ce18aaec983de2b4f309a27c2f
cd1e0fed
1 parent
abcfe3dd
drawing UI methods on the background thread
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
38 deletions
PNChart/PNScatterChart.m
PNChart/PNScatterChart.m
View file @
cd1e0fe
...
...
@@ -181,8 +181,8 @@
-
(
void
)
setChartData
:
(
NSArray
*
)
data
{
if
(
data
!=
_chartData
)
{
CGFloat
yFinilizeValue
,
xFinilizeValue
;
CGFloat
yValue
,
xValue
;
__block
CGFloat
yFinilizeValue
,
xFinilizeValue
;
__block
CGFloat
yValue
,
xValue
;
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"opacity"
];
pathAnimation
.
duration
=
_duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
...
...
@@ -191,22 +191,28 @@
pathAnimation
.
fillMode
=
kCAFillModeForwards
;
self
.
layer
.
opacity
=
1
;
for
(
PNScatterChartData
*
chartData
in
data
)
{
for
(
NSUInteger
i
=
0
;
i
<
chartData
.
itemCount
;
i
++
)
{
yValue
=
chartData
.
getData
(
i
).
y
;
xValue
=
chartData
.
getData
(
i
).
x
;
if
(
!
(
xValue
>=
_AxisX_minValue
&&
xValue
<=
_AxisX_maxValue
)
||
!
(
yValue
>=
_AxisY_minValue
&&
yValue
<=
_AxisY_maxValue
))
{
NSLog
(
@"input is not in correct range."
);
exit
(
0
);
dispatch_async
(
dispatch_get_global_queue
(
DISPATCH_QUEUE_PRIORITY_DEFAULT
,
0
),
^
{
[
NSThread
sleepForTimeInterval
:
1
];
// update UI on the main thread
dispatch_async
(
dispatch_get_main_queue
(),
^
{
for
(
PNScatterChartData
*
chartData
in
data
)
{
for
(
NSUInteger
i
=
0
;
i
<
chartData
.
itemCount
;
i
++
)
{
yValue
=
chartData
.
getData
(
i
).
y
;
xValue
=
chartData
.
getData
(
i
).
x
;
if
(
!
(
xValue
>=
_AxisX_minValue
&&
xValue
<=
_AxisX_maxValue
)
||
!
(
yValue
>=
_AxisY_minValue
&&
yValue
<=
_AxisY_maxValue
))
{
NSLog
(
@"input is not in correct range."
);
exit
(
0
);
}
xFinilizeValue
=
[
self
mappingIsForAxisX
:
true
WithValue
:
xValue
];
yFinilizeValue
=
[
self
mappingIsForAxisX
:
false
WithValue
:
yValue
];
CAShapeLayer
*
shape
=
[
self
drawingPointsForChartData
:
chartData
AndWithX
:
xFinilizeValue
AndWithY
:
yFinilizeValue
];
[
self
.
layer
addSublayer
:
shape
];
self
.
pathLayer
=
shape
;
[
self
.
pathLayer
addAnimation
:
pathAnimation
forKey
:
@"fade"
];
}
}
xFinilizeValue
=
[
self
mappingIsForAxisX
:
true
WithValue
:
xValue
];
yFinilizeValue
=
[
self
mappingIsForAxisX
:
false
WithValue
:
yValue
];
CAShapeLayer
*
shape
=
[
self
drawingPointsForChartData
:
chartData
AndWithX
:
xFinilizeValue
AndWithY
:
yFinilizeValue
];
[
self
.
layer
addSublayer
:
shape
];
self
.
pathLayer
=
shape
;
[
self
.
pathLayer
addAnimation
:
pathAnimation
forKey
:
@"fade"
];
}
}
});
});
}
}
...
...
@@ -313,27 +319,35 @@
}
-
(
void
)
drawLineFromPoint
:
(
CGPoint
)
startPoint
ToPoint
:
(
CGPoint
)
endPoint
WithLineWith
:
(
CGFloat
)
lineWidth
AndWithColor
:
(
UIColor
*
)
color
{
// calculating start and end point
CGFloat
startX
=
[
self
mappingIsForAxisX
:
true
WithValue
:
startPoint
.
x
];
CGFloat
startY
=
[
self
mappingIsForAxisX
:
false
WithValue
:
startPoint
.
y
];
CGFloat
endX
=
[
self
mappingIsForAxisX
:
true
WithValue
:
endPoint
.
x
];
CGFloat
endY
=
[
self
mappingIsForAxisX
:
false
WithValue
:
endPoint
.
y
];
// drawing path between two points
UIBezierPath
*
path
=
[
UIBezierPath
bezierPath
];
[
path
moveToPoint
:
CGPointMake
(
startX
,
startY
)];
[
path
addLineToPoint
:
CGPointMake
(
endX
,
endY
)];
CAShapeLayer
*
shapeLayer
=
[
CAShapeLayer
layer
];
shapeLayer
.
path
=
[
path
CGPath
];
shapeLayer
.
strokeColor
=
[
color
CGColor
];
shapeLayer
.
lineWidth
=
lineWidth
;
shapeLayer
.
fillColor
=
[
color
CGColor
];
// adding animation to path
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
];
// call the same method on a background thread
dispatch_async
(
dispatch_get_global_queue
(
DISPATCH_QUEUE_PRIORITY_DEFAULT
,
0
),
^
{
[
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
];
__block
CGFloat
endX
=
[
self
mappingIsForAxisX
:
true
WithValue
:
endPoint
.
x
];
__block
CGFloat
endY
=
[
self
mappingIsForAxisX
:
false
WithValue
:
endPoint
.
y
];
// update UI on the main thread
dispatch_async
(
dispatch_get_main_queue
(),
^
{
// drawing path between two points
UIBezierPath
*
path
=
[
UIBezierPath
bezierPath
];
[
path
moveToPoint
:
CGPointMake
(
startX
,
startY
)];
[
path
addLineToPoint
:
CGPointMake
(
endX
,
endY
)];
CAShapeLayer
*
shapeLayer
=
[
CAShapeLayer
layer
];
shapeLayer
.
path
=
[
path
CGPath
];
shapeLayer
.
strokeColor
=
[
color
CGColor
];
shapeLayer
.
lineWidth
=
lineWidth
;
shapeLayer
.
fillColor
=
[
color
CGColor
];
// adding animation to path
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