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
andi
2015-03-02 09:54:33 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4fe9108592354b6b4fe4967a667fec897cd9325d
4fe91085
1 parent
416700b2
added the customisation of relative and absolute values on pie chart and labels on/off
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
6 deletions
PNChart/PNPieChart.h
PNChart/PNPieChart.m
PNChartDemo/Base.lproj/Main.storyboard
PNChartDemo/PCChartViewController.h
PNChartDemo/PCChartViewController.m
PNChart/PNPieChart.h
View file @
4fe9108
...
...
@@ -31,6 +31,13 @@
/** Default is 1.0. */
@property
(
nonatomic
)
NSTimeInterval
duration
;
/** Show only values, this is useful when legend is present */
@property
(
nonatomic
)
BOOL
showOnlyValues
;
/** Show absolute values not relative i.e. percentages */
@property
(
nonatomic
)
BOOL
showAbsoluteValues
;
-
(
void
)
strokeChart
;
@end
...
...
PNChart/PNPieChart.m
View file @
4fe9108
...
...
@@ -127,13 +127,18 @@
UILabel
*
descriptionLabel
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
100
,
80
)];
NSString
*
titleText
=
currentDataItem
.
textDescription
;
if
(
!
titleText
){
titleText
=
[
NSString
stringWithFormat
:
@"%.0f%%"
,
currentDataItem
.
value
/
_total
*
100
];
descriptionLabel
.
text
=
titleText
;
NSString
*
titleValue
;
if
(
self
.
showAbsoluteValues
)
{
titleValue
=
[
NSString
stringWithFormat
:
@"%.0f"
,
currentDataItem
.
value
];
}
else
{
titleValue
=
[
NSString
stringWithFormat
:
@"%.0f%%"
,
currentDataItem
.
value
/
_total
*
100
];
}
if
(
!
titleText
||
self
.
showOnlyValues
){
descriptionLabel
.
text
=
titleValue
;
}
else
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%.0f%%
\n
"
,
currentDataItem
.
value
/
_total
*
100
];
str
=
[
str
stringByAppendingString
:
titleText
];
NSString
*
str
=
[
titleValue
stringByAppendingString
:[
NSString
stringWithFormat
:
@"
\n
%@"
,
titleText
]];
descriptionLabel
.
text
=
str
;
}
...
...
PNChartDemo/Base.lproj/Main.storyboard
View file @
4fe9108
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"6254"
systemVersion=
"14
B25
"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
initialViewController=
"9Rt-UT-IxH"
>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"
version=
"3.0"
toolsVersion=
"6254"
systemVersion=
"14
C109
"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
initialViewController=
"9Rt-UT-IxH"
>
<dependencies>
<deployment
identifier=
"iOS"
/>
<plugIn
identifier=
"com.apple.InterfaceBuilder.IBCocoaTouchPlugin"
version=
"6247"
/>
...
...
@@ -32,6 +32,30 @@
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor"
/>
<nil
key=
"highlightedColor"
/>
</label>
<switch
opaque=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"750"
verticalHuggingPriority=
"750"
fixedFrame=
"YES"
contentHorizontalAlignment=
"center"
contentVerticalAlignment=
"center"
on=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"ORA-mb-hJl"
>
<rect
key=
"frame"
x=
"16"
y=
"489"
width=
"51"
height=
"31"
/>
<connections>
<action
selector=
"leftSwitchChanged:"
destination=
"Tha-Wr-sPW"
eventType=
"valueChanged"
id=
"q9T-QK-Sas"
/>
</connections>
</switch>
<switch
opaque=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"750"
verticalHuggingPriority=
"750"
fixedFrame=
"YES"
contentHorizontalAlignment=
"center"
contentVerticalAlignment=
"center"
on=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"qR7-40-7ir"
>
<rect
key=
"frame"
x=
"261"
y=
"489"
width=
"51"
height=
"31"
/>
<connections>
<action
selector=
"rightSwitchChanged:"
destination=
"Tha-Wr-sPW"
eventType=
"valueChanged"
id=
"n6V-lL-r8Q"
/>
</connections>
</switch>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
fixedFrame=
"YES"
text=
"Percentage"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"IKu-qh-ksi"
>
<rect
key=
"frame"
x=
"16"
y=
"528"
width=
"88"
height=
"21"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"17"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor"
/>
<nil
key=
"highlightedColor"
/>
</label>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
fixedFrame=
"YES"
text=
"Show Labels"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"Ifm-a9-Wkq"
>
<rect
key=
"frame"
x=
"211"
y=
"527"
width=
"99"
height=
"21"
/>
<fontDescription
key=
"fontDescription"
type=
"system"
pointSize=
"17"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
<color
key=
"backgroundColor"
white=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"calibratedWhite"
/>
<constraints>
...
...
@@ -44,6 +68,10 @@
<navigationItem
key=
"navigationItem"
title=
"PNChart"
id=
"Ukg-Sg-E2z"
/>
<connections>
<outlet
property=
"changeValueButton"
destination=
"L3F-13-Wf5"
id=
"JnI-y3-Xpj"
/>
<outlet
property=
"leftLabel"
destination=
"IKu-qh-ksi"
id=
"CPy-oy-qCP"
/>
<outlet
property=
"leftSwitch"
destination=
"ORA-mb-hJl"
id=
"u1M-2f-6P1"
/>
<outlet
property=
"rightLabel"
destination=
"Ifm-a9-Wkq"
id=
"QhE-j2-qpe"
/>
<outlet
property=
"rightSwitch"
destination=
"qR7-40-7ir"
id=
"noL-6R-d3a"
/>
<outlet
property=
"titleLabel"
destination=
"FUU-vZ-jMd"
id=
"dA3-KC-Ht4"
/>
</connections>
</viewController>
...
...
PNChartDemo/PCChartViewController.h
View file @
4fe9108
...
...
@@ -23,4 +23,13 @@
-
(
IBAction
)
changeValue
:(
id
)
sender
;
@property
(
weak
,
nonatomic
)
IBOutlet
UIButton
*
changeValueButton
;
@property
(
weak
,
nonatomic
)
IBOutlet
UISwitch
*
leftSwitch
;
@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
;
@end
...
...
PNChartDemo/PCChartViewController.m
View file @
4fe9108
...
...
@@ -16,6 +16,11 @@
[
super
viewDidLoad
];
self
.
titleLabel
.
textColor
=
PNFreshGreen
;
self
.
leftSwitch
.
hidden
=
YES
;
self
.
rightSwitch
.
hidden
=
YES
;
self
.
leftLabel
.
hidden
=
YES
;
self
.
rightLabel
.
hidden
=
YES
;
if
([
self
.
title
isEqualToString
:
@"Line Chart"
])
{
self
.
titleLabel
.
text
=
@"Line Chart"
;
...
...
@@ -116,6 +121,11 @@
else
if
([
self
.
title
isEqualToString
:
@"Pie Chart"
])
{
self
.
titleLabel
.
text
=
@"Pie Chart"
;
self
.
leftSwitch
.
hidden
=
NO
;
self
.
rightSwitch
.
hidden
=
NO
;
self
.
leftLabel
.
hidden
=
NO
;
self
.
rightLabel
.
hidden
=
NO
;
NSArray
*
items
=
@[[
PNPieChartDataItem
dataItemWithValue
:
10
color
:
PNLightGreen
],
[
PNPieChartDataItem
dataItemWithValue
:
20
color
:
PNFreshGreen
description
:
@"WWDC"
],
...
...
@@ -126,6 +136,8 @@
self
.
pieChart
.
descriptionTextColor
=
[
UIColor
whiteColor
];
self
.
pieChart
.
descriptionTextFont
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
11
.
0
];
self
.
pieChart
.
descriptionTextShadowColor
=
[
UIColor
clearColor
];
self
.
pieChart
.
showAbsoluteValues
=
NO
;
self
.
pieChart
.
showOnlyValues
=
NO
;
[
self
.
pieChart
strokeChart
];
...
...
@@ -272,4 +284,27 @@
return
(
NSArray
*
)
array
;
}
-
(
IBAction
)
rightSwitchChanged
:
(
id
)
sender
{
if
([
self
.
title
isEqualToString
:
@"Pie Chart"
]){
UISwitch
*
showLabels
=
(
UISwitch
*
)
sender
;
if
(
showLabels
.
on
)
{
self
.
pieChart
.
showOnlyValues
=
NO
;
}
else
{
self
.
pieChart
.
showOnlyValues
=
YES
;
}
[
self
.
pieChart
strokeChart
];
}
}
-
(
IBAction
)
leftSwitchChanged
:
(
id
)
sender
{
if
([
self
.
title
isEqualToString
:
@"Pie Chart"
]){
UISwitch
*
showRelative
=
(
UISwitch
*
)
sender
;
if
(
showRelative
.
on
)
{
self
.
pieChart
.
showAbsoluteValues
=
NO
;
}
else
{
self
.
pieChart
.
showAbsoluteValues
=
YES
;
}
[
self
.
pieChart
strokeChart
];
}
}
@end
...
...
Please
register
or
login
to post a comment