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
2013-12-15 11:35:21 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6d9e48fdbbc9413a3de217ac28e5ea1c4c8cc757
6d9e48fd
1 parent
1dedf694
Add Support multible line callback
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
40 deletions
PNChartDemo/PCChartsTableViewController.m
PNChartDemo/PNChart/PNChartDelegate.h
PNChartDemo/PNChart/PNLineChart.h
PNChartDemo/PNChart/PNLineChart.m
PNChartDemo/PCChartsTableViewController.m
View file @
6d9e48f
...
...
@@ -137,12 +137,12 @@
}
-
(
void
)
userClickedOnLineKeyPoint
:
(
CGPoint
)
point
andPointIndex
:
(
NSInteger
)
i
ndex
{
NSLog
(
@"Click Key on line %f, %f
and index is %ld"
,
point
.
x
,
point
.
y
,(
long
)
i
ndex
);
-
(
void
)
userClickedOnLineKeyPoint
:
(
CGPoint
)
point
lineIndex
:
(
NSInteger
)
lineIndex
andPointIndex
:
(
NSInteger
)
pointI
ndex
{
NSLog
(
@"Click Key on line %f, %f
line index is %d and point index is %d"
,
point
.
x
,
point
.
y
,(
int
)
lineIndex
,
(
int
)
pointI
ndex
);
}
-
(
void
)
userClickedOnLinePoint
:
(
CGPoint
)
point
{
NSLog
(
@"Click on line %f, %f
"
,
point
.
x
,
point
.
y
);
-
(
void
)
userClickedOnLinePoint
:
(
CGPoint
)
point
lineIndex
:
(
NSInteger
)
lineIndex
{
NSLog
(
@"Click on line %f, %f
, line index is %d"
,
point
.
x
,
point
.
y
,
(
int
)
lineIndex
);
}
@end
...
...
PNChartDemo/PNChart/PNChartDelegate.h
View file @
6d9e48f
...
...
@@ -14,13 +14,13 @@
* When user click on the chart line
*
*/
-
(
void
)
userClickedOnLinePoint
:
(
CGPoint
)
point
;
-
(
void
)
userClickedOnLinePoint
:
(
CGPoint
)
point
lineIndex
:
(
NSInteger
)
lineIndex
;
/**
* When user click on the chart line key point
*
*/
-
(
void
)
userClickedOnLineKeyPoint
:(
CGPoint
)
point
andPointIndex
:(
NSInteger
)
i
ndex
;
-
(
void
)
userClickedOnLineKeyPoint
:(
CGPoint
)
point
lineIndex
:(
NSInteger
)
lineIndex
andPointIndex
:(
NSInteger
)
pointI
ndex
;
@end
...
...
PNChartDemo/PNChart/PNLineChart.h
View file @
6d9e48f
...
...
@@ -46,6 +46,4 @@
@property
(
nonatomic
)
BOOL
showLabel
;
@property
(
nonatomic
,
strong
)
UIBezierPath
*
progressline
;
@end
...
...
PNChartDemo/PNChart/PNLineChart.m
View file @
6d9e48f
...
...
@@ -20,6 +20,8 @@
@property
(
nonatomic
,
strong
)
NSMutableArray
*
chartLineArray
;
// Array[CAShapeLayer]
@property
(
strong
,
nonatomic
)
NSMutableArray
*
chartPath
;
//Array of line path, one for each line.
-
(
void
)
setDefaultValues
;
@end
...
...
@@ -90,43 +92,53 @@
-
(
void
)
touchesBegan
:(
NSSet
*
)
touches
withEvent
:(
UIEvent
*
)
event
{
[
self
che
chPoint
:
touches
withEvent
:
event
];
[
self
tou
chPoint
:
touches
withEvent
:
event
];
}
-
(
void
)
touchesMoved
:(
NSSet
*
)
touches
withEvent
:(
UIEvent
*
)
event
{
[
self
che
chPoint
:
touches
withEvent
:
event
];
[
self
tou
chPoint
:
touches
withEvent
:
event
];
}
-
(
void
)
che
chPoint
:(
NSSet
*
)
touches
withEvent
:(
UIEvent
*
)
event
-
(
void
)
tou
chPoint
:(
NSSet
*
)
touches
withEvent
:(
UIEvent
*
)
event
{
//Get the point user touched
UITouch
*
touch
=
[
touches
anyObject
];
CGPoint
touchPoint
=
[
touch
locationInView
:
self
];
CGPathRef
originalPath
=
_progressline
.
CGPath
;
CGPathRef
strokedPath
=
CGPathCreateCopyByStrokingPath
(
originalPath
,
NULL
,
3
.
0
,
kCGLineCapRound
,
kCGLineJoinRound
,
3
.
0
);
BOOL
pathContainsPoint
=
CGPathContainsPoint
(
strokedPath
,
NULL
,
touchPoint
,
NO
);
if
(
pathContainsPoint
)
{
[
_delegate
userClickedOnLinePoint
:
touchPoint
];
for
(
NSValue
*
val
in
_pathPoints
)
{
CGPoint
p
=
[
val
CGPointValue
];
if
(
p
.
x
+
3
.
0
>
touchPoint
.
x
&&
p
.
x
-
3
.
0
<
touchPoint
.
x
&&
p
.
y
+
3
.
0
>
touchPoint
.
y
&&
p
.
y
-
3
.
0
<
touchPoint
.
y
)
{
[
_delegate
userClickedOnLineKeyPoint
:
touchPoint
andPointIndex
:[
_pathPoints
indexOfObject
:
val
]];
for
(
UIBezierPath
*
path
in
_chartPath
)
{
CGPathRef
originalPath
=
path
.
CGPath
;
CGPathRef
strokedPath
=
CGPathCreateCopyByStrokingPath
(
originalPath
,
NULL
,
3
.
0
,
kCGLineCapRound
,
kCGLineJoinRound
,
3
.
0
);
BOOL
pathContainsPoint
=
CGPathContainsPoint
(
strokedPath
,
NULL
,
touchPoint
,
NO
);
if
(
pathContainsPoint
)
{
[
_delegate
userClickedOnLinePoint
:
touchPoint
lineIndex
:[
_chartPath
indexOfObject
:
path
]];
for
(
NSArray
*
linePointsArray
in
_pathPoints
)
{
for
(
NSValue
*
val
in
linePointsArray
)
{
CGPoint
p
=
[
val
CGPointValue
];
if
(
p
.
x
+
3
.
0
>
touchPoint
.
x
&&
p
.
x
-
3
.
0
<
touchPoint
.
x
&&
p
.
y
+
3
.
0
>
touchPoint
.
y
&&
p
.
y
-
3
.
0
<
touchPoint
.
y
)
{
//Call the delegate and pass the point and index of the point
[
_delegate
userClickedOnLineKeyPoint
:
touchPoint
lineIndex
:[
_pathPoints
indexOfObject
:
linePointsArray
]
andPointIndex
:
[
linePointsArray
indexOfObject
:
val
]];
}
}
}
}
}
}
-
(
void
)
strokeChart
{
for
(
NSUInteger
a
=
0
;
a
<
self
.
chartData
.
count
;
a
++
)
{
PNLineChartData
*
chartData
=
self
.
chartData
[
a
];
CAShapeLayer
*
chartLine
=
(
CAShapeLayer
*
)
self
.
chartLineArray
[
a
];
_chartPath
=
[[
NSMutableArray
alloc
]
init
];
//Draw each line
for
(
NSUInteger
lineIndex
=
0
;
lineIndex
<
self
.
chartData
.
count
;
lineIndex
++
)
{
PNLineChartData
*
chartData
=
self
.
chartData
[
lineIndex
];
CAShapeLayer
*
chartLine
=
(
CAShapeLayer
*
)
self
.
chartLineArray
[
lineIndex
];
UIGraphicsBeginImageContext
(
self
.
frame
.
size
);
_progressline
=
[
UIBezierPath
bezierPath
];
UIBezierPath
*
progressline
=
[
UIBezierPath
bezierPath
];
[
_chartPath
addObject
:
progressline
];
PNLineChartDataItem
*
firstDataItem
=
chartData
.
getData
(
0
);
CGFloat
firstValue
=
firstDataItem
.
y
;
...
...
@@ -138,13 +150,14 @@
}
CGFloat
grade
=
(
float
)
firstValue
/
_yValueMax
;
[
_progressline
moveToPoint
:
CGPointMake
(
xPosition
,
_chartCavanHeight
-
grade
*
_chartCavanHeight
+
_xLabelHeight
)];
[
_pathPoints
addObject
:[
NSValue
valueWithCGPoint
:
CGPointMake
(
xPosition
,
_chartCavanHeight
-
grade
*
_chartCavanHeight
+
_xLabelHeight
)]];
[
_progressline
setLineWidth
:
3
.
0
];
[
_progressline
setLineCapStyle
:
kCGLineCapRound
];
[
_progressline
setLineJoinStyle
:
kCGLineJoinRound
];
NSMutableArray
*
linePointsArray
=
[[
NSMutableArray
alloc
]
init
];
[
progressline
moveToPoint
:
CGPointMake
(
xPosition
,
_chartCavanHeight
-
grade
*
_chartCavanHeight
+
_xLabelHeight
)];
[
linePointsArray
addObject
:[
NSValue
valueWithCGPoint
:
CGPointMake
(
xPosition
,
_chartCavanHeight
-
grade
*
_chartCavanHeight
+
_xLabelHeight
)]];
[
progressline
setLineWidth
:
3
.
0
];
[
progressline
setLineCapStyle
:
kCGLineCapRound
];
[
progressline
setLineJoinStyle
:
kCGLineJoinRound
];
NSInteger
index
=
0
;
for
(
NSUInteger
i
=
0
;
i
<
chartData
.
itemCount
;
i
++
)
{
...
...
@@ -154,13 +167,13 @@
CGFloat
innerGrade
=
value
/
_yValueMax
;
if
(
index
!=
0
)
{
CGPoint
point
=
CGPointMake
(
index
*
_xLabelWidth
+
30
.
0
+
_xLabelWidth
/
2
.
0
,
_chartCavanHeight
-
(
innerGrade
*
_chartCavanHeight
)
+
_xLabelHeight
);
[
_pathPoints
addObject
:[
NSValue
valueWithCGPoint
:
point
]];
[
_
progressline
addLineToPoint
:
point
];
[
_
progressline
moveToPoint
:
point
];
[
linePointsArray
addObject
:[
NSValue
valueWithCGPoint
:
point
]];
[
progressline
addLineToPoint
:
point
];
[
progressline
moveToPoint
:
point
];
}
index
+=
1
;
}
[
_pathPoints
addObject
:[
linePointsArray
copy
]];
// setup the color of the chart line
if
(
chartData
.
color
)
{
chartLine
.
strokeColor
=
[
chartData
.
color
CGColor
];
...
...
@@ -168,9 +181,9 @@
chartLine
.
strokeColor
=
[
PNGreen
CGColor
];
}
[
_
progressline
stroke
];
[
progressline
stroke
];
chartLine
.
path
=
_
progressline
.
CGPath
;
chartLine
.
path
=
progressline
.
CGPath
;
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
...
...
Please
register
or
login
to post a comment