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
kevinzhow
2014-12-12 02:04:51 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5f6a8272031214fb12c49fe23bbd9578b7ea4a0c
5f6a8272
1 parent
664b146f
New calculateChartPath method
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
35 deletions
PNChart/PNLineChart.h
PNChart/PNLineChart.m
PNChart/PNLineChart.h
View file @
5f6a827
...
...
@@ -59,4 +59,10 @@
-
(
void
)
setXLabels
:(
NSArray
*
)
xLabels
withWidth
:(
CGFloat
)
width
;
/**
* Update Chart Value
*/
-
(
void
)
updateChartData
:(
NSArray
*
)
data
;
@end
...
...
PNChart/PNLineChart.m
View file @
5f6a827
...
...
@@ -150,6 +150,8 @@
}
}
#pragma mark - Touch at point
-
(
void
)
touchesBegan
:(
NSSet
*
)
touches
withEvent
:(
UIEvent
*
)
event
{
[
self
touchPoint
:
touches
withEvent
:
event
];
...
...
@@ -224,21 +226,66 @@
}
}
#pragma mark - Draw Chart
-
(
void
)
strokeChart
{
_chartPath
=
[[
NSMutableArray
alloc
]
init
];
_pointPath
=
[[
NSMutableArray
alloc
]
init
];
[
self
calculateChartPath
:
_chartPath
andPointsPath
:
_pointPath
andPathKeyPoints
:
_pathPoints
];
// Draw each line
for
(
NSUInteger
lineIndex
=
0
;
lineIndex
<
self
.
chartData
.
count
;
lineIndex
++
)
{
PNLineChartData
*
chartData
=
self
.
chartData
[
lineIndex
];
CAShapeLayer
*
chartLine
=
(
CAShapeLayer
*
)
self
.
chartLineArray
[
lineIndex
];
CAShapeLayer
*
pointLayer
=
(
CAShapeLayer
*
)
self
.
chartPointArray
[
lineIndex
];
UIGraphicsBeginImageContext
(
self
.
frame
.
size
);
// setup the color of the chart line
if
(
chartData
.
color
)
{
chartLine
.
strokeColor
=
[
chartData
.
color
CGColor
];
}
else
{
chartLine
.
strokeColor
=
[
PNGreen
CGColor
];
pointLayer
.
strokeColor
=
[
PNGreen
CGColor
];
}
UIBezierPath
*
progressline
=
[
_chartPath
objectAtIndex
:
lineIndex
];
UIBezierPath
*
pointPath
=
[
_pointPath
objectAtIndex
:
lineIndex
];
chartLine
.
path
=
progressline
.
CGPath
;
pointLayer
.
path
=
pointPath
.
CGPath
;
[
CATransaction
begin
];
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
;
// if you want cancel the point animation, conment this code, the point will show immediately
if
(
chartData
.
inflexionPointStyle
!=
PNLineChartPointStyleNone
)
{
[
pointLayer
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
[
CATransaction
commit
];
UIGraphicsEndImageContext
();
}
}
-
(
void
)
calculateChartPath
:
(
NSMutableArray
*
)
chartPath
andPointsPath
:
(
NSMutableArray
*
)
pointsPath
andPathKeyPoints
:
(
NSMutableArray
*
)
pathPoints
{
// Draw each line
for
(
NSUInteger
lineIndex
=
0
;
lineIndex
<
self
.
chartData
.
count
;
lineIndex
++
)
{
PNLineChartData
*
chartData
=
self
.
chartData
[
lineIndex
];
CGFloat
yValue
;
CGFloat
innerGrade
;
UIGraphicsBeginImageContext
(
self
.
frame
.
size
);
UIBezierPath
*
progressline
=
[
UIBezierPath
bezierPath
];
[
progressline
setLineWidth
:
chartData
.
lineWidth
];
...
...
@@ -248,8 +295,9 @@
UIBezierPath
*
pointPath
=
[
UIBezierPath
bezierPath
];
[
pointPath
setLineWidth
:
chartData
.
lineWidth
];
[
_chartPath
addObject
:
progressline
];
[
_pointPath
addObject
:
pointPath
];
[
chartPath
insertObject
:
progressline
atIndex
:
lineIndex
];
[
pointsPath
insertObject
:
pointPath
atIndex
:
lineIndex
];
if
(
!
_showLabel
)
{
_chartCavanHeight
=
self
.
frame
.
size
.
height
-
2
*
_yLabelHeight
;
...
...
@@ -373,42 +421,13 @@
[
linePointsArray
addObject
:[
NSValue
valueWithCGPoint
:
CGPointMake
(
x
,
y
)]];
}
[
_pathPoints
addObject
:[
linePointsArray
copy
]];
// setup the color of the chart line
if
(
chartData
.
color
)
{
chartLine
.
strokeColor
=
[
chartData
.
color
CGColor
];
}
else
{
chartLine
.
strokeColor
=
[
PNGreen
CGColor
];
pointLayer
.
strokeColor
=
[
PNGreen
CGColor
];
}
[
progressline
stroke
];
chartLine
.
path
=
progressline
.
CGPath
;
pointLayer
.
path
=
pointPath
.
CGPath
;
[
CATransaction
begin
];
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
;
// if you want cancel the point animation, conment this code, the point will show immediately
if
(
chartData
.
inflexionPointStyle
!=
PNLineChartPointStyleNone
)
{
[
pointLayer
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
[
CATransaction
commit
];
[
pathPoints
addObject
:[
linePointsArray
copy
]];
UIGraphicsEndImageContext
();
}
}
#pragma mark - Set Chart Data
-
(
void
)
setChartData
:
(
NSArray
*
)
data
{
if
(
data
!=
_chartData
)
{
...
...
@@ -479,6 +498,13 @@
}
}
#pragma mark - Update Chart Data
-
(
void
)
updateChartData
:
(
NSArray
*
)
data
{
}
#define IOS7_OR_LATER [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0
-
(
void
)
drawRect
:
(
CGRect
)
rect
...
...
Please
register
or
login
to post a comment