diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edc082c --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Xcode +build/* +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +*.xcworkspace +!default.xcworkspace +xcuserdata +profile +*.moved-aside diff --git a/.gitmodules b/.gitmodules index 41d3d09..b5bf6b4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "iOSPlot/JSONKit"] path = iOSPlot/JSONKit url = git://github.com/johnezang/JSONKit.git +[submodule "iOSPlot/FPPopover"] + path = iOSPlot/FPPopover + url = https://github.com/50pixels/FPPopover.git diff --git a/iOSPlot/.DS_Store b/iOSPlot/.DS_Store new file mode 100644 index 0000000..ba8e331 Binary files /dev/null and b/iOSPlot/.DS_Store differ diff --git a/iOSPlot/FPPopover b/iOSPlot/FPPopover new file mode 160000 index 0000000..9fbe74c --- /dev/null +++ b/iOSPlot/FPPopover @@ -0,0 +1 @@ +Subproject commit 9fbe74c1867ef45055e8740534478243f26e6221 diff --git a/iOSPlot/PieChartPopover.h b/iOSPlot/PieChartPopover.h new file mode 100644 index 0000000..57e0fcf --- /dev/null +++ b/iOSPlot/PieChartPopover.h @@ -0,0 +1,21 @@ +// +// PieChartPopover.h +// PlotCreator +// +// Created by gustavo halperin on 8/16/12. +// +// + +#import + +@interface PieChartPopover : UIViewController + +@property (strong, nonatomic) IBOutlet NSString *chartTitle; +@property (strong, nonatomic) IBOutlet NSString *chartSubTitle; +@property (strong, nonatomic) IBOutlet NSString *chartContent; + +@property (strong, nonatomic) IBOutlet UILabel *titleLabel; +@property (strong, nonatomic) IBOutlet UILabel *subTitleLabel; +@property (strong, nonatomic) IBOutlet UITextView *contentTextView; + +@end diff --git a/iOSPlot/PieChartPopover.m b/iOSPlot/PieChartPopover.m new file mode 100644 index 0000000..fc14b65 --- /dev/null +++ b/iOSPlot/PieChartPopover.m @@ -0,0 +1,59 @@ +// +// PieChartPopover.m +// PlotCreator +// +// Created by gustavo halperin on 8/16/12. +// +// + +#import "PieChartPopover.h" + +@interface PieChartPopover () + +@end + +@implementation PieChartPopover +@synthesize chartTitle = _chartTitle; +@synthesize chartSubTitle = _chartSubTitle; +@synthesize chartContent = _chartContent; +@synthesize titleLabel = _titleLabel; +@synthesize subTitleLabel = _subTitleLabel; +@synthesize contentTextView = _contentTextView; + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. + self.titleLabel.text = _chartTitle; + self.subTitleLabel.text = _chartSubTitle; + self.contentTextView.text = _chartContent; +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; + [self setChartTitle:nil]; + [self setChartSubTitle:nil]; + [self setChartContent:nil]; + [self setTitleLabel:nil]; + [self setSubTitleLabel:nil]; + [self setContentTextView:nil]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return YES; +} + +@end diff --git a/iOSPlot/PieChartPopover.xib b/iOSPlot/PieChartPopover.xib new file mode 100644 index 0000000..aed1c99 --- /dev/null +++ b/iOSPlot/PieChartPopover.xib @@ -0,0 +1,301 @@ + + + + 1296 + 12A269 + 2549 + 1187 + 624.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1498 + + + IBProxyObject + IBUILabel + IBUITextView + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBIPadFramework + + + IBFirstResponder + IBIPadFramework + + + + 274 + + + + 306 + {{20, 20}, {475, 45}} + + + _NS:9 + NO + YES + 7 + NO + IBIPadFramework + Label + + 0 + 10 + + TrebuchetMS-Bold + Trebuchet MS + 2 + 40 + + + TrebuchetMS-Bold + 40 + 16 + + + + + 306 + {{20, 73}, {475, 45}} + + + _NS:9 + NO + YES + 7 + NO + IBIPadFramework + Label + + 0 + 10 + + TrebuchetMS-Bold + Trebuchet MS + 2 + 26 + + + TrebuchetMS-Bold + 26 + 16 + + + + + 306 + {{157, 126}, {338, 233}} + + + _NS:9 + + 1 + MSAxIDEAA + + YES + YES + IBIPadFramework + NO + NO + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + 1 + MCAwIDEAA + + + 2 + IBCocoaTouchFramework + + + TrebuchetMS + Trebuchet MS + 0 + 14 + + + TrebuchetMS + 14 + 16 + + + + {515, 379} + + + + 3 + MQA + + NO + + IBUISimulatedFreeformSizeMetricsSentinel + Freeform + + IBIPadFramework + + + + + + + view + + + + 3 + + + + contentTextView + + + + 12 + + + + subTitleLabel + + + + 13 + + + + titleLabel + + + + 14 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 2 + + + + + + + + + + 4 + + + + + 5 + + + + + 7 + + + + + + + PieChartPopover + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 14 + + + + + PieChartPopover + UIViewController + + NSString + NSString + NSString + UITextView + UILabel + UILabel + + + + chartContent + NSString + + + chartSubTitle + NSString + + + chartTitle + NSString + + + contentTextView + UITextView + + + subTitleLabel + UILabel + + + titleLabel + UILabel + + + + IBProjectSource + ./Classes/PieChartPopover.h + + + + + 0 + IBIPadFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + YES + 3 + 1498 + + diff --git a/iOSPlot/PieChartViewController3.h b/iOSPlot/PieChartViewController3.h new file mode 100644 index 0000000..eb8bdf8 --- /dev/null +++ b/iOSPlot/PieChartViewController3.h @@ -0,0 +1,13 @@ +// +// PieChartViewController3.h +// PlotCreator +// +// Created by gustavo halperin on 8/14/12. +// +// + +#import + +@interface PieChartViewController3 : UIViewController + +@end diff --git a/iOSPlot/PieChartViewController3.m b/iOSPlot/PieChartViewController3.m new file mode 100644 index 0000000..64ae165 --- /dev/null +++ b/iOSPlot/PieChartViewController3.m @@ -0,0 +1,121 @@ +// +// PieChartViewController3.m +// PlotCreator +// +// Created by gustavo halperin on 8/14/12. +// +// + +#import "PieChartViewController3.h" +#import "PCPieChart.h" +#import "PieChartPopover.h" + +@interface PieChartViewController3() + +-(UIViewController*)ViewController: (PCPieComponent*)pieComponent; + +@end + +@implementation PieChartViewController3 + +- (id)init +{ + self = [super init]; + if (self) + { + [self.view setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]]; + [self setTitle:@"Pie Chart"]; + + + int height = [self.view bounds].size.width/3*2.; // 220; + int width = [self.view bounds].size.width; //320; + PCPieChart *pieChart = [[PCPieChart alloc] initWithFrame:CGRectMake(([self.view bounds].size.width-width)/2,([self.view bounds].size.height-height)/2,width,height)]; + [pieChart setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin]; + [pieChart setDiameter:width/2]; + [pieChart setSameColorLabel:YES]; + + [pieChart setShowInnerCircle:YES]; + [pieChart setTitleInnerCircle:@"Center Title"]; + [pieChart setShowValuesInChart:YES]; + + [self.view addSubview:pieChart]; + + if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad) + { + pieChart.titleFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:30]; + pieChart.percentageFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:50]; + } + + NSString *sampleFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"sample_piechart_data.plist"]; + NSDictionary *sampleInfo = [NSDictionary dictionaryWithContentsOfFile:sampleFile]; + NSMutableArray *components = [NSMutableArray array]; + for (int i=0; i<[[sampleInfo objectForKey:@"data"] count]; i++) + { + NSDictionary *item = [[sampleInfo objectForKey:@"data"] objectAtIndex:i]; + PCPieComponent *component = [PCPieComponent pieComponentWithTitle:[item objectForKey:@"title"] value:[[item objectForKey:@"value"] floatValue]]; + component.delegate = self; + [components addObject:component]; + + if (i==0) + { + [component setColour:PCColorYellow]; + } + else if (i==1) + { + [component setColour:PCColorGreen]; + } + else if (i==2) + { + [component setColour:PCColorOrange]; + } + else if (i==3) + { + [component setColour:PCColorRed]; + } + else if (i==4) + { + [component setColour:PCColorBlue]; + } + } + [pieChart setComponents:components]; + + } + return self; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + // Overriden to allow any orientation. + return YES; +} + + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc. that aren't in use. +} + + +- (void)viewDidUnload { + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(UIViewController*)ViewController: (PCPieComponent*)pieComponent +{ + PieChartPopover *pieChartPopover = [[PieChartPopover alloc] init]; + [pieChartPopover setChartTitle:pieComponent.title]; + [pieChartPopover setChartSubTitle:[NSString stringWithFormat:@"Chart Value %f", pieComponent.value]]; + NSString *content = [NSString stringWithFormat:@"Content for chart %@ and value %f ", pieComponent.title, pieComponent.value]; + for (int i = 0; i < 10; i++) { + content = [content stringByAppendingString:content]; + } + [pieChartPopover setChartContent:[NSString stringWithFormat:@"THE CONTENT CAN BE SCROLLED DOWN.\n %@", content]]; + + return pieChartPopover; +} + + +@end diff --git a/iOSPlot/PieChartViewController4.h b/iOSPlot/PieChartViewController4.h new file mode 100644 index 0000000..495497b --- /dev/null +++ b/iOSPlot/PieChartViewController4.h @@ -0,0 +1,13 @@ +// +// PieChartViewController4 +// PlotCreator +// +// Created by Gustavo E Halperin on 8/17/12. +// +// + +#import + +@interface PieChartViewController4 : UIViewController + +@end diff --git a/iOSPlot/PieChartViewController4.m b/iOSPlot/PieChartViewController4.m new file mode 100644 index 0000000..df3c20e --- /dev/null +++ b/iOSPlot/PieChartViewController4.m @@ -0,0 +1,123 @@ +// +// PieChartViewController4 +// PlotCreator +// +// Created by Gustavo E Halperin on 8/17/12. +// +// + +#import "PieChartViewController4.h" +#import "PCPieChart.h" +#import "PieChartPopover.h" + +@interface PieChartViewController4() + +-(UIViewController*)ViewController: (PCPieComponent*)pieComponent; + +@end + +@implementation PieChartViewController4 + +- (id)init +{ + self = [super init]; + if (self) + { + [self.view setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]]; + [self setTitle:@"Pie Chart"]; + + + int width = [self.view bounds].size.width * 0.75f; //320; + int height = width / 3.f * 2.2f; // 220; + PCPieChart *pieChart = [[PCPieChart alloc] initWithFrame:CGRectMake(15,//([self.view bounds].size.width-width)/2, + ([self.view bounds].size.height-height)/2,width,height)]; + [pieChart setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin]; + [pieChart setDiameter: 374];// width/2]; + [pieChart setSameColorLabel:YES]; + + [pieChart setShowInnerCircle:YES]; + [pieChart setTitleInnerCircle:@"Center Title"]; + [pieChart setShowValuesInChart:YES]; + [pieChart setTouchAnimated:YES]; + + [self.view addSubview:pieChart]; + + if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad) + { + pieChart.titleFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:30]; + pieChart.percentageFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:50]; + } + + NSString *sampleFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"sample_piechart_data.plist"]; + NSDictionary *sampleInfo = [NSDictionary dictionaryWithContentsOfFile:sampleFile]; + NSMutableArray *components = [NSMutableArray array]; + for (int i=0; i<[[sampleInfo objectForKey:@"data"] count]; i++) + { + NSDictionary *item = [[sampleInfo objectForKey:@"data"] objectAtIndex:i]; + PCPieComponent *component = [PCPieComponent pieComponentWithTitle:[item objectForKey:@"title"] value:[[item objectForKey:@"value"] floatValue]]; + component.delegate = self; + [components addObject:component]; + + if (i==0) + { + [component setColour:PCColorYellow]; + } + else if (i==1) + { + [component setColour:PCColorGreen]; + } + else if (i==2) + { + [component setColour:PCColorOrange]; + } + else if (i==3) + { + [component setColour:PCColorRed]; + } + else if (i==4) + { + [component setColour:PCColorBlue]; + } + } + [pieChart setComponents:components]; + + } + return self; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + // Overriden to allow any orientation. + return YES; +} + + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc. that aren't in use. +} + + +- (void)viewDidUnload { + [super viewDidUnload]; + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + +-(UIViewController*)ViewController: (PCPieComponent*)pieComponent +{ + PieChartPopover *pieChartPopover = [[PieChartPopover alloc] init]; + [pieChartPopover setChartTitle:pieComponent.title]; + [pieChartPopover setChartSubTitle:[NSString stringWithFormat:@"Chart Value %f", pieComponent.value]]; + NSString *content = [NSString stringWithFormat:@"Content for chart %@ and value %f ", pieComponent.title, pieComponent.value]; + for (int i = 0; i < 10; i++) { + content = [content stringByAppendingString:content]; + } + [pieChartPopover setChartContent:[NSString stringWithFormat:@"THE CONTENT CAN BE SCROLLED DOWN.\n %@", content]]; + + return pieChartPopover; +} + + +@end diff --git a/iOSPlot/PlotCreator.xcodeproj/project.pbxproj b/iOSPlot/PlotCreator.xcodeproj/project.pbxproj index 156456b..571d502 100755 --- a/iOSPlot/PlotCreator.xcodeproj/project.pbxproj +++ b/iOSPlot/PlotCreator.xcodeproj/project.pbxproj @@ -15,6 +15,13 @@ 2860E32E111B888700E27156 /* AppDelegate_iPad.m in Sources */ = {isa = PBXBuildFile; fileRef = 2860E32C111B888700E27156 /* AppDelegate_iPad.m */; }; 2860E32F111B888700E27156 /* MainWindow_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2860E32D111B888700E27156 /* MainWindow_iPad.xib */; }; 288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; }; + 929C6EC415DEF4AC008FD849 /* PieChartViewController4.m in Sources */ = {isa = PBXBuildFile; fileRef = 929C6EC315DEF4AC008FD849 /* PieChartViewController4.m */; }; + C96DD05715DD35EC00939DC6 /* FPPopoverController.m in Sources */ = {isa = PBXBuildFile; fileRef = C96DD05215DD35EC00939DC6 /* FPPopoverController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + C96DD05815DD35EC00939DC6 /* FPPopoverView.m in Sources */ = {isa = PBXBuildFile; fileRef = C96DD05415DD35EC00939DC6 /* FPPopoverView.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + C96DD05915DD35EC00939DC6 /* FPTouchView.m in Sources */ = {isa = PBXBuildFile; fileRef = C96DD05615DD35EC00939DC6 /* FPTouchView.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + C96DD05E15DD39B000939DC6 /* PieChartPopover.m in Sources */ = {isa = PBXBuildFile; fileRef = C96DD05C15DD39B000939DC6 /* PieChartPopover.m */; }; + C96DD05F15DD39B000939DC6 /* PieChartPopover.xib in Resources */ = {isa = PBXBuildFile; fileRef = C96DD05D15DD39B000939DC6 /* PieChartPopover.xib */; }; + C9B46D8E15DAE7880069B114 /* PieChartViewController3.m in Sources */ = {isa = PBXBuildFile; fileRef = C9B46D8D15DAE7880069B114 /* PieChartViewController3.m */; }; F832606A1363D49B0045F9DC /* ChartListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F83260691363D49B0045F9DC /* ChartListViewController.m */; }; F83260AA1363D8170045F9DC /* back_button.png in Resources */ = {isa = PBXBuildFile; fileRef = F83260A81363D8170045F9DC /* back_button.png */; }; F83260AB1363D8170045F9DC /* back_button@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F83260A91363D8170045F9DC /* back_button@2x.png */; }; @@ -44,6 +51,19 @@ 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Shared/main.m; sourceTree = ""; }; 32CA4F630368D1EE00C91783 /* PlotCreator_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlotCreator_Prefix.pch; sourceTree = ""; }; 8D1107310486CEB800E47090 /* PlotCreator-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PlotCreator-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = ""; }; + 929C6EC215DEF4AC008FD849 /* PieChartViewController4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PieChartViewController4.h; sourceTree = ""; }; + 929C6EC315DEF4AC008FD849 /* PieChartViewController4.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PieChartViewController4.m; sourceTree = ""; }; + C96DD05115DD35EC00939DC6 /* FPPopoverController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPPopoverController.h; sourceTree = ""; }; + C96DD05215DD35EC00939DC6 /* FPPopoverController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPPopoverController.m; sourceTree = ""; }; + C96DD05315DD35EC00939DC6 /* FPPopoverView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPPopoverView.h; sourceTree = ""; }; + C96DD05415DD35EC00939DC6 /* FPPopoverView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPPopoverView.m; sourceTree = ""; }; + C96DD05515DD35EC00939DC6 /* FPTouchView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPTouchView.h; sourceTree = ""; }; + C96DD05615DD35EC00939DC6 /* FPTouchView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPTouchView.m; sourceTree = ""; }; + C96DD05B15DD39B000939DC6 /* PieChartPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PieChartPopover.h; sourceTree = ""; }; + C96DD05C15DD39B000939DC6 /* PieChartPopover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PieChartPopover.m; sourceTree = ""; }; + C96DD05D15DD39B000939DC6 /* PieChartPopover.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PieChartPopover.xib; sourceTree = ""; }; + C9B46D8C15DAE7880069B114 /* PieChartViewController3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PieChartViewController3.h; sourceTree = ""; }; + C9B46D8D15DAE7880069B114 /* PieChartViewController3.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PieChartViewController3.m; sourceTree = ""; }; F83260681363D49B0045F9DC /* ChartListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartListViewController.h; path = iPhone/ChartListViewController.h; sourceTree = ""; }; F83260691363D49B0045F9DC /* ChartListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ChartListViewController.m; path = iPhone/ChartListViewController.m; sourceTree = ""; }; F83260A81363D8170045F9DC /* back_button.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = back_button.png; path = Images/back_button.png; sourceTree = ""; }; @@ -113,12 +133,20 @@ 28EEBF621118D79A00187D67 /* Shared */ = { isa = PBXGroup; children = ( + C96DD05015DD35EC00939DC6 /* FPPopover */, 3794799B13706BB200C0E457 /* iOSPlot */, F8C1B407136F7FB7002DDF6C /* JSONKit */, + C96DD05B15DD39B000939DC6 /* PieChartPopover.h */, + C96DD05C15DD39B000939DC6 /* PieChartPopover.m */, + C96DD05D15DD39B000939DC6 /* PieChartPopover.xib */, F897D6FE136311E60025FE6E /* PieChartViewController.h */, F897D6FF136311E60025FE6E /* PieChartViewController.m */, F83260C01363D91E0045F9DC /* PieChartViewController2.h */, F83260C11363D91E0045F9DC /* PieChartViewController2.m */, + C9B46D8C15DAE7880069B114 /* PieChartViewController3.h */, + C9B46D8D15DAE7880069B114 /* PieChartViewController3.m */, + 929C6EC215DEF4AC008FD849 /* PieChartViewController4.h */, + 929C6EC315DEF4AC008FD849 /* PieChartViewController4.m */, F87DE41B1370D82D00347F69 /* HalfPieChartViewController.h */, F87DE41C1370D82D00347F69 /* HalfPieChartViewController.m */, F83260681363D49B0045F9DC /* ChartListViewController.h */, @@ -178,6 +206,19 @@ name = iOSPlot; sourceTree = ""; }; + C96DD05015DD35EC00939DC6 /* FPPopover */ = { + isa = PBXGroup; + children = ( + C96DD05115DD35EC00939DC6 /* FPPopoverController.h */, + C96DD05215DD35EC00939DC6 /* FPPopoverController.m */, + C96DD05315DD35EC00939DC6 /* FPPopoverView.h */, + C96DD05415DD35EC00939DC6 /* FPPopoverView.m */, + C96DD05515DD35EC00939DC6 /* FPTouchView.h */, + C96DD05615DD35EC00939DC6 /* FPTouchView.m */, + ); + path = FPPopover; + sourceTree = ""; + }; F897D6E513630F4B0025FE6E /* Sample Data */ = { isa = PBXGroup; children = ( @@ -254,6 +295,7 @@ F83260AA1363D8170045F9DC /* back_button.png in Resources */, F83260AB1363D8170045F9DC /* back_button@2x.png in Resources */, F8C1B41C136F8056002DDF6C /* sample_linechart_data.json in Resources */, + C96DD05F15DD39B000939DC6 /* PieChartPopover.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -276,6 +318,12 @@ F87DE41A1370D68300347F69 /* PCHalfPieChart.m in Sources */, F87DE41D1370D82D00347F69 /* HalfPieChartViewController.m in Sources */, F8B8196215D573FB0005945A /* JSONKit.m in Sources */, + C9B46D8E15DAE7880069B114 /* PieChartViewController3.m in Sources */, + C96DD05715DD35EC00939DC6 /* FPPopoverController.m in Sources */, + C96DD05815DD35EC00939DC6 /* FPPopoverView.m in Sources */, + C96DD05915DD35EC00939DC6 /* FPTouchView.m in Sources */, + C96DD05E15DD39B000939DC6 /* PieChartPopover.m in Sources */, + 929C6EC415DEF4AC008FD849 /* PieChartViewController4.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -293,6 +341,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = PlotCreator_Prefix.pch; INFOPLIST_FILE = "PlotCreator-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; PRODUCT_NAME = PlotCreator; RUN_CLANG_STATIC_ANALYZER = YES; }; @@ -307,6 +356,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = PlotCreator_Prefix.pch; INFOPLIST_FILE = "PlotCreator-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; PRODUCT_NAME = PlotCreator; RUN_CLANG_STATIC_ANALYZER = YES; VALIDATE_PRODUCT = YES; diff --git a/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/gustavohalperin.xcuserdatad/UserInterfaceState.xcuserstate b/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/gustavohalperin.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..98d8bbf Binary files /dev/null and b/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/gustavohalperin.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/UserInterfaceState.xcuserstate b/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index 854ce49..0000000 Binary files a/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/WorkspaceSettings.xcsettings b/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/WorkspaceSettings.xcsettings deleted file mode 100644 index 659c876..0000000 --- a/iOSPlot/PlotCreator.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/WorkspaceSettings.xcsettings +++ /dev/null @@ -1,10 +0,0 @@ - - - - - HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges - - SnapshotAutomaticallyBeforeSignificantChanges - - - diff --git a/iOSPlot/PlotCreator.xcodeproj/xcuserdata/gustavohalperin.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/iOSPlot/PlotCreator.xcodeproj/xcuserdata/gustavohalperin.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist new file mode 100644 index 0000000..05301bc --- /dev/null +++ b/iOSPlot/PlotCreator.xcodeproj/xcuserdata/gustavohalperin.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/iOSPlot/PlotCreator.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/PlotCreator.xcscheme b/iOSPlot/PlotCreator.xcodeproj/xcuserdata/gustavohalperin.xcuserdatad/xcschemes/PlotCreator.xcscheme similarity index 84% rename from iOSPlot/PlotCreator.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/PlotCreator.xcscheme rename to iOSPlot/PlotCreator.xcodeproj/xcuserdata/gustavohalperin.xcuserdatad/xcschemes/PlotCreator.xcscheme index 81b5b9d..470d42e 100644 --- a/iOSPlot/PlotCreator.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/PlotCreator.xcscheme +++ b/iOSPlot/PlotCreator.xcodeproj/xcuserdata/gustavohalperin.xcuserdatad/xcschemes/PlotCreator.xcscheme @@ -1,7 +1,7 @@ + LastUpgradeVersion = "0450" + version = "1.3"> @@ -23,23 +23,31 @@ + + + + title CCC value - 10 + 30 title DDD value - 30 + 10 title diff --git a/iOSPlot/Shared/PCPieChart.h b/iOSPlot/Shared/PCPieChart.h index 6431233..4f549aa 100644 --- a/iOSPlot/Shared/PCPieChart.h +++ b/iOSPlot/Shared/PCPieChart.h @@ -34,10 +34,16 @@ #import #import "PCPieChart.h" +@class PCPieComponent; + +@protocol PCPieComponentDelegate; + @interface PCPieComponent : NSObject -@property (nonatomic, assign) float value, startDeg, endDeg; +@property (nonatomic, assign) float value; @property (nonatomic, strong) UIColor *colour; @property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSString *contentPopover; +@property (nonatomic, weak) id delegate; - (id)initWithTitle:(NSString*)title value:(float)value; + (id)pieComponentWithTitle:(NSString*)title value:(float)value; @end @@ -48,11 +54,19 @@ #define PCColorRed [UIColor colorWithRed:1.0 green:51/255.0 blue:51/255.0 alpha:1.0] #define PCColorYellow [UIColor colorWithRed:1.0 green:220/255.0 blue:0.0 alpha:1.0] #define PCColorDefault [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0] +#define PCColorInnerCircle [UIColor colorWithRed:0.85 green:0.80 blue:0.85 alpha:1.0] +#define PCColorTextInnerCircle [UIColor colorWithRed:0.05 green:0.15 blue:0.05 alpha:1.0] @interface PCPieChart : UIView @property (nonatomic, assign) int diameter; @property (nonatomic, strong) NSMutableArray *components; @property (nonatomic, strong) UIFont *titleFont, *percentageFont; -@property (nonatomic, assign) BOOL showArrow, sameColorLabel; +@property (nonatomic, strong) NSString *titleInnerCircle; +@property (nonatomic, assign) BOOL showArrow, sameColorLabel, showInnerCircle, showValuesInChart, touchAnimated; @property (nonatomic, assign, getter = hasOutline) BOOL outline; @end + +@protocol PCPieComponentDelegate +@required +-(UIViewController*)ViewController: (PCPieComponent*)pieComponent; +@end \ No newline at end of file diff --git a/iOSPlot/Shared/PCPieChart.m b/iOSPlot/Shared/PCPieChart.m index 2a907db..9cf75e0 100644 --- a/iOSPlot/Shared/PCPieChart.m +++ b/iOSPlot/Shared/PCPieChart.m @@ -1,37 +1,46 @@ /** * Copyright (c) 2011 Muh Hon Cheng * Created by honcheng on 28/4/11. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject * to the following conditions: - * - * The above copyright notice and this permission notice shall be + * + * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT - * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT - * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR - * IN CONNECTION WITH THE SOFTWARE OR + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT + * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT + * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * + * * @author Muh Hon Cheng * @copyright 2011 Muh Hon Cheng * @version - * + * */ #import "PCPieChart.h" +#import "FPPopoverController.h" + +#import "PieChartPopover.h" + +@interface PCPieComponent() + +@property float startDeg, endDeg; + +@end @implementation PCPieComponent @@ -62,6 +71,24 @@ - (NSString*)description @end +@interface PCPieChart() + +@property (strong, nonatomic) UITapGestureRecognizer *tapGesture; + +@property (nonatomic, assign) float deltaRotation; +@property (nonatomic, assign) int diameterInnerCircle; +@property (nonatomic, strong) UIFont *titleFontInnerCircle; + +- (void)drawCicleBackground: (CGPoint)center; +- (void)drawInnerCircle: (CGPoint)center; +- (void)drawChartPortions: (CGPoint)center; +- (void)drawPercentValuesOnChart: (CGPoint)center; + +-(void)TapByUser:(id)sender; +-(void)addDeltaAngleTillCenter: (id)obj; + +@end + @implementation PCPieChart - (id)initWithFrame:(CGRect)frame @@ -75,33 +102,201 @@ - (id)initWithFrame:(CGRect)frame _percentageFont = [UIFont boldSystemFontOfSize:20]; _showArrow = YES; _sameColorLabel = NO; + + _tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapByUser:)]; + _tapGesture.delegate=self; + _tapGesture.numberOfTapsRequired=1; + [self addGestureRecognizer:_tapGesture]; + + self.deltaRotation = 0; + } return self; } -#define LABEL_TOP_MARGIN 15 +- (void)setDeltaRotation:(float)deltaRotation +{ + _deltaRotation = deltaRotation; + if (_deltaRotation >= 360.f) { + _deltaRotation = remainderf(_deltaRotation, 360.f); + } +} + +- (void)setComponents:(NSMutableArray *)components +{ + if (_components) { + _components = nil; + } + _components = components; + float total = 0; + for (PCPieComponent *component in self.components) + total += component.value; + + float nextStartDeg = _deltaRotation; + float endDeg = 0; + for (PCPieComponent *component in _components) { + float perc = [component value]/total; + endDeg = nextStartDeg+perc*360; + + [component setStartDeg:nextStartDeg]; + [component setEndDeg:endDeg]; + nextStartDeg = endDeg; + } +} + +- (void)setShowArrow:(BOOL)showArrow +{ + _showArrow = showArrow; + if (_showArrow) { + _showValuesInChart = NO; + } +} + +- (void)setShowValuesInChart:(BOOL)showValuesInChart +{ + _showValuesInChart = showValuesInChart; + if (_showValuesInChart) { + _showArrow = NO; + } +} + +#define MARGIN 15 #define ARROW_HEAD_LENGTH 6 #define ARROW_HEAD_WIDTH 4 +#pragma mark draw methods +- (void)drawCicleBackground: (CGPoint)center +{ + CGContextRef ctx = UIGraphicsGetCurrentContext(); + UIGraphicsPushContext(ctx); + CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); // white color + CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 15); + // a white filled circle with a diameter of 100 pixels, centered in (60, 60) + CGContextFillEllipseInRect(ctx, CGRectMake(center.x, center.y, self.diameter, self.diameter)); + UIGraphicsPopContext(); + CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 0); +} + +- (void)drawInnerCircle: (CGPoint)center +{ + float x_innerCircle = center.x - _diameterInnerCircle * 0.5f; + float y_innerCircle = center.y - _diameterInnerCircle * 0.5f; + CGContextRef ctx = UIGraphicsGetCurrentContext(); + UIGraphicsPushContext(ctx); + CGContextSetFillColorWithColor(ctx, [PCColorInnerCircle CGColor]); + CGContextSetShadow(ctx, CGSizeMake(0.3f, 0.2f), MARGIN); + CGContextFillEllipseInRect(ctx, + CGRectMake(x_innerCircle, + y_innerCircle, + _diameterInnerCircle, + _diameterInnerCircle)); + UIGraphicsPopContext(); + + if (_titleInnerCircle) { + float width = cosf(25) * _diameterInnerCircle; + if (width < 8) + width = 8; + float height = fabsf(sinf(25) * _diameterInnerCircle); + int fontSize = height; + _titleFontInnerCircle = [UIFont boldSystemFontOfSize:fontSize]; + + CGFloat text_x = x_innerCircle + (_diameterInnerCircle - width) * 0.5f; + CGFloat text_y = y_innerCircle + (_diameterInnerCircle - height) * 0.5f; + + + CGRect titleFrame = CGRectMake(text_x, text_y, width, height); + + UIGraphicsPushContext(ctx); + CGContextSetFillColorWithColor(ctx, [PCColorTextInnerCircle CGColor]); + [_titleInnerCircle drawInRect:titleFrame + withFont:_titleFontInnerCircle + lineBreakMode:UILineBreakModeWordWrap + alignment:UITextAlignmentCenter]; + UIGraphicsPopContext(); + } +} + +- (void)drawChartPortions: (CGPoint)center +{ + float radius = self.diameter * 0.5f; + float gap = 1; + CGContextRef ctx = UIGraphicsGetCurrentContext(); + for (PCPieComponent *component in _components) + { + //float perc = component.value / total; + //endDeg = nextStartDeg+perc*360; + + CGContextSetFillColorWithColor(ctx, [component.colour CGColor]); + CGContextMoveToPoint(ctx, center.x, center.y); + //CGContextAddArc(ctx, origin_x, origin_y, radius, (nextStartDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0); + CGContextAddArc(ctx, center.x, center.y, radius, + (component.startDeg-90+_deltaRotation)*M_PI/180.0, (component.endDeg-90+_deltaRotation)*M_PI/180.0, 0); + CGContextClosePath(ctx); + CGContextFillPath(ctx); + + CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1); + CGContextSetLineWidth(ctx, gap); + CGContextMoveToPoint(ctx, center.x, center.y); + //CGContextAddArc(ctx, origin_x, origin_y, radius, (nextStartDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0); + CGContextAddArc(ctx, center.x, center.y, radius, + (component.startDeg-90+_deltaRotation)*M_PI/180.0, (component.endDeg-90+_deltaRotation)*M_PI/180.0, 0); + CGContextClosePath(ctx); + CGContextStrokePath(ctx); + + //nextStartDeg = endDeg; + } +} + +- (void)drawPercentValuesOnChart: (CGPoint)center +{ + float nextStartDeg; + float endDeg = 0; + float total = 0; + for (PCPieComponent *component in self.components) + total += component.value; + + CGContextRef ctx = UIGraphicsGetCurrentContext(); + for (PCPieComponent *component in _components) + { + nextStartDeg = component.startDeg + _deltaRotation; + endDeg = component.endDeg + _deltaRotation; + + float angle_rad = (-nextStartDeg - endDeg + 180)*0.5f / 180.f * M_PI; + float origin_x_label = cosf(angle_rad) * _diameter * 0.5f * 0.75f; + float origin_y_label = - sinf(angle_rad) * _diameter * 0.5f * 0.75f; + + CGContextSetShadow(ctx, CGSizeMake(1.f, 1.0f), .6f); + CGContextSetRGBFillColor(ctx, 0.4f, 0.4f, 0.4f, 1.0f); + + //float text_x = x + 10; + NSString *percentageText = [NSString stringWithFormat:@"%.1f%%", component.value/total*100]; + CGSize optimumSize = [percentageText sizeWithFont:self.titleFont]; + CGRect percFrame = CGRectMake(center.x+origin_x_label - optimumSize.width * 0.5f, + center.y+origin_y_label - optimumSize.height * 0.5f, + optimumSize.width, + optimumSize.height); + [percentageText drawInRect:percFrame withFont:self.titleFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight]; + } +} + - (void)drawRect:(CGRect)rect { - float margin = 15; if (self.diameter==0) { - self.diameter = MIN(rect.size.width, rect.size.height) - 2*margin; + self.diameter = MIN(rect.size.width, rect.size.height) - 2 * MARGIN; } - float x = (rect.size.width - self.diameter)/2; - float y = (rect.size.height - self.diameter)/2; - float gap = 1; - float inner_radius = self.diameter/2; - float origin_x = x + self.diameter/2; - float origin_y = y + self.diameter/2; - - // label stuff - float left_label_y = LABEL_TOP_MARGIN; - float right_label_y = LABEL_TOP_MARGIN; + float x = (rect.size.width - self.diameter) * 0.5f; + float y = (rect.size.height - self.diameter) * 0.5f; + float radius = self.diameter * 0.5f; + float origin_x = x + self.diameter * 0.5f; + float origin_y = y + self.diameter * 0.5f; + _diameterInnerCircle = self.diameter / 3.f; + // label stuff + float left_label_y = MARGIN; + float right_label_y = MARGIN; + if ([self.components count]>0) { @@ -112,350 +307,391 @@ - (void)drawRect:(CGRect)rect } CGContextRef ctx = UIGraphicsGetCurrentContext(); - UIGraphicsPushContext(ctx); - CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); // white color - CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), margin); - CGContextFillEllipseInRect(ctx, CGRectMake(x, y, self.diameter, self.diameter)); // a white filled circle with a diameter of 100 pixels, centered in (60, 60) - UIGraphicsPopContext(); - CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 0); - - float nextStartDeg = 0; + + [self drawCicleBackground: CGPointMake(x, y)]; + + float nextStartDeg; float endDeg = 0; - NSMutableArray *tmpComponents = [NSMutableArray array]; - int last_insert = -1; - for (int i=0; i<[self.components count]; i++) - { - PCPieComponent *component = [self.components objectAtIndex:i]; - float perc = [component value]/total; - endDeg = nextStartDeg+perc*360; - - CGContextSetFillColorWithColor(ctx, [component.colour CGColor]); - CGContextMoveToPoint(ctx, origin_x, origin_y); - CGContextAddArc(ctx, origin_x, origin_y, inner_radius, (nextStartDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - - CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1); - CGContextSetLineWidth(ctx, gap); - CGContextMoveToPoint(ctx, origin_x, origin_y); - CGContextAddArc(ctx, origin_x, origin_y, inner_radius, (nextStartDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0); - CGContextClosePath(ctx); - CGContextStrokePath(ctx); - - [component setStartDeg:nextStartDeg]; - [component setEndDeg:endDeg]; - if (nextStartDeg<180) - { - [tmpComponents addObject:component]; - } - else - { - if (last_insert==-1) - { - last_insert = i; - [tmpComponents addObject:component]; - } - else - { - [tmpComponents insertObject:component atIndex:last_insert]; - } - } - - nextStartDeg = endDeg; - } - - nextStartDeg = 0; - endDeg = 0; - float max_text_width = x - 10; - for (int i=0; i<[tmpComponents count]; i++) - { - PCPieComponent *component = [tmpComponents objectAtIndex:i]; - nextStartDeg = component.startDeg; - endDeg = component.endDeg; - - if (nextStartDeg > 180 || (nextStartDeg < 180 && endDeg> 270) ) - { - // left - - // display percentage label - if (self.sameColorLabel) - { - CGContextSetFillColorWithColor(ctx, [component.colour CGColor]); - } - else - { - CGContextSetRGBFillColor(ctx, 0.1f, 0.1f, 0.1f, 1.0f); - } - //CGContextSetRGBStrokeColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); - //CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); - CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 3); - - //float text_x = x + 10; - NSString *percentageText = [NSString stringWithFormat:@"%.1f%%", component.value/total*100]; - CGSize optimumSize = [percentageText sizeWithFont:self.percentageFont constrainedToSize:CGSizeMake(max_text_width,100)]; - CGRect percFrame = CGRectMake(5, left_label_y, max_text_width, optimumSize.height); - if (self.hasOutline) { - CGContextSaveGState(ctx); - - CGContextSetLineWidth(ctx, 1.0f); - CGContextSetLineJoin(ctx, kCGLineJoinRound); - CGContextSetTextDrawingMode (ctx, kCGTextFillStroke); - CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 0.8f); - - [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight]; - - CGContextRestoreGState(ctx); - } else { - [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight]; - } - - if (self.showArrow) - { - // draw line to point to chart - CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 1); - CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - //CGContextSetRGBStrokeColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); - //CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); - //CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 5); - - - int x1 = inner_radius/4*3*cos((nextStartDeg+component.value/total*360/2-90)*M_PI/180.0)+origin_x; - int y1 = inner_radius/4*3*sin((nextStartDeg+component.value/total*360/2-90)*M_PI/180.0)+origin_y; - CGContextSetLineWidth(ctx, 1); - if (left_label_y + optimumSize.height/2 < y)//(left_label_y==LABEL_TOP_MARGIN) - { - - CGContextMoveToPoint(ctx, 5 + max_text_width, left_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, left_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, y1); - CGContextStrokePath(ctx); - - //CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextMoveToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); - CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_LENGTH); - CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - - } - else - { - - CGContextMoveToPoint(ctx, 5 + max_text_width, left_label_y + optimumSize.height/2); - if (left_label_y + optimumSize.height/2 > y + self.diameter) - { - CGContextAddLineToPoint(ctx, x1, left_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, y1); - CGContextStrokePath(ctx); - - //CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextMoveToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); - CGContextAddLineToPoint(ctx, x1, y1-ARROW_HEAD_LENGTH); - CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - } - else - { - float y_diff = y1 - (left_label_y + optimumSize.height/2); - if ( (y_diff < 2*ARROW_HEAD_LENGTH && y_diff>0) || (-1*y_diff < 2*ARROW_HEAD_LENGTH && y_diff<0)) - { - - // straight arrow - y1 = left_label_y + optimumSize.height/2; - - CGContextAddLineToPoint(ctx, x1, y1); - CGContextStrokePath(ctx); - - //CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextMoveToPoint(ctx, x1, y1-ARROW_HEAD_WIDTH/2); - CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_LENGTH, y1); - CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_WIDTH/2); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - } - else if (left_label_y + optimumSize.height/2 component2.startDeg) + return (NSComparisonResult)NSOrderedAscending; + else + return (NSComparisonResult)NSOrderedDescending; + }]; + + for (PCPieComponent *component in sortedArray) + { + nextStartDeg = component.startDeg + _deltaRotation; + endDeg = component.endDeg + _deltaRotation; + + + if (nextStartDeg > 180 || (nextStartDeg < 180 && endDeg> 270) ) + { + // left + + // display percentage label + if (self.sameColorLabel) + { + CGContextSetFillColorWithColor(ctx, [component.colour CGColor]); + } + else + { + CGContextSetRGBFillColor(ctx, 0.1f, 0.1f, 0.1f, 1.0f); + } + CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 3); + + //float text_x = x + 10; + NSString *percentageText = [NSString stringWithFormat:@"%.1f%%", component.value/total*100]; + CGSize optimumSize = [percentageText sizeWithFont:self.percentageFont constrainedToSize:CGSizeMake(max_text_width,100)]; + CGRect percFrame = CGRectMake(5, left_label_y, max_text_width, optimumSize.height); + + if (self.hasOutline) { + CGContextSaveGState(ctx); + + CGContextSetLineWidth(ctx, 1.0f); + CGContextSetLineJoin(ctx, kCGLineJoinRound); + CGContextSetTextDrawingMode (ctx, kCGTextFillStroke); + CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 0.8f); + + [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight]; + + CGContextRestoreGState(ctx); + } else { + [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight]; + } + + if (self.showArrow) + { + // draw line to point to chart + CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 1); + CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); + + int x1 = radius/4*3*cos((nextStartDeg+component.value/total*360/2-90)*M_PI/180.0)+origin_x; + int y1 = radius/4*3*sin((nextStartDeg+component.value/total*360/2-90)*M_PI/180.0)+origin_y; + CGContextSetLineWidth(ctx, 1); + if (left_label_y + optimumSize.height/2 < y)//(left_label_y==LABEL_TOP_MARGIN) + { + + CGContextMoveToPoint(ctx, 5 + max_text_width, left_label_y + optimumSize.height/2); + CGContextAddLineToPoint(ctx, x1, left_label_y + optimumSize.height/2); + CGContextAddLineToPoint(ctx, x1, y1); + CGContextStrokePath(ctx); + + CGContextMoveToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); + CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_LENGTH); + CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); + CGContextClosePath(ctx); + CGContextFillPath(ctx); + + } + else + { + + CGContextMoveToPoint(ctx, 5 + max_text_width, left_label_y + optimumSize.height/2); + if (left_label_y + optimumSize.height/2 > y + self.diameter) + { + CGContextAddLineToPoint(ctx, x1, left_label_y + optimumSize.height/2); + CGContextAddLineToPoint(ctx, x1, y1); + CGContextStrokePath(ctx); + + CGContextMoveToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); + CGContextAddLineToPoint(ctx, x1, y1-ARROW_HEAD_LENGTH); + CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); + CGContextClosePath(ctx); + CGContextFillPath(ctx); + } + else + { + float y_diff = y1 - (left_label_y + optimumSize.height/2); + if ( (y_diff < 2*ARROW_HEAD_LENGTH && y_diff>0) || (-1*y_diff < 2*ARROW_HEAD_LENGTH && y_diff<0)) + { + + // straight arrow + y1 = left_label_y + optimumSize.height/2; + + CGContextAddLineToPoint(ctx, x1, y1); + CGContextStrokePath(ctx); + + CGContextMoveToPoint(ctx, x1, y1-ARROW_HEAD_WIDTH/2); + CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_LENGTH, y1); + CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_WIDTH/2); + CGContextClosePath(ctx); + CGContextFillPath(ctx); + } + else if (left_label_y + optimumSize.height/20) || (-1*y_diff < 2*ARROW_HEAD_LENGTH && y_diff<0)) + { + // straight arrow + y1 = right_label_y + optimumSize.height/2; + + CGContextMoveToPoint(ctx, text_x, right_label_y + optimumSize.height/2); + CGContextAddLineToPoint(ctx, x1, y1); + CGContextStrokePath(ctx); + + CGContextMoveToPoint(ctx, x1, y1-ARROW_HEAD_WIDTH/2); + CGContextAddLineToPoint(ctx, x1-ARROW_HEAD_LENGTH, y1); + CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_WIDTH/2); + CGContextClosePath(ctx); + CGContextFillPath(ctx); + } + else if (right_label_y + optimumSize.height/2180) + { + // arrow point up + y1 += ARROW_HEAD_LENGTH; + + CGContextMoveToPoint(ctx, text_x, right_label_y + optimumSize.height/2); + CGContextAddLineToPoint(ctx, x1, right_label_y + optimumSize.height/2); + CGContextAddLineToPoint(ctx, x1, y1); + CGContextStrokePath(ctx); + + CGContextMoveToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); + CGContextAddLineToPoint(ctx, x1, y1-ARROW_HEAD_LENGTH); + CGContextAddLineToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); + CGContextClosePath(ctx); + CGContextFillPath(ctx); + } + } + } + + // display title on the left + CGContextSetRGBFillColor(ctx, 0.4f, 0.4f, 0.4f, 1.0f); + right_label_y += optimumSize.height - 4; + optimumSize = [component.title sizeWithFont:self.titleFont constrainedToSize:CGSizeMake(max_text_width,100)]; + CGRect titleFrame = CGRectMake(text_x, right_label_y, optimumSize.width, optimumSize.height); + if (_showValuesInChart == NO) { + [component.title drawInRect:titleFrame withFont:self.titleFont]; + } + right_label_y += optimumSize.height + 10; + } + } + } + if (_showInnerCircle) + [self drawInnerCircle: CGPointMake(origin_x, origin_y)]; + } +} + +#pragma mark actions +-(void)TapByUser:(id)sender +{ + CGRect rect = self.frame; + float origin_x = rect.size.width*0.5f; + float origin_y = rect.size.height*0.5f; + + //Find by what angle it has to rotate + CGPoint touchPointOnSelf=[(UITapGestureRecognizer *)sender locationInView:self]; + if (_showInnerCircle && + powf(touchPointOnSelf.x-origin_x, 2.f) + powf(touchPointOnSelf.y-origin_y,2.f) <= powf(_diameterInnerCircle*0.5f,2.f)) { + NSLog(@"Touch inside Inner Circle"); + return; + } + if (powf(touchPointOnSelf.x-origin_x, 2.f) + powf(touchPointOnSelf.y-origin_y,2.f) > powf(_diameter*0.5f,2.f)){ + NSLog(@"Touch outside"); + return; + } + NSLog(@"Touch inside"); + + float angle=atan2f((touchPointOnSelf.y - origin_y), (touchPointOnSelf.x - origin_x)) * 180.f / M_PI; + if(angle<0) angle += 360; + angle += 90; // Chart alligment. + angle -= _deltaRotation; + if (angle >= 360.f) angle = remainderf(angle, 360.f); + for (PCPieComponent *component in self.components) { + if (angle > component.startDeg && angle < component.endDeg) { + if (_touchAnimated) { + [NSThread detachNewThreadSelector:@selector(addDeltaAngleTillCenter:) + toTarget:self + withObject:component]; + } + else { + if (component.delegate) { + UIViewController *viewController = [component.delegate ViewController:component]; + FPPopoverController *popoverController = [[FPPopoverController alloc] initWithViewController:viewController]; + CGPoint point = CGPointMake(self.frame.origin.x + touchPointOnSelf.x, self.frame.origin.y + touchPointOnSelf.y); + CGRect frame = CGRectMake(point.x-self.frame.origin.x, point.y-self.frame.origin.y, 1, 1); + UIView *view = [[UIView alloc] initWithFrame:frame]; + [self addSubview:view]; + [popoverController presentPopoverFromView:view]; + [view removeFromSuperview]; + } + } + break; } - - if (self.showArrow) - { - // draw line to point to chart - CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 1); - CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - //CGContextSetRGBStrokeColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); - //CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); - //CGContextSetShadow(ctx, CGSizeMake(0.0f, 0.0f), 5); - - CGContextSetLineWidth(ctx, 1); - int x1 = inner_radius/4*3*cos((nextStartDeg+component.value/total*360/2-90)*M_PI/180.0)+origin_x; - int y1 = inner_radius/4*3*sin((nextStartDeg+component.value/total*360/2-90)*M_PI/180.0)+origin_y; - - - if (right_label_y + optimumSize.height/2 < y)//(right_label_y==LABEL_TOP_MARGIN) - { - - CGContextMoveToPoint(ctx, text_x - 3, right_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, right_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, y1); - CGContextStrokePath(ctx); - - //CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextMoveToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); - CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_LENGTH); - CGContextAddLineToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - } - else - { - float y_diff = y1 - (right_label_y + optimumSize.height/2); - if ( (y_diff < 2*ARROW_HEAD_LENGTH && y_diff>0) || (-1*y_diff < 2*ARROW_HEAD_LENGTH && y_diff<0)) - { - // straight arrow - y1 = right_label_y + optimumSize.height/2; - - CGContextMoveToPoint(ctx, text_x, right_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, y1); - CGContextStrokePath(ctx); - - //CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextMoveToPoint(ctx, x1, y1-ARROW_HEAD_WIDTH/2); - CGContextAddLineToPoint(ctx, x1-ARROW_HEAD_LENGTH, y1); - CGContextAddLineToPoint(ctx, x1, y1+ARROW_HEAD_WIDTH/2); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - } - else if (right_label_y + optimumSize.height/2180) - { - // arrow point up - y1 += ARROW_HEAD_LENGTH; - - CGContextMoveToPoint(ctx, text_x, right_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, right_label_y + optimumSize.height/2); - CGContextAddLineToPoint(ctx, x1, y1); - CGContextStrokePath(ctx); - - //CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f); - CGContextMoveToPoint(ctx, x1+ARROW_HEAD_WIDTH/2, y1); - CGContextAddLineToPoint(ctx, x1, y1-ARROW_HEAD_LENGTH); - CGContextAddLineToPoint(ctx, x1-ARROW_HEAD_WIDTH/2, y1); - CGContextClosePath(ctx); - CGContextFillPath(ctx); - } - } - } - - // display title on the left - CGContextSetRGBFillColor(ctx, 0.4f, 0.4f, 0.4f, 1.0f); - right_label_y += optimumSize.height - 4; - optimumSize = [component.title sizeWithFont:self.titleFont constrainedToSize:CGSizeMake(max_text_width,100)]; - CGRect titleFrame = CGRectMake(text_x, right_label_y, optimumSize.width, optimumSize.height); - [component.title drawInRect:titleFrame withFont:self.titleFont]; - right_label_y += optimumSize.height + 10; - } - nextStartDeg = endDeg; - } } + +} + +-(void)popovermethod: (PCPieComponent*)component +{ + + UIViewController *viewController = [component.delegate ViewController:component]; + FPPopoverController *popoverController = [[FPPopoverController alloc] initWithViewController:viewController]; + CGPoint point = CGPointMake(self.frame.size.width * 0.5f + self.diameter * 0.5f, + self.frame.size.height * 0.5f); + CGRect frame = CGRectMake(point.x, point.y, 1, 1); + UIView *view = [[UIView alloc] initWithFrame:frame]; + [self addSubview:view]; + [popoverController presentPopoverFromView:view]; + [view removeFromSuperview]; +} + +-(void)addDeltaAngleTillCenter: (id)obj +{ + [NSThread sleepForTimeInterval:0.015f]; + PCPieComponent *component = obj; + float targetAngle = 360 - (component.startDeg + component.endDeg) * 0.5f + 90; + if(targetAngle < 0) targetAngle += 360; + if (targetAngle >= 360.f) targetAngle = remainderf(targetAngle, 360.f); + if (ceilf(_deltaRotation) == ceilf(targetAngle)) { + if (component.delegate) + [self performSelectorOnMainThread:@selector(popovermethod:) + withObject:component waitUntilDone:NO]; + return; + } + self.deltaRotation = _deltaRotation + 1; + [self setNeedsDisplay]; + + [NSThread detachNewThreadSelector:@selector(addDeltaAngleTillCenter:) + toTarget:self + withObject:component]; } @end diff --git a/iOSPlot/iPhone/ChartListViewController.m b/iOSPlot/iPhone/ChartListViewController.m index 28f41aa..7dae651 100644 --- a/iOSPlot/iPhone/ChartListViewController.m +++ b/iOSPlot/iPhone/ChartListViewController.m @@ -34,6 +34,8 @@ #import "ChartListViewController.h" #import "PieChartViewController.h" #import "PieChartViewController2.h" +#import "PieChartViewController3.h" +#import "PieChartViewController4.h" #import "LineChartViewController.h" #import "HalfPieChartViewController.h" @@ -70,7 +72,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. - return 4; + return 6; } @@ -88,22 +90,30 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } - if (indexPath.row==0) - { - [cell.textLabel setText:@"Pie Chart with arrows"]; - } - else if (indexPath.row==1) - { - [cell.textLabel setText:@"Pie Chart without arrows"]; - } - else if (indexPath.row==2) - { - [cell.textLabel setText:@"Half Pie Chart (not completed yet)"]; - } - else if (indexPath.row==3) - { - [cell.textLabel setText:@"Line Chart"]; - } + + switch (indexPath.row) { + case 0: + [cell.textLabel setText:@"Pie Chart with arrows"]; + break; + case 1: + [cell.textLabel setText:@"Pie Chart without arrows"]; + break; + case 2: + [cell.textLabel setText:@"Pie Chart with inner circle"]; + break; + case 3: + [cell.textLabel setText:@"Pie Chart with inner circle animated"]; + break; + case 4: + [cell.textLabel setText:@"Half Pie Chart (not completed yet)"]; + break; + case 5: + [cell.textLabel setText:@"Line Chart"]; + break; + + default: + break; + } return cell; } @@ -113,26 +123,31 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.row==0) - { - PieChartViewController *detailViewController = [[PieChartViewController alloc] init]; - [self.navigationController pushViewController:detailViewController animated:YES]; - } - else if (indexPath.row==1) - { - PieChartViewController2 *detailViewController = [[PieChartViewController2 alloc] init]; - [self.navigationController pushViewController:detailViewController animated:YES]; - } - else if (indexPath.row==2) - { - HalfPieChartViewController *detailViewController = [[HalfPieChartViewController alloc] init]; - [self.navigationController pushViewController:detailViewController animated:YES]; - } - else if (indexPath.row==3) - { - LineChartViewController *detailViewController = [[LineChartViewController alloc] init]; - [self.navigationController pushViewController:detailViewController animated:YES]; - } + UIViewController *detailViewController; + switch (indexPath.row) { + case 0: + detailViewController= [[PieChartViewController alloc] init]; + break; + case 1: + detailViewController = [[PieChartViewController2 alloc] init]; + break; + case 2: + detailViewController = [[PieChartViewController3 alloc] init]; + break; + case 3: + detailViewController = [[PieChartViewController4 alloc] init]; + break; + case 4: + detailViewController = [[HalfPieChartViewController alloc] init]; + break; + case 5: + detailViewController = [[LineChartViewController alloc] init]; + break; + + default: + break; + } + [self.navigationController pushViewController:detailViewController animated:YES]; } diff --git a/iOSPlot/iPhone/PieChartViewController.m b/iOSPlot/iPhone/PieChartViewController.m index 7304efa..4593bb4 100644 --- a/iOSPlot/iPhone/PieChartViewController.m +++ b/iOSPlot/iPhone/PieChartViewController.m @@ -51,7 +51,7 @@ - (id)init [pieChart setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin]; [pieChart setDiameter:width/2]; [pieChart setSameColorLabel:YES]; - + [self.view addSubview:pieChart]; if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)