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

Commit

Permalink
Add Initial (Partial) Swift Implementation
Browse files Browse the repository at this point in the history
Begins to address #105, #214, #262, #275, and #296.
  • Loading branch information
Sam Spencer committed Aug 4, 2017
1 parent 049c520 commit 0a29c20
Show file tree
Hide file tree
Showing 32 changed files with 2,391 additions and 209 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -76,48 +76,6 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
- (UIImage *)graphSnapshotImageRenderedWhileInBackground:(BOOL)appIsInBackground NS_AVAILABLE_IOS(7_0);


/** Calculates the average (mean) of all points on the line graph.
@return The average (mean) number of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculatePointValueAverage __deprecated_msg("Use calculatePointValueAverageOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** Calculates the sum of all points on the line graph.
@return The sum of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculatePointValueSum __deprecated_msg("Use calculatePointValueSumOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** Calculates the median of all points on the line graph.
@return The median number of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculatePointValueMedian __deprecated_msg("Use calculatePointValueMedianOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** Calculates the mode of all points on the line graph.
@return The mode number of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculatePointValueMode __deprecated_msg("Use calculatePointValueModeOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** Calculates the standard deviation of all points on the line graph.
@return The standard deviation of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculateLineGraphStandardDeviation __deprecated_msg("Use calculateLineGraphStandardDeviationAverageOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** Calculates the minimum value of all points on the line graph.
@return The minimum number of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculateMinimumPointValue __deprecated_msg("Use calculateMinimumPointValueAverageOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** Calculates the maximum value of all points on the line graph.
@return The maximum value of the points on the graph. Originally a float.
@deprecated Used a similar method with a shared instance of BEMGraphCalculator instead. */
- (NSNumber *)calculateMaximumPointValue __deprecated_msg("Use calculateMaximumPointValueOnGraph: on a shared instance of BEMGraphCalculator instead.");


/** All the displayed values of the X-Axis.
@return An array of NSStrings, one for each displayed X-Axis label. The array is sorted from the left side of the graph to the right side. */
- (nullable NSArray <NSString *> *)graphValuesForXAxis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//

#import "BEMSimpleLineGraphView.h"
#import "BEMGraphCalculator.h" //just for deprecation warnings; should be removed

const CGFloat BEMNullGraphValue = CGFLOAT_MAX;

Expand Down Expand Up @@ -509,21 +508,28 @@ - (void)drawEntireGraph {
}

- (CGFloat)labelWidthForValue:(CGFloat)value {
NSDictionary *attributes = @{NSFontAttributeName: self.labelFont};
UIFont *fontToUse = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
if (self.labelFont != nil) fontToUse = self.labelFont;

NSDictionary *attributes = @{NSFontAttributeName: fontToUse};
NSString *valueString = [self yAxisTextForValue:value];
NSString *labelString = [valueString stringByReplacingOccurrencesOfString:@"[0-9-]" withString:@"N" options:NSRegularExpressionSearch range:NSMakeRange(0, [valueString length])];
return [labelString sizeWithAttributes:attributes].width;
}

- (CGFloat)calculateWidestLabel {
NSDictionary *attributes = @{NSFontAttributeName: self.labelFont};
UIFont *fontToUse = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
if (self.labelFont != nil) fontToUse = self.labelFont;

NSDictionary *attributes = @{NSFontAttributeName: fontToUse};
CGFloat widestNumber;
if (self.autoScaleYAxis == YES){
if (self.autoScaleYAxis == YES) {
widestNumber = MAX([self labelWidthForValue:self.maxValue],
[self labelWidthForValue:self.minValue]);
} else {
widestNumber = [self labelWidthForValue:self.frame.size.height] ;
widestNumber = [self labelWidthForValue:self.frame.size.height] ;
}

if (self.averageLine.enableAverageLine) {
return MAX(widestNumber, [self.averageLine.title sizeWithAttributes:attributes].width);
} else {
Expand Down Expand Up @@ -1463,41 +1469,6 @@ - (CGFloat)yPositionForDotValue:(CGFloat)dotValue {

// MARK: - Deprecated Methods

- (NSNumber *)calculatePointValueSum {
[self printDeprecationTransitionWarningForOldMethod:@"calculatePointValueSum" replacementMethod:@"calculatePointValueSumOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculatePointValueSumOnGraph:self];
}

- (NSNumber *)calculatePointValueMode {
[self printDeprecationTransitionWarningForOldMethod:@"calculatePointValueMode" replacementMethod:@"calculatePointValueModeOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculatePointValueModeOnGraph:self];
}

- (NSNumber *)calculatePointValueMedian {
[self printDeprecationTransitionWarningForOldMethod:@"calculatePointValueMedian" replacementMethod:@"calculatePointValueMedianOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculatePointValueMedianOnGraph:self];
}

- (NSNumber *)calculatePointValueAverage {
[self printDeprecationTransitionWarningForOldMethod:@"calculatePointValueAverage" replacementMethod:@"calculatePointValueAverageOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculatePointValueAverageOnGraph:self];
}

- (NSNumber *)calculateMinimumPointValue {
[self printDeprecationTransitionWarningForOldMethod:@"calculateMinimumPointValue" replacementMethod:@"calculatePointValueAverageOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculateMinimumPointValueOnGraph:self];
}

- (NSNumber *)calculateMaximumPointValue {
[self printDeprecationTransitionWarningForOldMethod:@"calculateMaximumPointValue" replacementMethod:@"calculateMaximumPointValueOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculateMaximumPointValueOnGraph:self];
}

- (NSNumber *)calculateLineGraphStandardDeviation {
[self printDeprecationTransitionWarningForOldMethod:@"calculateLineGraphStandardDeviation" replacementMethod:@"calculateStandardDeviationOnGraph:" newObject:@"BEMGraphCalculator" sharedInstance:YES];
return [[BEMGraphCalculator sharedCalculator] calculateStandardDeviationOnGraph:self];
}

- (void)printDeprecationAndUnavailableWarningForOldMethod:(NSString *)oldMethod {
NSLog(@"[BEMSimpleLineGraph] UNAVAILABLE, DEPRECATION ERROR. The delegate method, %@, is both deprecated and unavailable. It is now a data source method. You must implement this method from BEMSimpleLineGraphDataSource. Update your delegate method as soon as possible. One of two things will now happen: A) an exception will be thrown, or B) the graph will not load.", oldMethod);
}
Expand Down
Loading

0 comments on commit 0a29c20

Please sign in to comment.