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
2015-08-24 11:58:49 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
bd4d2709f237c2d02e210d2ff167ad78023e56fb
bd4d2709
2 parents
6f9ff037
7d2c641d
Merge branch 'jerrygdm-multiple-selection'
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
14 deletions
PNChart/PNPieChart.h
PNChart/PNPieChart.m
PNChartDemo.xcworkspace/contents.xcworkspacedata
PNChartDemo/Base.lproj/Main.storyboard
PNChartDemo/PCChartViewController.h
PNChartDemo/PCChartViewController.m
Podfile.lock
PNChart/PNPieChart.h
View file @
bd4d270
...
...
@@ -55,6 +55,9 @@
/** Update chart items. Does not update chart itself. */
-
(
void
)
updateChartData
:(
NSArray
*
)
data
;
/** Multiple selection */
@property
(
nonatomic
,
assign
)
BOOL
enableMultipleSelection
;
-
(
void
)
strokeChart
;
-
(
void
)
recompute
;
...
...
PNChart/PNPieChart.m
View file @
bd4d270
...
...
@@ -20,6 +20,8 @@
@property
(
nonatomic
)
NSMutableArray
*
descriptionLabels
;
@property
(
strong
,
nonatomic
)
CAShapeLayer
*
sectorHighlight
;
@property
(
nonatomic
,
strong
)
NSMutableDictionary
*
selectedItems
;
-
(
void
)
loadDefault
;
-
(
UILabel
*
)
descriptionLabelForItemAtIndex
:(
NSUInteger
)
index
;
...
...
@@ -45,12 +47,16 @@
self
=
[
self
initWithFrame
:
frame
];
if
(
self
){
_items
=
[
NSArray
arrayWithArray
:
items
];
_selectedItems
=
[
NSMutableDictionary
dictionary
];
_outerCircleRadius
=
CGRectGetWidth
(
self
.
bounds
)
/
2
;
_innerCircleRadius
=
CGRectGetWidth
(
self
.
bounds
)
/
6
;
_descriptionTextColor
=
[
UIColor
whiteColor
];
_descriptionTextFont
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
18
.
0
];
_descriptionTextShadowColor
=
[[
UIColor
blackColor
]
colorWithAlphaComponent
:
0
.
4
];
_descriptionTextShadowOffset
=
CGSizeMake
(
0
,
1
);
_duration
=
1
.
0
;
_shouldHighlightSectorOnTouch
=
YES
;
_enableMultipleSelection
=
NO
;
[
super
setupDefaultValues
];
[
self
loadDefault
];
...
...
@@ -285,15 +291,17 @@
while
(
percentage
>
[
self
endPercentageForItemAtIndex
:
index
])
{
index
++
;
}
if
([
self
.
delegate
respondsToSelector
:
@selector
(
userClickedOnPieIndexItem
:)])
{
[
self
.
delegate
userClickedOnPieIndexItem
:
index
];
}
if
(
self
.
shouldHighlightSectorOnTouch
)
{
if
(
self
.
sectorHighlight
)
{
[
self
.
sectorHighlight
removeFromSuperlayer
];
if
(
self
.
shouldHighlightSectorOnTouch
)
{
if
(
!
self
.
enableMultipleSelection
)
{
if
(
self
.
sectorHighlight
)
[
self
.
sectorHighlight
removeFromSuperlayer
];
}
PNPieChartDataItem
*
currentItem
=
[
self
dataItemForIndex
:
index
];
...
...
@@ -306,13 +314,33 @@
CGFloat
startPercnetage
=
[
self
startPercentageForItemAtIndex
:
index
];
CGFloat
endPercentage
=
[
self
endPercentageForItemAtIndex
:
index
];
self
.
sectorHighlight
=
[
self
newCircleLayerWithRadius
:
_outerCircleRadius
+
5
self
.
sectorHighlight
=
[
self
newCircleLayerWithRadius
:
_outerCircleRadius
+
5
borderWidth
:
10
fillColor
:
[
UIColor
clearColor
]
borderColor
:
newColor
startPercentage
:
startPercnetage
endPercentage
:
endPercentage
];
[
_contentView
.
layer
addSublayer
:
self
.
sectorHighlight
];
if
(
self
.
enableMultipleSelection
)
{
NSString
*
dictIndex
=
[
NSString
stringWithFormat
:
@"%d"
,
index
];
CAShapeLayer
*
indexShape
=
[
self
.
selectedItems
valueForKey
:
dictIndex
];
if
(
indexShape
)
{
[
indexShape
removeFromSuperlayer
];
[
self
.
selectedItems
removeObjectForKey
:
dictIndex
];
}
else
{
[
self
.
selectedItems
setObject
:
self
.
sectorHighlight
forKey
:
dictIndex
];
[
_contentView
.
layer
addSublayer
:
self
.
sectorHighlight
];
}
}
else
{
[
_contentView
.
layer
addSublayer
:
self
.
sectorHighlight
];
}
}
}
...
...
@@ -403,7 +431,7 @@
x
+=
self
.
legendStyle
==
PNLegendItemStyleStacked
?
0
:
labelsize
.
width
+
beforeLabel
;
y
+=
self
.
legendStyle
==
PNLegendItemStyleStacked
?
labelsize
.
height
:
0
;
totalHeight
=
self
.
legendStyle
==
PNLegendItemStyleSerial
?
fmaxf
(
totalHeight
,
rowMaxHeight
+
y
)
:
totalHeight
+
labelsize
.
height
;
[
legendViews
addObject
:
label
];
counter
++
;
...
...
@@ -428,7 +456,7 @@
CGContextRef
context
=
UIGraphicsGetCurrentContext
();
CGContextAddArc
(
context
,
size
/
2
,
size
/
2
,
size
/
2
,
0
,
M_PI
*
2
,
YES
);
//Set some fill color
CGContextSetFillColorWithColor
(
context
,
color
.
CGColor
);
...
...
PNChartDemo.xcworkspace/contents.xcworkspacedata
View file @
bd4d270
<?xml version='1.0' encoding='UTF-8'?>
<Workspace
version=
'1.0'
><FileRef
location=
'group:PNChartDemo.xcodeproj'
/><FileRef
location=
'group:Pods/Pods.xcodeproj'
/></Workspace>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version =
"1.0"
>
<FileRef
location =
"group:PNChartDemo.xcodeproj"
>
</FileRef>
<FileRef
location =
"group:Pods/Pods.xcodeproj"
>
</FileRef>
</Workspace>
...
...
PNChartDemo/Base.lproj/Main.storyboard
View file @
bd4d270
This diff is collapsed. Click to expand it.
PNChartDemo/PCChartViewController.h
View file @
bd4d270
...
...
@@ -25,12 +25,13 @@
@property
(
weak
,
nonatomic
)
IBOutlet
UIButton
*
changeValueButton
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
leftSwitch
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
centerSwitch
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
rightSwitch
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
leftLabel
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
rightLabel
;
-
(
IBAction
)
rightSwitchChanged
:(
id
)
sender
;
-
(
IBAction
)
leftSwitchChanged
:(
id
)
sender
;
-
(
IBAction
)
rightSwitchChanged
:(
id
)
sender
;
@end
...
...
PNChartDemo/PCChartViewController.m
View file @
bd4d270
...
...
@@ -344,6 +344,15 @@
}
}
-
(
IBAction
)
centerSwitchChanged
:
(
id
)
sender
{
if
(
self
.
pieChart
)
{
[
self
.
pieChart
setEnableMultipleSelection
:
self
.
centerSwitch
.
on
];
[
self
.
pieChart
strokeChart
];
}
}
-
(
IBAction
)
leftSwitchChanged
:
(
id
)
sender
{
if
([
self
.
title
isEqualToString
:
@"Pie Chart"
]){
UISwitch
*
showRelative
=
(
UISwitch
*
)
sender
;
...
...
Podfile.lock
View file @
bd4d270
PODS:
- Expecta (
0.4
.2)
- Expecta (
1.0
.2)
- UICountingLabel (1.2.0)
DEPENDENCIES:
...
...
@@ -7,7 +7,7 @@ DEPENDENCIES:
- UICountingLabel (~> 1.2.0)
SPEC CHECKSUMS:
Expecta:
78b4e8b0c8291fa4524d7f74016b6065c2e391ec
Expecta:
54e8a3530add08f4f0208c111355eda7cde74a53
UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa
COCOAPODS: 0.3
8.2
COCOAPODS: 0.3
5.0
...
...
Please
register
or
login
to post a comment