Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Classes/JCStockGraphController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#import "CorePlot-CocoaTouch.h"

typedef enum {
kGraphRange5Year = 0,
kGraphRange1Year,
kGraphRange3Month,
kGraphRange1Week = 0,
kGraphRange1Month,
kGraphRange1Week,
kGraphRange3Month,
kGraphRange1Year,
kGraphRange5Year,
kGraphRangeCount
} JCStockGraphRange;

Expand All @@ -38,12 +38,15 @@ typedef NSInteger JCStockGraphOptionMask;
@property (nonatomic) JCStockGraphRange range;
@property (nonatomic) CGPoint graphOffset;
@property (nonatomic) CGSize graphSize;
@property (nonatomic) id parentPage;

@property (strong, nonatomic) NSString *ticker;
@property (strong, nonatomic) JCStockGraphView *graphView;

- (id)initWithTicker:(NSString *)ticker;
- (id)initWithTicker:(NSString *)ticker parent:(id)qParent;
- (void)loadDataWithCompletion:(void (^)())completion;
- (void)reloadGraph;

- (void)releaseGraph;

@end
15 changes: 11 additions & 4 deletions Classes/JCStockGraphController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ @interface JCStockGraphController () {
NSArray *points;
BOOL loaded;
BOOL hasSetSize;
UITapGestureRecognizer *tapRecognizer;
// UITapGestureRecognizer *tapRecognizer;
}
@end


@implementation JCStockGraphController

- (id)initWithTicker:(NSString *)ticker
- (id)initWithTicker:(NSString *)ticker parent:(id)qParent
{
self = [super init];
if (self) {
Expand All @@ -37,6 +37,7 @@ - (id)initWithTicker:(NSString *)ticker
self.range = kGraphRange5Year;
self.graphOffset = CGPointZero;
self.graphSize = CGSizeZero;
self.parentPage = qParent;
}
return self;
}
Expand Down Expand Up @@ -71,7 +72,7 @@ - (void)loadDataWithCompletion:(void (^)())completion

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

[[JCStockPriceStore sharedInstance] getDataForTicker:self.ticker withProgress:^(double progress) {
[[JCStockPriceStore sharedInstance] getDataForTicker:self.ticker parentPage:self.parentPage withProgress:^(double progress) {
hud.progress = progress;

} completion:^(NSArray *newPoints) {
Expand Down Expand Up @@ -105,7 +106,7 @@ -(void)loadGraph
(self.graphOptions & kGraphOptionHideYAxis) ? [self.graphView hideYAxis] : [self.graphView configureYAxisWithPoints:points];
if (!(self.graphOptions & kGraphOptionHideGrid)) [self.graphView configureGridLines];
if (!(self.graphOptions & kGraphOptionHideRangeLabel)) [self.graphView addRangeLabel];
self.graphView.userInteractionEnabled = (self.graphOptions & kGraphOptionInteractive);
self.graphView.userInteractionEnabled = (BOOL) (self.graphOptions & kGraphOptionInteractive);

[self.view addSubview:self.graphView];
}
Expand All @@ -117,6 +118,12 @@ - (void)reloadGraph
[self.graphView reloadGraph];
}

- (void)releaseGraph
{
[self.graphView removePlots];
self.graphView = nil;
}

- (NSArray *)thinPoints:(NSArray *)fullPoints
{
//Make graph look smoother by thinning out the number of data points
Expand Down
15 changes: 14 additions & 1 deletion Classes/JCStockGraphPageController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ - (void)viewWillAppear:(BOOL)animated
[self reloadViews];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
if (graphControllers!=nil)
{
for (JCStockGraphController *gc in graphControllers)
{
[gc releaseGraph];
[gc removeFromParentViewController];
}
}
}

- (void)reloadViews
{
if (pagingScrollView) {
Expand Down Expand Up @@ -76,7 +89,7 @@ - (void)loadRemainingPages
return;
}

JCStockGraphController *graphController = [[JCStockGraphController alloc] initWithTicker:self.ticker];
JCStockGraphController *graphController = [[JCStockGraphController alloc] initWithTicker:self.ticker parent:self];
//graphController.view.frame = self.view.bounds;
graphController.graphOffset = self.graphOffset;
graphController.graphSize = self.graphSize;
Expand Down
5 changes: 4 additions & 1 deletion Classes/JCStockGraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//

#import <UIKit/UIKit.h>
#import "CorePlot/CorePlot-CocoaTouch.h"
//#import "CorePlot/CorePlot-CocoaTouch.h"
#import "CorePlot-CocoaTouch.h"
#import "JCStockGraphController.h"

@class JCStockPriceStore;
Expand All @@ -30,4 +31,6 @@
- (void)hideYAxis;
- (void)addRangeLabel;

-(void)removePlots;

@end
22 changes: 20 additions & 2 deletions Classes/JCStockGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ - (void)reloadGraph
[self.hostView.hostedGraph reloadData];
}

#pragma mark - some release handle
-(void)removePlots
{
for (CPTPlot* plot in [self.hostView.hostedGraph allPlots])
{
plot.dataSource = nil;
plot.delegate = nil;
[plot deleteDataInIndexRange:NSMakeRange(0, plot.cachedDataCount)];
[self.hostView.hostedGraph removePlot:plot];
}
[self.hostView removeFromSuperview];
self.hostView = nil;
}


#pragma mark - Chart behavior

-(void)configureHost
Expand Down Expand Up @@ -83,7 +98,9 @@ -(void)configurePlotWithDataSource:(id<CPTPlotDataSource>)dataSource
- (void)configureXAxisWithPoints:(NSArray *)points delegate:(id<CPTAxisDelegate>)delegate
{
// 0 - increase padding to make room for axis labels
self.hostView.hostedGraph.plotAreaFrame.paddingBottom = 24;
self.hostView.hostedGraph.plotAreaFrame.paddingBottom = 20;
self.hostView.hostedGraph.plotAreaFrame.paddingRight = 20;
self.hostView.hostedGraph.plotAreaFrame.paddingTop = 6;

// 1 - Get axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
Expand Down Expand Up @@ -115,6 +132,7 @@ - (void)configureYAxisWithPoints:(NSArray *)points
priceFormatter.numberStyle = kCFNumberFormatterCurrencyStyle;
priceFormatter.maximumSignificantDigits = 3;
priceFormatter.usesSignificantDigits = YES;
priceFormatter.currencySymbol = @"$";

CPTXYAxis *y = axisSet.yAxis;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];
Expand Down Expand Up @@ -194,7 +212,7 @@ - (void)addRangeLabel
rangeLabel.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.4];
[rangeLabel sizeToFit];
rangeLabel.width += 8;
rangeLabel.y = self.height - rangeLabel.height;
rangeLabel.y = self.height + 4; // - rangeLabel.height;
rangeLabel.right = self.right;
rangeLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self addSubview:rangeLabel];
Expand Down
2 changes: 1 addition & 1 deletion Classes/JCStockPriceStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
+ (JCStockPriceStore *)sharedInstance;

///@return YES if we loaded data from the cache/memory, NO if we made a request for the data
- (BOOL)getDataForTicker:(NSString *)ticker withProgress:(void (^)(double progress))progBlock completion:(void (^)(NSArray *points))block;
- (BOOL)getDataForTicker:(NSString *)ticker parentPage:(id)qParent withProgress:(void (^)(double progress))progBlock completion:(void (^)(NSArray *points))block;

@property (nonatomic) BOOL diskCachingEnabled;
@property (nonatomic) BOOL memoryCachingEnabled;
Expand Down
Loading