Permalink
Browse files

Initial checkin of the PieChart files

  • Loading branch information...
1 parent 588e49d commit 8e0544af5952eaee4ca6562a54f4ff1ae415c645 @pavanpodila committed Feb 26, 2012
@@ -15,29 +15,38 @@
675C613914FAD02400B4C6E6 /* PSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 675C613814FAD02400B4C6E6 /* PSAppDelegate.m */; };
675C613C14FAD02400B4C6E6 /* PSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 675C613B14FAD02400B4C6E6 /* PSViewController.m */; };
675C613F14FAD02400B4C6E6 /* PSViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 675C613D14FAD02400B4C6E6 /* PSViewController.xib */; };
+ 675C615014FAD10A00B4C6E6 /* PieSliceLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 675C614D14FAD10A00B4C6E6 /* PieSliceLayer.m */; };
+ 675C615114FAD10A00B4C6E6 /* PieView.m in Sources */ = {isa = PBXBuildFile; fileRef = 675C614F14FAD10A00B4C6E6 /* PieView.m */; };
+ 675C615314FAD1ED00B4C6E6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 675C615214FAD1ED00B4C6E6 /* QuartzCore.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
675C612414FAD02400B4C6E6 /* PieChart.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PieChart.app; sourceTree = BUILT_PRODUCTS_DIR; };
675C612814FAD02400B4C6E6 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
675C612A14FAD02400B4C6E6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
675C612C14FAD02400B4C6E6 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
- 675C613014FAD02400B4C6E6 /* PieChart-Info.plist */ = {isa = PBXFileReference; path = "PieChart-Info.plist"; sourceTree = "<group>"; };
+ 675C613014FAD02400B4C6E6 /* PieChart-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PieChart-Info.plist"; sourceTree = "<group>"; };
675C613214FAD02400B4C6E6 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
675C613414FAD02400B4C6E6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
- 675C613614FAD02400B4C6E6 /* PieChart-Prefix.pch */ = {isa = PBXFileReference; path = "PieChart-Prefix.pch"; sourceTree = "<group>"; };
- 675C613714FAD02400B4C6E6 /* PSAppDelegate.h */ = {isa = PBXFileReference; path = PSAppDelegate.h; sourceTree = "<group>"; };
+ 675C613614FAD02400B4C6E6 /* PieChart-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PieChart-Prefix.pch"; sourceTree = "<group>"; };
+ 675C613714FAD02400B4C6E6 /* PSAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PSAppDelegate.h; sourceTree = "<group>"; };
675C613814FAD02400B4C6E6 /* PSAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PSAppDelegate.m; sourceTree = "<group>"; };
- 675C613A14FAD02400B4C6E6 /* PSViewController.h */ = {isa = PBXFileReference; path = PSViewController.h; sourceTree = "<group>"; };
+ 675C613A14FAD02400B4C6E6 /* PSViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PSViewController.h; sourceTree = "<group>"; };
675C613B14FAD02400B4C6E6 /* PSViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PSViewController.m; sourceTree = "<group>"; };
675C613E14FAD02400B4C6E6 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/PSViewController.xib; sourceTree = "<group>"; };
+ 675C614C14FAD10A00B4C6E6 /* PieSliceLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PieSliceLayer.h; sourceTree = "<group>"; };
+ 675C614D14FAD10A00B4C6E6 /* PieSliceLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PieSliceLayer.m; sourceTree = "<group>"; };
+ 675C614E14FAD10A00B4C6E6 /* PieView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PieView.h; sourceTree = "<group>"; };
+ 675C614F14FAD10A00B4C6E6 /* PieView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PieView.m; sourceTree = "<group>"; };
+ 675C615214FAD1ED00B4C6E6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
675C612114FAD02400B4C6E6 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 675C615314FAD1ED00B4C6E6 /* QuartzCore.framework in Frameworks */,
675C612914FAD02400B4C6E6 /* UIKit.framework in Frameworks */,
675C612B14FAD02400B4C6E6 /* Foundation.framework in Frameworks */,
675C612D14FAD02400B4C6E6 /* CoreGraphics.framework in Frameworks */,
@@ -67,6 +76,7 @@
675C612714FAD02400B4C6E6 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 675C615214FAD1ED00B4C6E6 /* QuartzCore.framework */,
675C612814FAD02400B4C6E6 /* UIKit.framework */,
675C612A14FAD02400B4C6E6 /* Foundation.framework */,
675C612C14FAD02400B4C6E6 /* CoreGraphics.framework */,
@@ -77,6 +87,10 @@
675C612E14FAD02400B4C6E6 /* PieChart */ = {
isa = PBXGroup;
children = (
+ 675C614C14FAD10A00B4C6E6 /* PieSliceLayer.h */,
+ 675C614D14FAD10A00B4C6E6 /* PieSliceLayer.m */,
+ 675C614E14FAD10A00B4C6E6 /* PieView.h */,
+ 675C614F14FAD10A00B4C6E6 /* PieView.m */,
675C613714FAD02400B4C6E6 /* PSAppDelegate.h */,
675C613814FAD02400B4C6E6 /* PSAppDelegate.m */,
675C613A14FAD02400B4C6E6 /* PSViewController.h */,
@@ -164,6 +178,8 @@
675C613514FAD02400B4C6E6 /* main.m in Sources */,
675C613914FAD02400B4C6E6 /* PSAppDelegate.m in Sources */,
675C613C14FAD02400B4C6E6 /* PSViewController.m in Sources */,
+ 675C615014FAD10A00B4C6E6 /* PieSliceLayer.m in Sources */,
+ 675C615114FAD10A00B4C6E6 /* PieView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "675C612314FAD02400B4C6E6"
+ BuildableName = "PieChart.app"
+ BlueprintName = "PieChart"
+ ReferencedContainer = "container:PieChart.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "675C612314FAD02400B4C6E6"
+ BuildableName = "PieChart.app"
+ BlueprintName = "PieChart"
+ ReferencedContainer = "container:PieChart.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "675C612314FAD02400B4C6E6"
+ BuildableName = "PieChart.app"
+ BlueprintName = "PieChart"
+ ReferencedContainer = "container:PieChart.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "675C612314FAD02400B4C6E6"
+ BuildableName = "PieChart.app"
+ BlueprintName = "PieChart"
+ ReferencedContainer = "container:PieChart.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>SchemeUserState</key>
+ <dict>
+ <key>PieChart.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ <key>SuppressBuildableAutocreation</key>
+ <dict>
+ <key>675C612314FAD02400B4C6E6</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>
@@ -7,7 +7,9 @@
//
#import <UIKit/UIKit.h>
+#import "PieView.h"
@interface PSViewController : UIViewController
+@property (weak, nonatomic) IBOutlet PieView *pieView;
@end
@@ -9,12 +9,22 @@
#import "PSViewController.h"
@implementation PSViewController
+@synthesize pieView;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
+- (IBAction)animatePieSlices:(id)sender {
+ NSMutableArray *randomNumbers = [NSMutableArray array];
+ int count = 1 + rand() % 10;
+ for (int i = 0; i < count; i++) {
+ [randomNumbers addObject:[NSNumber numberWithInt:rand() % 100]];
+ }
+
+ pieView.sliceValues = randomNumbers;
+}
#pragma mark - View lifecycle
@@ -26,6 +36,7 @@ - (void)viewDidLoad
- (void)viewDidUnload
{
+ [self setPieView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
View
@@ -0,0 +1,20 @@
+//
+// PieSliceLayer.h
+// PieChart
+//
+// Created by Pavan Podila on 2/20/12.
+// Copyright (c) 2012 Pixel-in-Gene. All rights reserved.
+//
+
+#import <QuartzCore/QuartzCore.h>
+
+@interface PieSliceLayer : CALayer
+
+
+@property (nonatomic) CGFloat startAngle;
+@property (nonatomic) CGFloat endAngle;
+
+@property (nonatomic, strong) UIColor *fillColor;
+@property (nonatomic) CGFloat strokeWidth;
+@property (nonatomic, strong) UIColor *strokeColor;
+@end
View
@@ -0,0 +1,98 @@
+//
+// PieSliceLayer.m
+// PieChart
+//
+// Created by Pavan Podila on 2/20/12.
+// Copyright (c) 2012 Pixel-in-Gene. All rights reserved.
+//
+
+#import "PieSliceLayer.h"
+
+@implementation PieSliceLayer
+
+@dynamic startAngle, endAngle;
+@synthesize fillColor, strokeColor, strokeWidth;
+
+-(CABasicAnimation *)makeAnimationForKey:(NSString *)key {
+ CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:key];
+ anim.fromValue = [[self presentationLayer] valueForKey:key];
+ anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
+ anim.duration = 0.5;
+
+ return anim;
+}
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ self.fillColor = [UIColor grayColor];
+ self.strokeColor = [UIColor blackColor];
+ self.strokeWidth = 1.0;
+
+ [self setNeedsDisplay];
+ }
+
+ return self;
+}
+
+-(id<CAAction>)actionForKey:(NSString *)event {
+ if ([event isEqualToString:@"startAngle"] ||
+ [event isEqualToString:@"endAngle"]) {
+ return [self makeAnimationForKey:event];
+ }
+
+ return [super actionForKey:event];
+}
+
+- (id)initWithLayer:(id)layer {
+ if (self = [super initWithLayer:layer]) {
+ if ([layer isKindOfClass:[PieSliceLayer class]]) {
+ PieSliceLayer *other = (PieSliceLayer *)layer;
+ self.startAngle = other.startAngle;
+ self.endAngle = other.endAngle;
+ self.fillColor = other.fillColor;
+
+ self.strokeColor = other.strokeColor;
+ self.strokeWidth = other.strokeWidth;
+ }
+ }
+
+ return self;
+}
+
++ (BOOL)needsDisplayForKey:(NSString *)key {
+ if ([key isEqualToString:@"startAngle"] || [key isEqualToString:@"endAngle"]) {
+ return YES;
+ }
+
+ return [super needsDisplayForKey:key];
+}
+
+
+-(void)drawInContext:(CGContextRef)ctx {
+
+ // Create the path
+ CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
+ CGFloat radius = MIN(center.x, center.y);
+
+ CGContextBeginPath(ctx);
+ CGContextMoveToPoint(ctx, center.x, center.y);
+
+ CGPoint p1 = CGPointMake(center.x + radius * cosf(self.startAngle), center.y + radius * sinf(self.startAngle));
+ CGContextAddLineToPoint(ctx, p1.x, p1.y);
+
+ int clockwise = self.startAngle > self.endAngle;
+ CGContextAddArc(ctx, center.x, center.y, radius, self.startAngle, self.endAngle, clockwise);
+
+// CGContextAddLineToPoint(ctx, center.x, center.y);
+
+ CGContextClosePath(ctx);
+
+ // Color it
+ CGContextSetFillColorWithColor(ctx, self.fillColor.CGColor);
+ CGContextSetStrokeColorWithColor(ctx, self.strokeColor.CGColor);
+ CGContextSetLineWidth(ctx, self.strokeWidth);
+
+ CGContextDrawPath(ctx, kCGPathFillStroke);
+}
+@end
View
@@ -0,0 +1,16 @@
+//
+// PieView.h
+// PieChart
+//
+// Created by Pavan Podila on 2/21/12.
+// Copyright (c) 2012 Pixel-in-Gene. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface PieView : UIView
+
+@property (nonatomic, strong) NSArray *sliceValues;
+
+-(id)initWithSliceValues:(NSArray *)sliceValues;
+@end
Oops, something went wrong.

0 comments on commit 8e0544a

Please sign in to comment.