Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 42bb744

Browse files
authored
Merge pull request #295 from mackworth/feature
New TestBed App and multiple bug fixes/cleanups
2 parents a1c0279 + e1c6fd6 commit 42bb744

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+8275
-554
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ osx_image: xcode8.2
33
xcode_project: Sample Project/SimpleLineChart.xcodeproj
44
xcode_scheme: SimpleLineChartTests
55
xcode_sdk: iphonesimulator
6+
script:
7+
- xcodebuild clean build test -project "Sample Project/SimpleLineChart.xcodeproj" -scheme SimpleLineChartTests -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 7" ONLY_ACTIVE_ARCH=NO

Classes/BEMAverageLine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
/// A line displayed horizontally across the graph at the average y-value
14-
@interface BEMAverageLine : NSObject
14+
@interface BEMAverageLine : NSObject <NSCoding>
1515

1616

1717
/// When set to YES, an average line will be displayed on the line graph
@@ -35,7 +35,7 @@
3535

3636

3737
/// Dash pattern for the average line
38-
@property (strong, nonatomic, nullable) NSArray *dashPattern;
38+
@property (strong, nonatomic, nullable) NSArray <NSNumber *> *dashPattern;
3939

4040

4141
//Label for average line in y axis. Default is blank.

Classes/BEMAverageLine.m

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,60 @@ - (instancetype)init {
1414
self = [super init];
1515
if (self) {
1616
_enableAverageLine = NO;
17-
_color = [UIColor whiteColor];
1817
_alpha = 1.0;
1918
_width = 3.0;
2019
_yValue = NAN;
2120
}
2221

2322
return self;
2423
}
25-
-(void) setLabel:(UILabel *)label {
24+
25+
- (instancetype) initWithCoder:(NSCoder *)coder {
26+
27+
#define RestoreProperty(property, type) {\
28+
if ([coder containsValueForKey:@#property]) { \
29+
self.property = [coder decode ## type ##ForKey:@#property ]; \
30+
}\
31+
}
32+
self = [self init];
33+
#pragma clang diagnostic push
34+
#pragma clang diagnostic ignored "-Wnullable-to-nonnull-conversion"
35+
36+
RestoreProperty (enableAverageLine, Bool);
37+
RestoreProperty (color, Object);
38+
RestoreProperty (yValue, Double);
39+
RestoreProperty (alpha, Double);
40+
RestoreProperty (width, Double);
41+
RestoreProperty (dashPattern, Object);
42+
RestoreProperty (title, Object);
43+
#pragma clang diagnostic pop
44+
45+
//AverageLine
46+
return self;
47+
}
48+
49+
- (void) encodeWithCoder: (NSCoder *)coder {
50+
51+
#define EncodeProperty(property, type) [coder encode ## type: self.property forKey:@#property]
52+
EncodeProperty (enableAverageLine, Bool);
53+
EncodeProperty (color, Object);
54+
EncodeProperty (yValue, Float);
55+
EncodeProperty (alpha, Float);
56+
EncodeProperty (width, Float);
57+
EncodeProperty (dashPattern, Object);
58+
EncodeProperty (title, Object);
59+
}
60+
61+
62+
63+
- (void)setLabel:(UILabel *)label {
2664
if (_label != label) {
2765
[_label removeFromSuperview];
2866
_label = label;
2967
}
3068
}
3169

32-
-(void) dealloc {
70+
- (void)dealloc {
3371
self.label= nil;
3472
}
3573
@end

Classes/BEMGraphCalculator.m

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ - (instancetype)init {
4141
// MARK: -
4242
// MARK: Essential Calculations
4343

44-
- (nonnull NSArray *)calculationDataPointsOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
44+
- (nonnull NSArray <NSNumber *> *)calculationDataPointsOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
4545
NSPredicate *filter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
4646
NSNumber *value = (NSNumber *)evaluatedObject;
4747
BOOL retVal = ![value isEqualToNumber:@(BEMNullGraphValue)];
4848
return retVal;
4949
}];
50-
NSArray *filteredArray = [[graph graphValuesForDataPoints] filteredArrayUsingPredicate:filter];
50+
NSArray <NSNumber *> *filteredArray = [[graph graphValuesForDataPoints] filteredArrayUsingPredicate:filter];
5151
return filteredArray;
5252
}
5353

5454
// MARK: -
5555
// MARK: Basic Statistics
5656

5757
- (nonnull NSNumber *)calculatePointValueAverageOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
58-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
58+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
5959
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
6060

6161
NSExpression *expression = [NSExpression expressionForFunction:@"average:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
@@ -65,7 +65,7 @@ - (nonnull NSNumber *)calculatePointValueAverageOnGraph:(nonnull BEMSimpleLineGr
6565
}
6666

6767
- (nonnull NSNumber *)calculatePointValueSumOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
68-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
68+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
6969
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
7070

7171
NSExpression *expression = [NSExpression expressionForFunction:@"sum:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
@@ -75,7 +75,7 @@ - (nonnull NSNumber *)calculatePointValueSumOnGraph:(nonnull BEMSimpleLineGraphV
7575
}
7676

7777
- (nonnull NSNumber *)calculatePointValueMedianOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
78-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
78+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
7979
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
8080

8181
NSExpression *expression = [NSExpression expressionForFunction:@"median:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
@@ -85,19 +85,19 @@ - (nonnull NSNumber *)calculatePointValueMedianOnGraph:(nonnull BEMSimpleLineGra
8585
}
8686

8787
- (nonnull NSNumber *)calculatePointValueModeOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
88-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
88+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
8989
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
9090

9191
NSExpression *expression = [NSExpression expressionForFunction:@"mode:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
92-
NSMutableArray *value = [expression expressionValueWithObject:nil context:nil];
93-
NSNumber *numberValue = [value firstObject];
92+
NSMutableArray <NSNumber *> *values = [expression expressionValueWithObject:nil context:nil];
93+
NSNumber *numberValue = [values firstObject];
9494

9595
if (numberValue) return numberValue;
9696
else return [NSNumber numberWithInt:0];
9797
}
9898

9999
- (nonnull NSNumber *)calculateStandardDeviationOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
100-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
100+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
101101
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
102102

103103
NSExpression *expression = [NSExpression expressionForFunction:@"stddev:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
@@ -110,7 +110,7 @@ - (nonnull NSNumber *)calculateStandardDeviationOnGraph:(nonnull BEMSimpleLineGr
110110
// MARK: Minimum / Maximum
111111

112112
- (nonnull NSNumber *)calculateMinimumPointValueOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
113-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
113+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
114114
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
115115

116116
NSExpression *expression = [NSExpression expressionForFunction:@"min:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
@@ -119,7 +119,7 @@ - (nonnull NSNumber *)calculateMinimumPointValueOnGraph:(nonnull BEMSimpleLineGr
119119
}
120120

121121
- (nonnull NSNumber *)calculateMaximumPointValueOnGraph:(nonnull BEMSimpleLineGraphView *)graph {
122-
NSArray *filteredArray = [self calculationDataPointsOnGraph:graph];
122+
NSArray <NSNumber *> *filteredArray = [self calculationDataPointsOnGraph:graph];
123123
if (filteredArray.count == 0) return [NSNumber numberWithInt:0];
124124

125125
NSExpression *expression = [NSExpression expressionForFunction:@"max:" arguments:@[[NSExpression expressionForConstantValue:filteredArray]]];
@@ -132,18 +132,18 @@ - (nonnull NSNumber *)calculateMaximumPointValueOnGraph:(nonnull BEMSimpleLineGr
132132
// MARK: Integration
133133

134134
- (nonnull NSNumber *)calculateAreaUsingIntegrationMethod:(BEMIntegrationMethod)integrationMethod onGraph:(nonnull BEMSimpleLineGraphView *)graph xAxisScale:(nonnull NSNumber *)scale {
135-
NSArray *fixedDataPoints = [self calculationDataPointsOnGraph:graph];
135+
NSArray <NSNumber *> *fixedDataPoints = [self calculationDataPointsOnGraph:graph];
136136
if (integrationMethod == BEMIntegrationMethodLeftReimannSum) return [self integrateUsingLeftReimannSum:fixedDataPoints xAxisScale:scale];
137137
else if (integrationMethod == BEMIntegrationMethodRightReimannSum) return [self integrateUsingRightReimannSum:fixedDataPoints xAxisScale:scale];
138138
else if (integrationMethod == BEMIntegrationMethodTrapezoidalSum) return [self integrateUsingTrapezoidalSum:fixedDataPoints xAxisScale:scale];
139139
else if (integrationMethod == BEMIntegrationMethodParabolicSimpsonSum) return [self integrateUsingParabolicSimpsonSum:fixedDataPoints xAxisScale:scale];
140140
else return [NSNumber numberWithInt:0];
141141
}
142142

143-
- (NSNumber *)integrateUsingLeftReimannSum:(nonnull NSArray *)graphPoints xAxisScale:(nonnull NSNumber *)scale {
143+
- (NSNumber *)integrateUsingLeftReimannSum:(nonnull NSArray <NSNumber *> *)graphPoints xAxisScale:(nonnull NSNumber *)scale {
144144
NSNumber *totalArea = [NSNumber numberWithInt:0];
145145

146-
NSMutableArray *leftSumPoints = graphPoints.mutableCopy;
146+
NSMutableArray <NSNumber *> *leftSumPoints = graphPoints.mutableCopy;
147147
[leftSumPoints removeLastObject];
148148

149149
for (NSNumber *yValue in leftSumPoints) {
@@ -154,10 +154,10 @@ - (NSNumber *)integrateUsingLeftReimannSum:(nonnull NSArray *)graphPoints xAxisS
154154
return totalArea;
155155
}
156156

157-
- (NSNumber *)integrateUsingRightReimannSum:(nonnull NSArray *)graphPoints xAxisScale:(nonnull NSNumber *)scale {
157+
- (NSNumber *)integrateUsingRightReimannSum:(nonnull NSArray <NSNumber *> *)graphPoints xAxisScale:(nonnull NSNumber *)scale {
158158
NSNumber *totalArea = [NSNumber numberWithInt:0];
159159

160-
NSMutableArray *rightSumPoints = graphPoints.mutableCopy;
160+
NSMutableArray <NSNumber *> *rightSumPoints = graphPoints.mutableCopy;
161161
[rightSumPoints removeObjectAtIndex:0];
162162

163163
for (NSNumber *yValue in rightSumPoints) {
@@ -168,16 +168,16 @@ - (NSNumber *)integrateUsingRightReimannSum:(nonnull NSArray *)graphPoints xAxis
168168
return totalArea;
169169
}
170170

171-
- (NSNumber *)integrateUsingTrapezoidalSum:(nonnull NSArray *)graphPoints xAxisScale:(nonnull NSNumber *)scale {
171+
- (NSNumber *)integrateUsingTrapezoidalSum:(nonnull NSArray <NSNumber *> *)graphPoints xAxisScale:(nonnull NSNumber *)scale {
172172
NSNumber *left = [self integrateUsingLeftReimannSum:graphPoints xAxisScale:scale];
173173
NSNumber *right = [self integrateUsingRightReimannSum:graphPoints xAxisScale:scale];
174174
NSNumber *trapezoidal = [NSNumber numberWithFloat:(left.floatValue+right.floatValue)/2];
175175
return trapezoidal;
176176
}
177177

178-
- (NSNumber *)integrateUsingParabolicSimpsonSum:(nonnull NSArray *)points xAxisScale:(nonnull NSNumber *)scale {
178+
- (NSNumber *)integrateUsingParabolicSimpsonSum:(nonnull NSArray <NSNumber *> *)points xAxisScale:(nonnull NSNumber *)scale {
179179
// Get all the points from the graph into a mutable array
180-
NSMutableArray *graphPoints = points.mutableCopy;
180+
NSMutableArray <NSNumber *> *graphPoints = points.mutableCopy;
181181

182182
// If there are two or fewer points on the graph, no parabolic curve can be created. Thus, the next most accurate method will be employed: a trapezoidal summation
183183
if (graphPoints.count <= 2) return [self integrateUsingTrapezoidalSum:points xAxisScale:scale];
@@ -233,8 +233,8 @@ - (NSNumber *)integrateUsingParabolicSimpsonSum:(nonnull NSArray *)points xAxisS
233233
- (NSNumber *)calculateCorrelationCoefficientUsingCorrelationMethod:(BEMCorrelationMethod)correlationMethod onGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(nonnull NSNumber *)scale {
234234
// Grab the x and y points
235235
// Because a BEMSimpleLineGraph object simply increments X-Values, we must calculate the values here
236-
NSArray *yPoints = [self calculationDataPointsOnGraph:graph];
237-
NSMutableArray *xPoints = [NSMutableArray arrayWithCapacity:yPoints.count];
236+
NSArray <NSNumber *> *yPoints = [self calculationDataPointsOnGraph:graph];
237+
NSMutableArray <NSNumber *> *xPoints = [NSMutableArray arrayWithCapacity:yPoints.count];
238238
if (scale == nil || scale.floatValue == 0.0) {
239239
for (NSUInteger i = 1; i <= yPoints.count; i++) {
240240
[xPoints addObject:[NSNumber numberWithInteger:i]];

Classes/BEMLine.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ typedef NS_ENUM(NSUInteger, BEMLineGradientDirection) {
4343
//----- POINTS -----//
4444

4545
/// All of the Y-axis values for the points
46-
@property (strong, nonatomic, nonnull) NSArray *arrayOfPoints;
46+
@property (strong, nonatomic, nonnull) NSArray <NSNumber *> *arrayOfPoints;
4747

4848
/// All of the X-Axis coordinates used to draw vertical lines through
49-
@property (strong, nonatomic, nonnull) NSArray *arrayOfVerticalReferenceLinePoints;
49+
@property (strong, nonatomic, nonnull) NSArray <NSNumber *> *arrayOfVerticalReferenceLinePoints;
5050

5151
/// The value used to offset the fringe vertical reference lines when the x-axis labels are on the edge
5252
@property (assign, nonatomic) CGFloat verticalReferenceHorizontalFringeNegation;
5353

5454
/// All of the Y-Axis coordinates used to draw horizontal lines through
55-
@property (strong, nonatomic, nullable) NSArray *arrayOfHorizontalReferenceLinePoints;
55+
@property (strong, nonatomic, nullable) NSArray <NSNumber *> *arrayOfHorizontalReferenceLinePoints;
5656

5757
/// All of the point values
58-
@property (strong, nonatomic, nullable) NSArray *arrayOfValues;
58+
@property (strong, nonatomic, nullable) NSArray <NSNumber *> *arrayOfValues;
5959

6060
/** Draw thin, translucent, reference lines using the provided X-Axis and Y-Axis coordinates.
6161
@see Use \p arrayOfVerticalReferenceLinePoints to specify vertical reference lines' positions. Use \p arrayOfHorizontalReferenceLinePoints to specify horizontal reference lines' positions. */
@@ -77,10 +77,10 @@ typedef NS_ENUM(NSUInteger, BEMLineGradientDirection) {
7777
@property (assign, nonatomic) BOOL enableTopReferenceFrameLine;
7878

7979
/** Dash pattern for the references line on the X axis */
80-
@property (nonatomic, strong, nullable) NSArray *lineDashPatternForReferenceXAxisLines;
80+
@property (nonatomic, strong, nullable) NSArray <NSNumber *> *lineDashPatternForReferenceXAxisLines;
8181

8282
/** Dash pattern for the references line on the Y axis */
83-
@property (nonatomic, strong, nullable) NSArray *lineDashPatternForReferenceYAxisLines;
83+
@property (nonatomic, strong, nullable) NSArray <NSNumber *> *lineDashPatternForReferenceYAxisLines;
8484

8585
/** If a null value is present, interpolation would draw a best fit line through the null point bound by its surrounding points. Default: YES */
8686
@property (assign, nonatomic) BOOL interpolateNullValues;
@@ -99,16 +99,16 @@ typedef NS_ENUM(NSUInteger, BEMLineGradientDirection) {
9999
@property (strong, nonatomic, nullable) UIColor *topColor;
100100

101101
/// A color gradient applied to the area above the line, inside of its superview. If set, it will be drawn on top of the fill from the \p topColor property.
102-
@property (assign, nonatomic, nullable) CGGradientRef topGradient;
102+
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef topGradient;
103103

104104
/// The color of the area below the line, inside of its superview
105105
@property (strong, nonatomic, nullable) UIColor *bottomColor;
106106

107107
/// A color gradient applied to the area below the line, inside of its superview. If set, it will be drawn on top of the fill from the \p bottomColor property.
108-
@property (assign, nonatomic, nullable) CGGradientRef bottomGradient;
108+
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef bottomGradient;
109109

110110
/// A color gradient to be applied to the line. If this property is set, it will mask (override) the \p color property.
111-
@property (assign, nonatomic, nullable) CGGradientRef lineGradient;
111+
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef lineGradient;
112112

113113
/// The drawing direction of the line gradient color
114114
@property (nonatomic) BEMLineGradientDirection lineGradientDirection;

0 commit comments

Comments
 (0)