Skip to content

Commit f748530

Browse files
committed
Merge commit '3dd033de496f74a541c3117f3e7432cbb8bce2c7'
* commit '3dd033de496f74a541c3117f3e7432cbb8bce2c7': (37 commits) Remove unuseful breaking test Update .travis.yml Add "Graph" button to Compact devices Further fixes for more substantive comments on PR Boris-Em#295 Fix top reference line offset bug Adds categories for UIKit extensions in MasterVC Adds Options title for iPhone version of TestBed Only changes in storyboard due to newer IB Requested changes to PR 3295 Fixing breaks, spaces to match project style Explaining constant 4 in BEMLine (note bug on line76 0+offset should be 0) Bug fixes: Line clipsToBounds to avoid drawing outside the box (when extrapolating nulls or user set minValue too High) Top/Bottom reference lines were outside box When Bezier off and Interpolate nulls off, properly draws line segments now Removed VMA NSLog from TestBed/MasterController Fix bug with TouchLineInput color (doesn't change after initial setting) Allow use on iPhone and Split View Fix assorted bugs in BEMSimpleLineGraph, especially null-data related AverageLine: •Color should be picked up from line if not set (default nil) Typo in encoding macro Add colors, gradients, and alphas to TestBed Fix many bugs and buglets Create new TestBed app to manipulate almost all parameters Add coding to AverageLine Move gradient properties to strong to properly retain Fix compiler error about integers used in enums Change alwaysDisplayPopupatIndex to use NSUInteger for index instead of float Fix Frame warning in SimpleLineChart's launch Screen Add Types to all Arrays Add encoder/decoder for BEMLineGraph properties Add averageValue delegate method to allow BEMLineGraph to be separate from BEMCalculator Restore modifyPopUpView delegate method Use caption preferredFont instead of SystemFont fro NoData Handle overlapping labels better Reuse code for popup and permanent labels Travis CI Yet another Travis CI change Update .travis.yml N^th time's a charm? Storyboard Update (to fix Travis CI) Update .travis.yml Update .travis.yml ... # Conflicts: # Classes/BEMLine.m # Classes/BEMSimpleLineGraphView.h # Classes/BEMSimpleLineGraphView.m
2 parents a4e1436 + 3dd033d commit f748530

70 files changed

Lines changed: 10107 additions & 1767 deletions

File tree

Some content is hidden

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

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: objective-c
2-
osx_image: xcode7
3-
# xcode_project: Sample Project/SimpleLineChart.xcodeproj
4-
# xcode_scheme: SimpleLineChartTests
5-
# xcode_sdk: iphonesimulator
2+
osx_image: xcode8.2
3+
xcode_project: Sample Project/SimpleLineChart.xcodeproj
4+
xcode_scheme: SimpleLineChartTests
5+
xcode_sdk: iphonesimulator
66
script:
7-
- xcodebuild clean build test -project "Sample Project/SimpleLineChart.xcodeproj" -scheme SimpleLineChartTests -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
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
1818
@property (nonatomic) BOOL enableAverageLine;
1919

2020

2121
/// The color of the average line
22-
@property (strong, nonatomic) UIColor *color;
22+
@property (strong, nonatomic, nonnull) UIColor *color;
2323

2424

2525
/// The Y-Value of the average line. This could be an average, a median, a mode, sum, etc.
@@ -35,7 +35,14 @@
3535

3636

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

4040

41+
//Label for average line in y axis. Default is blank.
42+
@property (strong, nonatomic, nullable) NSString * title;
43+
44+
45+
/// Title label on screen
46+
@property (strong, nonatomic, nullable) UILabel *label;
47+
4148
@end

Classes/BEMAverageLine.m

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +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;
20-
_yValue = 0.0;
19+
_yValue = NAN;
2120
}
2221

2322
return self;
2423
}
2524

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 {
64+
if (_label != label) {
65+
[_label removeFromSuperview];
66+
_label = label;
67+
}
68+
}
69+
70+
- (void)dealloc {
71+
self.label= nil;
72+
}
2673
@end

Classes/BEMCircle.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
/// Set to YES if the data point circles should be constantly displayed. NO if they should only appear when relevant.
1919
@property (assign, nonatomic) BOOL shouldDisplayConstantly;
2020

21-
/// The point color
22-
@property (strong, nonatomic) UIColor *Pointcolor;
21+
/// The point's color
22+
@property (strong, nonatomic, nullable) UIColor *color;
23+
24+
/** The point color
25+
@deprecated This property is no longer in use. Please use the \p color property instead. */
26+
@property (strong, nonatomic, null_unspecified) UIColor *Pointcolor __deprecated_msg("Use color instead");
2327

2428
/// The value of the point
2529
@property (nonatomic) CGFloat absoluteValue;

Classes/BEMCircle.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
2323
- (void)drawRect:(CGRect)rect {
2424
CGContextRef ctx = UIGraphicsGetCurrentContext();
2525
CGContextAddEllipseInRect(ctx, rect);
26-
[self.Pointcolor set];
26+
[self.color set];
2727
CGContextFillPath(ctx);
2828
}
2929

Classes/BEMGraphCalculator.h

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//
2+
// BEMGraphCalculator.h
3+
// SimpleLineChart
4+
//
5+
// Created by Sam Spencer on 1/26/16.
6+
// Copyright © 2016 Boris Emorine. All rights reserved.
7+
//
8+
9+
@import Foundation;
10+
11+
#import "BEMSimpleLineGraphView.h"
12+
13+
/** There are multiple ways to find the area under the curve of a graph; \p BEMIntegrationMethod describes available methods for calculating this area.
14+
@discussion Finding the area under the curve of a graph becomes especially useful when charting rate over time. For example, finding the area of a graph that displays the speed of a cyclist at certain times would produce the total distance the cyclist traveled.
15+
@abstract Integration is a concept in calculus allowing one to find the area under a curve. However, integration requires manipulating the function of a graph. Because \p BEMSimpleLineGraphView objects rely on data points and not functions, other area-finding methods (with varying levels of accuracy) are employed here.
16+
@note As a general rule, the more accurate an integration method, the more computationally intense it may be. */
17+
typedef NS_ENUM (NSInteger, BEMIntegrationMethod) {
18+
/// Calculates area by finding the sum of all left–hand rectangles under each data point. This method gives the exact area when the graph's curve is constant. Low intensity computation.
19+
BEMIntegrationMethodLeftReimannSum = 0,
20+
/// Calculates area by finding the sum of all right–hand rectangles under each data point. This method gives the exact area when the graph's curve is constant. Low intensity computation.
21+
BEMIntegrationMethodRightReimannSum = 1,
22+
/// Calculates area by finding the sum of all trapezoids under each data point. This method gives the exact area when the graph's curve is constant or linear. Moderate intensity computation.
23+
BEMIntegrationMethodTrapezoidalSum = 2,
24+
/// Calculates area by finding the sum of all parabolas under each data point. This method gives the exact area when the graph's curve is constant, linear, quadratic, or cubic. Moderate intensity computation.
25+
BEMIntegrationMethodParabolicSimpsonSum = 3
26+
};
27+
28+
/** There are multiple methods to determine the correlation between points on a graph; \p BEMCorrelationMethod describes available methods for determining this coefficient.
29+
@discussion Discussion on data correlation to be added.
30+
@abstract Abstract on data correlation to be added.
31+
@note The greater the number of points on the given graph, the longer it may take to determine a correlation for those points. */
32+
typedef NS_ENUM (NSInteger, BEMCorrelationMethod) {
33+
/// Calculates the correlation coefficent for the graph using the common Pearson Correlation Method.
34+
BEMCorrelationMethodPearson = 0
35+
};
36+
37+
/** When calculating a correlation coefficient with the Pearson Correlation Method, \p BEMGraphCalculator can provide more general feedback as to the strength of the correlation. */
38+
typedef NS_ENUM (NSInteger, BEMPearsonCorrelationStrength) {
39+
/// Positive correlation value: 1.00 : 0.95
40+
BEMPearsonCorrelationPerfectPositive = 0,
41+
/// Positive correlation value: 0.94 : 0.50
42+
BEMPearsonCorrelationStrongPositive = 1,
43+
/// Positive correlation value: 0.49 : 0.06
44+
BEMPearsonCorrelationWeakPositive = 2,
45+
/// Positive correlation value: 0.05 : -0.05
46+
BEMPearsonCorrelationNone = 3,
47+
/// Positive correlation value: -0.06 : -0.49
48+
BEMPearsonCorrelationWeakNegative = 4,
49+
/// Positive correlation value: -0.50 : -0.94
50+
BEMPearsonCorrelationStrongNegative = 5,
51+
/// Positive correlation value: -0.95 : -1.00
52+
BEMPearsonCorrelationPerfectNegative = 6
53+
};
54+
55+
56+
NS_ASSUME_NONNULL_BEGIN
57+
58+
/** Makes calculations given for a specific graph object.
59+
@discussion Supply a graph object to the calculator to perform operations with that graph's data. Calculations may include the following:
60+
- Average value of points
61+
- Sum of points
62+
- Median of points
63+
- Mode of points
64+
- Graph standard deviation
65+
- Minimum point value on graph
66+
- Maximum point value on graph
67+
- Area under the curve of a graph
68+
- Correlation of data points */
69+
@interface BEMGraphCalculator : NSObject
70+
71+
+ (BEMGraphCalculator *)sharedCalculator;
72+
73+
/** Calculates the average (mean) of all points on the line graph.
74+
@return The average (mean) number of the points on the graph. Originally a float. */
75+
- (NSNumber *)calculatePointValueAverageOnGraph:(BEMSimpleLineGraphView *)graph;
76+
77+
78+
/** Calculates the sum of all points on the line graph.
79+
@return The sum of the points on the graph. Originally a float. */
80+
- (NSNumber *)calculatePointValueSumOnGraph:(BEMSimpleLineGraphView *)graph;
81+
82+
83+
/** Calculates the median of all points on the line graph.
84+
@return The median number of the points on the graph. Originally a float. */
85+
- (NSNumber *)calculatePointValueMedianOnGraph:(BEMSimpleLineGraphView *)graph;
86+
87+
88+
/** Calculates the mode of all points on the line graph.
89+
@return The mode number of the points on the graph. Originally a float. */
90+
- (NSNumber *)calculatePointValueModeOnGraph:(BEMSimpleLineGraphView *)graph;
91+
92+
93+
/** Calculates the standard deviation of all points on the line graph.
94+
@return The standard deviation of the points on the graph. Originally a float. */
95+
- (NSNumber *)calculateStandardDeviationOnGraph:(BEMSimpleLineGraphView *)graph;
96+
97+
98+
/** Calculates the minimum value of all points on the line graph.
99+
@return The minimum number of the points on the graph. Originally a float. */
100+
- (NSNumber *)calculateMinimumPointValueOnGraph:(BEMSimpleLineGraphView *)graph;
101+
102+
103+
/** Calculates the maximum value of all points on the line graph.
104+
@return The maximum value of the points on the graph. Originally a float. */
105+
- (NSNumber *)calculateMaximumPointValueOnGraph:(BEMSimpleLineGraphView *)graph;
106+
107+
108+
/** Calculates the area under the curve of the graph.
109+
@return The area under the curve of the graph. Accuracy varies based on selected integration method. Originally a float. */
110+
- (NSNumber *)calculateAreaUsingIntegrationMethod:(BEMIntegrationMethod)integrationMethod onGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(NSNumber *)scale;
111+
112+
113+
/** Calculates a correlation coefficient for the data points on the graph.
114+
@return A correlation coefficient, calculated from the graph's data points. Float value between -1.0 and 1.0. A value of -1.0 is a perfect negative correlation. A value of 1.0 is a perfect positive correlation. A value of 0.0 means that no correlation exists. */
115+
- (NSNumber *)calculateCorrelationCoefficientUsingCorrelationMethod:(BEMCorrelationMethod)correlationMethod onGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(nonnull NSNumber *)scale;
116+
117+
118+
/** Calculates a correlation coefficient and returns the general strength of the correlation, based on the data points on the given graph object.
119+
@return The strength of the calculated correlation coefficient; calculated from the graph's data points. This method assumes the Pearson Correlation Method. */
120+
- (BEMPearsonCorrelationStrength)calculatePearsonCorrelationStrengthOnGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(nonnull NSNumber *)scale;
121+
122+
123+
/** Calculates a correlation coefficient and returns the general strength of the correlation, based on the data points on the given graph object.
124+
@return The strength of the calculated correlation coefficient; calculated from the graph's data points. This method assumes the Pearson Correlation Method. */
125+
- (BEMPearsonCorrelationStrength)calculatePearsonCorrelationStrengthOnGraph:(BEMSimpleLineGraphView *)graph;
126+
127+
@end
128+
129+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)