andi

added the customisation of relative and absolute values on pie chart and labels on/off

@@ -31,6 +31,13 @@ @@ -31,6 +31,13 @@
31 /** Default is 1.0. */ 31 /** Default is 1.0. */
32 @property (nonatomic) NSTimeInterval duration; 32 @property (nonatomic) NSTimeInterval duration;
33 33
  34 +/** Show only values, this is useful when legend is present */
  35 +@property (nonatomic) BOOL showOnlyValues;
  36 +
  37 +
  38 +/** Show absolute values not relative i.e. percentages */
  39 +@property (nonatomic) BOOL showAbsoluteValues;
  40 +
34 - (void)strokeChart; 41 - (void)strokeChart;
35 42
36 @end 43 @end
@@ -127,13 +127,18 @@ @@ -127,13 +127,18 @@
127 127
128 UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 80)]; 128 UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 80)];
129 NSString *titleText = currentDataItem.textDescription; 129 NSString *titleText = currentDataItem.textDescription;
130 - if(!titleText){ 130 + NSString *titleValue;
131 - titleText = [NSString stringWithFormat:@"%.0f%%",currentDataItem.value/ _total * 100]; 131 +
132 - descriptionLabel.text = titleText ; 132 + if (self.showAbsoluteValues) {
  133 + titleValue = [NSString stringWithFormat:@"%.0f",currentDataItem.value];
  134 + }else{
  135 + titleValue = [NSString stringWithFormat:@"%.0f%%",currentDataItem.value/ _total * 100];
  136 + }
  137 + if(!titleText || self.showOnlyValues){
  138 + descriptionLabel.text = titleValue;
133 } 139 }
134 else { 140 else {
135 - NSString* str = [NSString stringWithFormat:@"%.0f%%\n",currentDataItem.value/ _total * 100]; 141 + NSString* str = [titleValue stringByAppendingString:[NSString stringWithFormat:@"\n%@",titleText]];
136 - str = [str stringByAppendingString:titleText];  
137 descriptionLabel.text = str ; 142 descriptionLabel.text = str ;
138 } 143 }
139 144
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="9Rt-UT-IxH"> 2 +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="9Rt-UT-IxH">
3 <dependencies> 3 <dependencies>
4 <deployment identifier="iOS"/> 4 <deployment identifier="iOS"/>
5 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/> 5 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
@@ -32,6 +32,30 @@ @@ -32,6 +32,30 @@
32 <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> 32 <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
33 <nil key="highlightedColor"/> 33 <nil key="highlightedColor"/>
34 </label> 34 </label>
  35 + <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ORA-mb-hJl">
  36 + <rect key="frame" x="16" y="489" width="51" height="31"/>
  37 + <connections>
  38 + <action selector="leftSwitchChanged:" destination="Tha-Wr-sPW" eventType="valueChanged" id="q9T-QK-Sas"/>
  39 + </connections>
  40 + </switch>
  41 + <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qR7-40-7ir">
  42 + <rect key="frame" x="261" y="489" width="51" height="31"/>
  43 + <connections>
  44 + <action selector="rightSwitchChanged:" destination="Tha-Wr-sPW" eventType="valueChanged" id="n6V-lL-r8Q"/>
  45 + </connections>
  46 + </switch>
  47 + <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">
  48 + <rect key="frame" x="16" y="528" width="88" height="21"/>
  49 + <fontDescription key="fontDescription" type="system" pointSize="17"/>
  50 + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
  51 + <nil key="highlightedColor"/>
  52 + </label>
  53 + <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">
  54 + <rect key="frame" x="211" y="527" width="99" height="21"/>
  55 + <fontDescription key="fontDescription" type="system" pointSize="17"/>
  56 + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
  57 + <nil key="highlightedColor"/>
  58 + </label>
35 </subviews> 59 </subviews>
36 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> 60 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
37 <constraints> 61 <constraints>
@@ -44,6 +68,10 @@ @@ -44,6 +68,10 @@
44 <navigationItem key="navigationItem" title="PNChart" id="Ukg-Sg-E2z"/> 68 <navigationItem key="navigationItem" title="PNChart" id="Ukg-Sg-E2z"/>
45 <connections> 69 <connections>
46 <outlet property="changeValueButton" destination="L3F-13-Wf5" id="JnI-y3-Xpj"/> 70 <outlet property="changeValueButton" destination="L3F-13-Wf5" id="JnI-y3-Xpj"/>
  71 + <outlet property="leftLabel" destination="IKu-qh-ksi" id="CPy-oy-qCP"/>
  72 + <outlet property="leftSwitch" destination="ORA-mb-hJl" id="u1M-2f-6P1"/>
  73 + <outlet property="rightLabel" destination="Ifm-a9-Wkq" id="QhE-j2-qpe"/>
  74 + <outlet property="rightSwitch" destination="qR7-40-7ir" id="noL-6R-d3a"/>
47 <outlet property="titleLabel" destination="FUU-vZ-jMd" id="dA3-KC-Ht4"/> 75 <outlet property="titleLabel" destination="FUU-vZ-jMd" id="dA3-KC-Ht4"/>
48 </connections> 76 </connections>
49 </viewController> 77 </viewController>
@@ -23,4 +23,13 @@ @@ -23,4 +23,13 @@
23 - (IBAction)changeValue:(id)sender; 23 - (IBAction)changeValue:(id)sender;
24 @property (weak, nonatomic) IBOutlet UIButton *changeValueButton; 24 @property (weak, nonatomic) IBOutlet UIButton *changeValueButton;
25 25
  26 +@property (weak, nonatomic) IBOutlet UISwitch *leftSwitch;
  27 +@property (weak, nonatomic) IBOutlet UISwitch *rightSwitch;
  28 +@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
  29 +@property (weak, nonatomic) IBOutlet UILabel *rightLabel;
  30 +
  31 +- (IBAction)rightSwitchChanged:(id)sender;
  32 +- (IBAction)leftSwitchChanged:(id)sender;
  33 +
  34 +
26 @end 35 @end
@@ -16,6 +16,11 @@ @@ -16,6 +16,11 @@
16 [super viewDidLoad]; 16 [super viewDidLoad];
17 self.titleLabel.textColor = PNFreshGreen; 17 self.titleLabel.textColor = PNFreshGreen;
18 18
  19 + self.leftSwitch.hidden = YES;
  20 + self.rightSwitch.hidden = YES;
  21 + self.leftLabel.hidden = YES;
  22 + self.rightLabel.hidden = YES;
  23 +
19 if ([self.title isEqualToString:@"Line Chart"]) { 24 if ([self.title isEqualToString:@"Line Chart"]) {
20 25
21 self.titleLabel.text = @"Line Chart"; 26 self.titleLabel.text = @"Line Chart";
@@ -116,6 +121,11 @@ @@ -116,6 +121,11 @@
116 else if ([self.title isEqualToString:@"Pie Chart"]) 121 else if ([self.title isEqualToString:@"Pie Chart"])
117 { 122 {
118 self.titleLabel.text = @"Pie Chart"; 123 self.titleLabel.text = @"Pie Chart";
  124 + self.leftSwitch.hidden = NO;
  125 + self.rightSwitch.hidden = NO;
  126 + self.leftLabel.hidden = NO;
  127 + self.rightLabel.hidden = NO;
  128 +
119 129
120 NSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNLightGreen], 130 NSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNLightGreen],
121 [PNPieChartDataItem dataItemWithValue:20 color:PNFreshGreen description:@"WWDC"], 131 [PNPieChartDataItem dataItemWithValue:20 color:PNFreshGreen description:@"WWDC"],
@@ -126,6 +136,8 @@ @@ -126,6 +136,8 @@
126 self.pieChart.descriptionTextColor = [UIColor whiteColor]; 136 self.pieChart.descriptionTextColor = [UIColor whiteColor];
127 self.pieChart.descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:11.0]; 137 self.pieChart.descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:11.0];
128 self.pieChart.descriptionTextShadowColor = [UIColor clearColor]; 138 self.pieChart.descriptionTextShadowColor = [UIColor clearColor];
  139 + self.pieChart.showAbsoluteValues = NO;
  140 + self.pieChart.showOnlyValues = NO;
129 [self.pieChart strokeChart]; 141 [self.pieChart strokeChart];
130 142
131 143
@@ -272,4 +284,27 @@ @@ -272,4 +284,27 @@
272 return (NSArray*) array; 284 return (NSArray*) array;
273 } 285 }
274 286
  287 +- (IBAction)rightSwitchChanged:(id)sender {
  288 + if ([self.title isEqualToString:@"Pie Chart"]){
  289 + UISwitch *showLabels = (UISwitch*) sender;
  290 + if (showLabels.on) {
  291 + self.pieChart.showOnlyValues = NO;
  292 + }else{
  293 + self.pieChart.showOnlyValues = YES;
  294 + }
  295 + [self.pieChart strokeChart];
  296 + }
  297 +}
  298 +
  299 +- (IBAction)leftSwitchChanged:(id)sender {
  300 + if ([self.title isEqualToString:@"Pie Chart"]){
  301 + UISwitch *showRelative = (UISwitch*) sender;
  302 + if (showRelative.on) {
  303 + self.pieChart.showAbsoluteValues = NO;
  304 + }else{
  305 + self.pieChart.showAbsoluteValues = YES;
  306 + }
  307 + [self.pieChart strokeChart];
  308 + }
  309 +}
275 @end 310 @end