Skip to content

Commit

Permalink
Merge pull request ResearchKit#119 from dephillipsmichael/feature/gra…
Browse files Browse the repository at this point in the history
…phview_changes

Feature/graphview changes
  • Loading branch information
Erin-Mounts committed May 11, 2016
2 parents 4b24af9 + dc44faf commit f58ea53
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
3 changes: 3 additions & 0 deletions APCAppCore/APCAppCore/Library/Scoring/APCScoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ typedef NS_ENUM(NSUInteger, APHTimelineGroups)
//APCScoring Delegate
@property (weak, nonatomic) id<APCScoringDelegate> scoringDelegate;

//Exposed for APCGraphViewController
@property (nonatomic) NSInteger numberOfDays;

//Exposed for APCCorrelationsSelectorViewController
@property (nonatomic, strong) NSString *caption;
@property (nonatomic, strong) NSString *series1Name;
Expand Down
1 change: 0 additions & 1 deletion APCAppCore/APCAppCore/Library/Scoring/APCScoring.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ @interface APCScoring()
@property (nonatomic) APHTimelineGroups groupBy;
@property (nonatomic) NSUInteger current;
@property (nonatomic) NSUInteger correlatedCurrent;
@property (nonatomic) NSInteger numberOfDays;
@property (nonatomic) BOOL usesHealthKitData;
@property (nonatomic) BOOL latestOnly;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@

@class APCScoring;

static NSInteger const APCGraphView5DaysAgo = -5;
static NSInteger const APCGraphView7DaysAgo = -7;
static NSInteger const APCGraphView30DaysAgo = -30;
static NSInteger const APCGraphView90DaysAgo = -90;
static NSInteger const APCGraphView180DaysAgo = -180;
static NSInteger const APCGraphView365DaysAgo = -365;

typedef NS_ENUM(NSUInteger, APCGraphViewPeriod) {
APCGraphViewPeriodLast5Days = 0,
APCGraphViewPeriodLastWeek,
APCGraphViewPeriodLastMonth,
APCGraphViewPeriodLast3Months,
APCGraphViewPeriodLast6Months,
APCGraphViewPeriodLastYear
};

@interface APCGraphViewController : UIViewController <APCScoringDelegate>

@property (weak, nonatomic) IBOutlet APCLineGraphView *lineGraphView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ - (void)setupAppearance
[self.collapseButton.imageView setTintColor:self.graphItem.tintColor];

self.tintView.backgroundColor = self.graphItem.tintColor;

[self updateSegmentControlToGraphViewState];
}

- (void)setSubTitleText
Expand Down Expand Up @@ -187,40 +189,46 @@ - (IBAction)segmentControlChanged:(UISegmentedControl *)sender
[self presentViewController:_spinnerController animated:YES completion:nil];

switch (sender.selectedSegmentIndex) {
case 0:
case APCGraphViewPeriodLast5Days:
{
//Last 5 days
[self.graphItem.graphData updatePeriodForDays:-5 groupBy:APHTimelineGroupDay];
[self.graphItem.graphData updatePeriodForDays:APCGraphView5DaysAgo
groupBy:APHTimelineGroupDay];
}
break;
case 1:
case APCGraphViewPeriodLastWeek:
{
//Last 1 week (7 days)
[self.graphItem.graphData updatePeriodForDays:-7 groupBy:APHTimelineGroupDay];
[self.graphItem.graphData updatePeriodForDays:APCGraphView7DaysAgo
groupBy:APHTimelineGroupDay];
}
break;
case 2:
case APCGraphViewPeriodLastMonth:
{
//Last 1 Month (30 days)
[self.graphItem.graphData updatePeriodForDays:-30 groupBy:APHTimelineGroupWeek];
[self.graphItem.graphData updatePeriodForDays:APCGraphView30DaysAgo
groupBy:APHTimelineGroupWeek];
}
break;
case 3:
case APCGraphViewPeriodLast3Months:
{
//Last 3 Months (90 days)
[self.graphItem.graphData updatePeriodForDays:-90 groupBy:APHTimelineGroupMonth];
[self.graphItem.graphData updatePeriodForDays:APCGraphView90DaysAgo
groupBy:APHTimelineGroupMonth];
}
break;
case 4:
case APCGraphViewPeriodLast6Months:
{
//Last 6 Months (180 days)
[self.graphItem.graphData updatePeriodForDays:-180 groupBy:APHTimelineGroupMonth];
[self.graphItem.graphData updatePeriodForDays:APCGraphView180DaysAgo
groupBy:APHTimelineGroupMonth];
}
break;
case 5:
case APCGraphViewPeriodLastYear:
{
//Last 1 year (365 days)
[self.graphItem.graphData updatePeriodForDays:-365 groupBy:APHTimelineGroupMonth];
[self.graphItem.graphData updatePeriodForDays:APCGraphView365DaysAgo
groupBy:APHTimelineGroupMonth];
}
break;
default:
Expand Down Expand Up @@ -263,4 +271,36 @@ -(void)graphViewControllerShouldUpdateChartWithScoring:(APCScoring *)__unused sc
[self reloadCharts];
}

/*
* This method will sync up the graph period of the graph data with the segmented control that is selected
*/
- (void) updateSegmentControlToGraphViewState
{
// Number of days will be negative, so check for greater than
if (self.graphItem.graphData.numberOfDays > APCGraphView7DaysAgo)
{
[self.segmentedControl setSelectedSegmentIndex:APCGraphViewPeriodLast5Days];
}
else if (self.graphItem.graphData.numberOfDays > APCGraphView30DaysAgo)
{
[self.segmentedControl setSelectedSegmentIndex:APCGraphViewPeriodLastWeek];
}
else if (self.graphItem.graphData.numberOfDays > APCGraphView90DaysAgo)
{
[self.segmentedControl setSelectedSegmentIndex:APCGraphViewPeriodLastMonth];
}
else if (self.graphItem.graphData.numberOfDays > APCGraphView180DaysAgo)
{
[self.segmentedControl setSelectedSegmentIndex:APCGraphViewPeriodLast3Months];
}
else if (self.graphItem.graphData.numberOfDays > APCGraphView365DaysAgo)
{
[self.segmentedControl setSelectedSegmentIndex:APCGraphViewPeriodLast6Months];
}
else
{
[self.segmentedControl setSelectedSegmentIndex:APCGraphViewPeriodLastYear];
}
}

@end

0 comments on commit f58ea53

Please sign in to comment.