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-13 06:08:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
918d2e99acead1c1cccfc7bfa7c64a31e3a764f2
918d2e99
1 parent
b554b0c8
Update bar chart update
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
31 deletions
PNChart/PNBar.h
PNChart/PNBar.m
PNChart/PNBarChart.h
PNChart/PNBarChart.m
PNChartDemo/PCChartViewController.m
PNChart/PNBar.h
View file @
918d2e9
...
...
@@ -18,5 +18,6 @@
@property
(
nonatomic
)
UIColor
*
barColor
;
@property
(
nonatomic
)
UIColor
*
barColorGradientStart
;
@property
(
nonatomic
)
CGFloat
barRadius
;
@property
(
nonatomic
)
CAShapeLayer
*
gradientMask
;
@end
...
...
PNChart/PNBar.m
View file @
918d2e9
...
...
@@ -38,7 +38,8 @@
-
(
void
)
setGrade
:(
float
)
grade
{
_grade
=
grade
;
NSLog
(
@"New garde %f"
,
grade
);
UIBezierPath
*
progressline
=
[
UIBezierPath
bezierPath
];
[
progressline
moveToPoint
:
CGPointMake
(
self
.
frame
.
size
.
width
/
2
.
0
,
self
.
frame
.
size
.
height
)];
...
...
@@ -46,7 +47,7 @@
[
progressline
setLineWidth
:
1
.
0
];
[
progressline
setLineCapStyle
:
kCGLineCapSquare
];
_chartLine
.
path
=
progressline
.
CGPath
;
if
(
_barColor
)
{
_chartLine
.
strokeColor
=
[
_barColor
CGColor
];
...
...
@@ -55,6 +56,26 @@
_chartLine
.
strokeColor
=
[
PNGreen
CGColor
];
}
if
(
_grade
)
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"path"
];
pathAnimation
.
fromValue
=
(
id
)
_chartLine
.
path
;
pathAnimation
.
toValue
=
(
id
)[
progressline
CGPath
];
pathAnimation
.
duration
=
0
.
5
f
;
pathAnimation
.
autoreverses
=
NO
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
_chartLine
.
path
=
progressline
.
CGPath
;
if
(
_barColorGradientStart
)
{
// Add gradient
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
self
.
gradientMask
.
path
=
progressline
.
CGPath
;
}
}
else
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
...
...
@@ -64,16 +85,17 @@
_chartLine
.
strokeEnd
=
1
.
0
;
_chartLine
.
path
=
progressline
.
CGPath
;
// Check if user wants to add a gradient from the start color to the bar color
if
(
_barColorGradientStart
)
{
// Add gradient
CAShapeLayer
*
gradientMask
=
[
CAShapeLayer
layer
];
gradientMask
.
fillColor
=
[[
UIColor
clearColor
]
CGColor
];
gradientMask
.
strokeColor
=
[[
UIColor
blackColor
]
CGColor
];
gradientMask
.
lineWidth
=
self
.
frame
.
size
.
width
;
gradientMask
.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
self
.
bounds
.
size
.
height
);
gradientMask
.
path
=
progressline
.
CGPath
;
self
.
gradientMask
=
[
CAShapeLayer
layer
];
self
.
gradientMask
.
fillColor
=
[[
UIColor
clearColor
]
CGColor
];
self
.
gradientMask
.
strokeColor
=
[[
UIColor
blackColor
]
CGColor
];
self
.
gradientMask
.
lineWidth
=
self
.
frame
.
size
.
width
;
self
.
gradientMask
.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
self
.
bounds
.
size
.
height
);
self
.
gradientMask
.
path
=
progressline
.
CGPath
;
CAGradientLayer
*
gradientLayer
=
[
CAGradientLayer
layer
];
...
...
@@ -87,14 +109,17 @@
];
gradientLayer
.
colors
=
colors
;
[
gradientLayer
setMask
:
gradientMask
];
[
gradientLayer
setMask
:
self
.
gradientMask
];
[
_chartLine
addSublayer
:
gradientLayer
];
gradientMask
.
strokeEnd
=
1
.
0
;
[
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
self
.
gradientMask
.
strokeEnd
=
1
.
0
;
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
}
_grade
=
grade
;
}
...
...
PNChart/PNBarChart.h
View file @
918d2e9
...
...
@@ -36,6 +36,9 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
@property
(
nonatomic
)
NSArray
*
strokeColors
;
/** Update Values. */
-
(
void
)
updateChartData
:(
NSArray
*
)
data
;
/** Changes chart margin. */
@property
(
nonatomic
)
CGFloat
yChartLabelWidth
;
...
...
PNChart/PNBarChart.m
View file @
918d2e9
...
...
@@ -91,6 +91,11 @@
}
}
-
(
void
)
updateChartData
:(
NSArray
*
)
data
{
self
.
yValues
=
data
;
[
self
updateBar
];
}
-
(
void
)
getYValueMax
:(
NSArray
*
)
yLabels
{
int
max
=
[[
yLabels
valueForKeyPath
:
@"@max.intValue"
]
intValue
];
...
...
@@ -151,28 +156,20 @@
_strokeColor
=
strokeColor
;
}
-
(
void
)
strokeChart
-
(
void
)
updateBar
{
//Add Labels
[
self
viewCleanupForCollection
:
_bars
];
//Add bars
CGFloat
chartCavanHeight
=
self
.
frame
.
size
.
height
-
_chartMargin
*
2
-
xLabelHeight
;
NSInteger
index
=
0
;
for
(
NSNumber
*
valueString
in
_yValues
)
{
float
value
=
[
valueString
floatValue
];
float
grade
=
(
float
)
value
/
(
float
)
_yValueMax
;
if
(
isnan
(
grade
))
{
grade
=
0
;
}
PNBar
*
bar
;
if
(
_bars
.
count
==
_yValues
.
count
)
{
bar
=
[
_bars
objectAtIndex
:
index
];
}
else
{
CGFloat
barWidth
;
CGFloat
barXPosition
;
...
...
@@ -208,23 +205,40 @@
}
else
{
bar
.
barColor
=
[
self
barColorAtIndex
:
index
];
}
//Height Of Bar
bar
.
grade
=
grade
;
// Add gradient
bar
.
barColorGradientStart
=
_barColorGradientStart
;
//For Click Index
bar
.
tag
=
index
;
[
_bars
addObject
:
bar
];
[
self
addSubview
:
bar
];
}
//Height Of Bar
float
value
=
[
valueString
floatValue
];
float
grade
=
(
float
)
value
/
(
float
)
_yValueMax
;
if
(
isnan
(
grade
))
{
grade
=
0
;
}
bar
.
grade
=
grade
;
index
+=
1
;
}
}
-
(
void
)
strokeChart
{
//Add Labels
[
self
viewCleanupForCollection
:
_bars
];
//Update Bar
[
self
updateBar
];
//Add chart border lines
...
...
PNChartDemo/PCChartViewController.m
View file @
918d2e9
...
...
@@ -136,7 +136,7 @@
else
if
([
self
.
title
isEqualToString
:
@"Bar Chart"
])
{
[
self
.
barChart
setXLabels
:@[
@"Jan 1"
,
@"Jan 2"
,
@"Jan 3"
,
@"Jan 4"
,
@"Jan 5"
,
@"Jan 6"
,
@"Jan 7"
]];
[
self
.
barChart
setYValues
:@[
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
)]];
[
self
.
barChart
updateChartData
:@[
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
)]];
}
}
...
...
Please
register
or
login
to post a comment