Skip to content

Commit

Permalink
Merge pull request Boris-Em#85 from skywinder/improve-Example
Browse files Browse the repository at this point in the history
Fix wrong presentation of years in code exmple + auto-update graph by clicking on segment controll
  • Loading branch information
Boris-Em committed Nov 2, 2014
2 parents 1e60d3a + 51c883a commit 8ac9651
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
17 changes: 12 additions & 5 deletions Sample Project/SimpleLineChart/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="j8C-nX-jcI">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A388b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="j8C-nX-jcI">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand All @@ -19,7 +20,7 @@
</objects>
<point key="canvasLocation" x="-61" y="130"/>
</scene>
<!--View Controller - Population Growth-->
<!--Population Growth-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
Expand Down Expand Up @@ -53,6 +54,9 @@
<segment title="Straight"/>
<segment title="Bezier"/>
</segments>
<connections>
<action selector="refresh:" destination="vXZ-lx-hvc" eventType="valueChanged" id="JTo-M3-LZO"/>
</connections>
</segmentedControl>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" id="39E-h4-zNa">
<rect key="frame" x="122" y="519" width="178" height="29"/>
Expand All @@ -61,6 +65,9 @@
<segment title="Yellow"/>
<segment title="Blue"/>
</segments>
<connections>
<action selector="refresh:" destination="vXZ-lx-hvc" eventType="valueChanged" id="LNC-fX-TaP"/>
</connections>
</segmentedControl>
<stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="11" minimumValue="3" maximumValue="140" id="YwO-xh-GEu">
<rect key="frame" x="20" y="519" width="94" height="29"/>
Expand Down Expand Up @@ -106,7 +113,7 @@
</objects>
<point key="canvasLocation" x="460" y="130"/>
</scene>
<!--Stats View Controller - Stats-->
<!--Stats-->
<scene sceneID="TBa-Ru-ahc">
<objects>
<tableViewController title="Stats" id="agL-Uo-Ja5" customClass="StatsViewController" sceneMemberID="viewController">
Expand Down Expand Up @@ -304,10 +311,10 @@
<point key="canvasLocation" x="1060" y="130"/>
</scene>
</scenes>
<color key="tintColor" red="0.1215686275" green="0.73333333329999995" blue="0.65098039220000004" alpha="1" colorSpace="calibratedRGB"/>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
<color key="tintColor" red="0.1215686275" green="0.73333333329999995" blue="0.65098039220000004" alpha="1" colorSpace="calibratedRGB"/>
</document>
4 changes: 2 additions & 2 deletions Sample Project/SimpleLineChart/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

@property (weak, nonatomic) IBOutlet BEMSimpleLineGraphView *myGraph;

@property (strong, nonatomic) NSMutableArray *ArrayOfValues;
@property (strong, nonatomic) NSMutableArray *ArrayOfDates;
@property (strong, nonatomic) NSMutableArray *arrayOfValues;
@property (strong, nonatomic) NSMutableArray *arrayOfDates;

@property (strong, nonatomic) IBOutlet UILabel *labelValues;
@property (strong, nonatomic) IBOutlet UILabel *labelDates;
Expand Down
42 changes: 21 additions & 21 deletions Sample Project/SimpleLineChart/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.ArrayOfValues = [[NSMutableArray alloc] init];
self.ArrayOfDates = [[NSMutableArray alloc] init];
self.arrayOfValues = [[NSMutableArray alloc] init];
self.arrayOfDates = [[NSMutableArray alloc] init];

previousStepperValue = self.graphObjectIncrement.value;
totalNumber = 0;

for (int i = 0; i < 9; i++) {
[self.ArrayOfValues addObject:@([self getRandomInteger])]; // Random values for the graph
[self.ArrayOfDates addObject:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:2000 + i]]]; // Dates for the X-Axis of the graph
[self.arrayOfValues addObject:@([self getRandomInteger])]; // Random values for the graph
[self.arrayOfDates addObject:[NSString stringWithFormat:@"%@", @(2000 + i)]]; // Dates for the X-Axis of the graph

totalNumber = totalNumber + [[self.ArrayOfValues objectAtIndex:i] intValue]; // All of the values added together
totalNumber = totalNumber + [[self.arrayOfValues objectAtIndex:i] intValue]; // All of the values added together
}

/* This is commented out because the graph is created in the interface with this sample app. However, the code remains as an example for creating the graph using code.
Expand Down Expand Up @@ -77,14 +77,14 @@ - (void)didReceiveMemoryWarning {
#pragma mark - Graph Actions

- (IBAction)refresh:(id)sender {
[self.ArrayOfValues removeAllObjects];
[self.ArrayOfDates removeAllObjects];
[self.arrayOfValues removeAllObjects];
[self.arrayOfDates removeAllObjects];

for (int i = 0; i < self.graphObjectIncrement.value; i++) {
[self.ArrayOfValues addObject:@([self getRandomInteger])]; // Random values for the graph
[self.ArrayOfDates addObject:[NSString stringWithFormat:@"Jan %@",[NSNumber numberWithInt:2000 + i]]]; // Dates for the X-Axis of the graph
[self.arrayOfValues addObject:@([self getRandomInteger])]; // Random values for the graph
[self.arrayOfDates addObject:[NSString stringWithFormat:@"%@", @(2000 + i)]]; // Dates for the X-Axis of the graph

totalNumber = totalNumber + [(self.ArrayOfValues)[i] intValue]; // All of the values added together
totalNumber = totalNumber + [(self.arrayOfValues)[i] intValue]; // All of the values added together
}
UIColor *color;
if (self.graphColorChoice.selectedSegmentIndex == 0) color = [UIColor colorWithRed:31.0/255.0 green:187.0/255.0 blue:166.0/255.0 alpha:1.0];
Expand Down Expand Up @@ -112,13 +112,13 @@ - (NSInteger)getRandomInteger
- (IBAction)addOrRemoveLineFromGraph:(id)sender {
if (self.graphObjectIncrement.value > previousStepperValue) {
// Add line
[self.ArrayOfValues addObject:@([self getRandomInteger])];
[self.ArrayOfDates addObject:[NSString stringWithFormat:@"%i", (int)[[self.ArrayOfDates lastObject] integerValue]+1]];
[self.arrayOfValues addObject:@([self getRandomInteger])];
[self.arrayOfDates addObject:[NSString stringWithFormat:@"%i", (int) [[self.arrayOfDates lastObject] integerValue] + 1]];
[self.myGraph reloadGraph];
} else if (self.graphObjectIncrement.value < previousStepperValue) {
// Remove line
[self.ArrayOfValues removeObjectAtIndex:0];
[self.ArrayOfDates removeObjectAtIndex:0];
[self.arrayOfValues removeObjectAtIndex:0];
[self.arrayOfDates removeObjectAtIndex:0];
[self.myGraph reloadGraph];
}

Expand Down Expand Up @@ -147,11 +147,11 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
#pragma mark - SimpleLineGraph Data Source

- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
return (int)[self.ArrayOfValues count];
return (int)[self.arrayOfValues count];
}

- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
return [[self.ArrayOfValues objectAtIndex:index] floatValue];
return [[self.arrayOfValues objectAtIndex:index] floatValue];
}

#pragma mark - SimpleLineGraph Delegate
Expand All @@ -161,13 +161,13 @@ - (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)grap
}

- (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index {
NSString *label = [self.ArrayOfDates objectAtIndex:index];
NSString *label = [self.arrayOfDates objectAtIndex:index];
return [label stringByReplacingOccurrencesOfString:@" " withString:@"\n"];
}

- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSInteger)index {
self.labelValues.text = [NSString stringWithFormat:@"%@", [self.ArrayOfValues objectAtIndex:index]];
self.labelDates.text = [NSString stringWithFormat:@"in %@", [self.ArrayOfDates objectAtIndex:index]];
self.labelValues.text = [NSString stringWithFormat:@"%@", [self.arrayOfValues objectAtIndex:index]];
self.labelDates.text = [NSString stringWithFormat:@"in %@", [self.arrayOfDates objectAtIndex:index]];
}

- (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithClosestIndex:(CGFloat)index {
Expand All @@ -176,7 +176,7 @@ - (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithCl
self.labelDates.alpha = 0.0;
} completion:^(BOOL finished) {
self.labelValues.text = [NSString stringWithFormat:@"%i", [[self.myGraph calculatePointValueSum] intValue]];
self.labelDates.text = [NSString stringWithFormat:@"between 2000 and %@", [self.ArrayOfDates lastObject]];
self.labelDates.text = [NSString stringWithFormat:@"between %@ and %@", [self.arrayOfDates firstObject], [self.arrayOfDates lastObject]];

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.labelValues.alpha = 1.0;
Expand All @@ -187,7 +187,7 @@ - (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithCl

- (void)lineGraphDidFinishLoading:(BEMSimpleLineGraphView *)graph {
self.labelValues.text = [NSString stringWithFormat:@"%i", [[self.myGraph calculatePointValueSum] intValue]];
self.labelDates.text = [NSString stringWithFormat:@"between 2000 and %@", [self.ArrayOfDates lastObject]];
self.labelDates.text = [NSString stringWithFormat:@"between %@ and %@", [self.arrayOfDates firstObject], [self.arrayOfDates lastObject]];
}

@end

0 comments on commit 8ac9651

Please sign in to comment.