Skip to content

Commit

Permalink
Added preliminary charting using Google Charts
Browse files Browse the repository at this point in the history
  • Loading branch information
nielubowicz committed Feb 19, 2011
1 parent 68f3beb commit e352bbc
Show file tree
Hide file tree
Showing 26 changed files with 1,663 additions and 472 deletions.
21 changes: 21 additions & 0 deletions Classes/charting/Chart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Chart.h
// iAbetes
//
// Created by chris nielubowicz on 2/19/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface Chart : UIViewController <UIWebViewDelegate>
{
IBOutlet UIWebView *chartView;
NSURL *chartURL;
NSArray *data;
}

@property (nonatomic, retain) IBOutlet UIWebView *chartView;
@property (nonatomic, retain) NSArray *data;

@end
40 changes: 40 additions & 0 deletions Classes/charting/Chart.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Chart.m
// iAbetes
//
// Created by chris nielubowicz on 2/19/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Chart.h"
#import "ChartFormatter.h"

@implementation Chart

@synthesize chartView, data;

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
}
return self;
}

-(void)viewDidLoad
{
ChartFormatter *format = [[[ChartFormatter alloc] init] autorelease];
chartURL = [NSURL URLWithString:[format urlForData:data]];
NSLog(@"chartURL:\n%@", [chartURL description]);
[chartView loadRequest:[NSURLRequest requestWithURL:chartURL]];
}

-(void)dealloc
{
[chartView setDelegate:nil];
[chartView release];
[super dealloc];
}


@end
192 changes: 192 additions & 0 deletions Classes/charting/Chart.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">784</int>
<string key="IBDocument.SystemVersion">9L30</string>
<string key="IBDocument.InterfaceBuilderVersion">680</string>
<string key="IBDocument.AppKitVersion">949.54</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="1"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBProxyObject" id="372490531">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
</object>
<object class="IBProxyObject" id="975951072">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
</object>
<object class="IBUIView" id="191373211">
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIWebView" id="733213800">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{20, 123}, {280, 259}}</string>
<reference key="NSSuperview" ref="191373211"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<int key="IBUIDataDetectorTypes">1</int>
<bool key="IBUIDetectsPhoneNumbers">YES</bool>
</object>
</object>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC42NzIyMjIyNiAxIDAuMzQ0NDQ0NDUAA</bytes>
</object>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">view</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="191373211"/>
</object>
<int key="connectionID">3</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">chartView</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="733213800"/>
</object>
<int key="connectionID">8</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="733213800"/>
<reference key="destination" ref="372490531"/>
</object>
<int key="connectionID">9</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
<object class="NSArray" key="object" id="1009648848">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">1</int>
<reference key="object" ref="191373211"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="733213800"/>
</object>
<reference key="parent" ref="1009648848"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="372490531"/>
<reference key="parent" ref="1009648848"/>
<string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="975951072"/>
<reference key="parent" ref="1009648848"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">7</int>
<reference key="object" ref="733213800"/>
<reference key="parent" ref="191373211"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
<string>1.IBEditorWindowLastContentRect</string>
<string>1.IBPluginDependency</string>
<string>7.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>Chart</string>
<string>UIResponder</string>
<string>{{481, 412}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<nil key="activeLocalization"/>
<object class="NSMutableDictionary" key="localizations">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">9</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">Chart</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">chartView</string>
<string key="NS.object.0">UIWebView</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">Classes/charting/Chart.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.LastKnownRelativeProjectPath">../../iAbetes.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">3.1</string>
</data>
</archive>
18 changes: 18 additions & 0 deletions Classes/charting/ChartFormatter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ChartFormatter.h
// iAbetes
//
// Created by chris nielubowicz on 2/19/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface ChartFormatter : NSObject {

}

-(NSString *)urlForData:(NSArray *)logEntries;

@end
41 changes: 41 additions & 0 deletions Classes/charting/ChartFormatter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// ChartFormatter.m
// iAbetes
//
// Created by chris nielubowicz on 2/19/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ChartFormatter.h"
#import "LogEntry.h"

@implementation ChartFormatter

-(id)init
{
if (self = [super init])
{

}
return self;
}

-(NSString *)urlForData:(NSArray *)logEntries
{
NSMutableString *dataString = [NSMutableString string];
NSSortDescriptor *sort = [[[NSSortDescriptor alloc] initWithKey:@"timeOfEntry" ascending:YES] autorelease];
NSArray *timeSortedArray = [logEntries sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
NSLog(@"sort : %@", [timeSortedArray description]);
for (LogEntry *log in timeSortedArray)
{
[dataString appendFormat:@"%d,", [log bloodSugar]];
}
return [NSString stringWithFormat:@"https://chart.googleapis.com/chart?cht=lc&chd=t:%@&chds=20,500&chs=280x250&chxt=y&chxr=0,20,500", [dataString substringToIndex:[dataString length]-1]];
}

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

@end
4 changes: 4 additions & 0 deletions Classes/iAbetesAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
[viewController saveDataToDisk];
}

- (void)dealloc {
[viewController release];
Expand Down
4 changes: 3 additions & 1 deletion Classes/iAbetesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
IBOutlet UITextField *exercizeDuration;
IBOutlet UISlider *exercizeIntensity;

NSMutableSet *logEntries;
NSMutableArray *logEntries;
}

@property (nonatomic, retain) IBOutlet UILabel *currentTime;
Expand All @@ -26,6 +26,8 @@
@property (nonatomic, retain) IBOutlet UISlider *exercizeIntensity;

-(IBAction)saveLogEntry;
-(IBAction)graph;
-(void)saveDataToDisk;

@end

Loading

0 comments on commit e352bbc

Please sign in to comment.