Skip to content

Commit

Permalink
- added a half pie chart, but without display value yet
Browse files Browse the repository at this point in the history
  • Loading branch information
honcheng committed May 4, 2011
1 parent 7f2df83 commit 68f922b
Show file tree
Hide file tree
Showing 8 changed files with 4,556 additions and 1,665 deletions.
4 changes: 4 additions & 0 deletions README
Expand Up @@ -8,3 +8,7 @@ iOSPlot
Allow legend labels to appear on either the right or left side of the chart (or not at all).
Use the rendered string width of the legend labels to determine right/left side margin.
If a legend string is significantly long (200% percentage of default margin width?), truncate or abbreviate it to X characters.

*todo list for half pie chart*
Use gesture/tap to show the value label
Display legend
16 changes: 16 additions & 0 deletions iOSPlot/HalfPieChartViewController.h
@@ -0,0 +1,16 @@
//
// HalfPieChartViewController.h
// PlotCreator
//
// Created by honcheng on 5/4/11.
// Copyright 2011 BuUuK Pte Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "GenericViewController.h"

@interface HalfPieChartViewController : GenericViewController {

}

@end
119 changes: 119 additions & 0 deletions iOSPlot/HalfPieChartViewController.m
@@ -0,0 +1,119 @@
//
// HalfPieChartViewController.m
// PlotCreator
//
// Created by honcheng on 5/4/11.
// Copyright 2011 BuUuK Pte Ltd. All rights reserved.
//

#import "HalfPieChartViewController.h"
#import "PCHalfPieChart.h"

@implementation HalfPieChartViewController

- (id)init
{
self = [super init];
if (self) {
// Custom initialization

[self.view setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]];
[self.titleLabel setText:@"Half Pie Chart"];


int height = [self.view bounds].size.height-20;
int width = [self.view bounds].size.width;
PCHalfPieChart *pieChart = [[PCHalfPieChart alloc] initWithFrame:CGRectMake(([self.view bounds].size.width-width)/2,([self.view bounds].size.height-height)/2,width,height)];
[pieChart setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin];
//[pieChart setDiameter:width/2];
[self.view addSubview:pieChart];
[pieChart release];

if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)
{
pieChart.titleFont = [UIFont fontWithName:@"HelveticaNeue" size:20];
pieChart.subtitleFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:50];
}

[pieChart setTitle:@"Total"];
//[pieChart setSubtitle:@"Chart subtitle"];

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];
PCHalfPieComponent *component = [PCHalfPieComponent halfPieComponentWithTitle:[item objectForKey:@"title"] value:[[item objectForKey:@"value"] floatValue]];
[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;
}

- (void)dealloc
{
[super dealloc];
}

- (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.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
68 changes: 68 additions & 0 deletions iOSPlot/PCHalfPieChart.h
@@ -0,0 +1,68 @@
/**
* 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
* to the following conditions:
*
* 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 USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @author Muh Hon Cheng <honcheng@gmail.com>
* @copyright 2011 Muh Hon Cheng
* @version
*
*/

#import <UIKit/UIKit.h>

@interface PCHalfPieComponent : NSObject
{
float value;
NSString *title;
UIColor *colour;
}

@property (nonatomic, assign) float value;
@property (nonatomic, retain) UIColor *colour;
@property (nonatomic, retain) NSString *title;

+ (id)halfPieComponentWithTitle:(NSString*)_title value:(float)_value;
- (id)initWithTitle:(NSString*)_title value:(float)_value;

#define PCColorBlue [UIColor colorWithRed:0.0 green:153/255.0 blue:204/255.0 alpha:1.0]
#define PCColorGreen [UIColor colorWithRed:153/255.0 green:204/255.0 blue:51/255.0 alpha:1.0]
#define PCColorOrange [UIColor colorWithRed:1.0 green:153/255.0 blue:51/255.0 alpha:1.0]
#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]


@end

@interface PCHalfPieChart : UIView {
NSMutableArray *components;
NSString *title, *subtitle;
UIFont *titleFont, *subtitleFont;
}
@property (nonatomic, retain) NSString *title, *subtitle;
@property (nonatomic, retain) NSMutableArray *components;
@property (nonatomic, retain) UIFont *titleFont, *subtitleFont;
@end

0 comments on commit 68f922b

Please sign in to comment.