Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/BEMAverageLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


/// A line displayed horizontally across the graph at the average y-value
@interface BEMAverageLine : NSObject
@interface BEMAverageLine : NSObject <NSCoding>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Love that BEMAverageLine is now also NSCoding compliant.



/// When set to YES, an average line will be displayed on the line graph
Expand Down
39 changes: 39 additions & 0 deletions Classes/BEMAverageLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,45 @@ - (instancetype)init {

return self;
}

- (instancetype) initWithCoder:(NSCoder *)coder {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra space.


#define RestoreProperty(property, type) {\
if ([coder containsValueForKey:@#property]) { \
self.property = [coder decode ## type ##ForKey:@#property ]; \
}\
}
self = [self init];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullable-to-nonnull-conversion"

RestoreProperty (enableAverageLine, Bool);
RestoreProperty (color, Object);
RestoreProperty (yValue, Double);
RestoreProperty (alpha, Double);
RestoreProperty (width, Double);
RestoreProperty (dashPattern, Object);
RestoreProperty (title, Object);
#pragma clang diagnostic pop

//AverageLine
return self;
}

- (void) encodeWithCoder: (NSCoder *)coder {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra space.


#define EncodeProperty(property, type) [coder encode ## type :self.property forKey:@"property" ]
EncodeProperty (enableAverageLine, Bool);
EncodeProperty (color, Object);
EncodeProperty (yValue, Float);
EncodeProperty (alpha, Float);
EncodeProperty (width, Float);
EncodeProperty (dashPattern, Object);
EncodeProperty (title, Object);
}



-(void) setLabel:(UILabel *)label {
if (_label != label) {
[_label removeFromSuperview];
Expand Down
6 changes: 3 additions & 3 deletions Classes/BEMLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ typedef NS_ENUM(NSUInteger, BEMLineGradientDirection) {
@property (strong, nonatomic, nullable) UIColor *topColor;

/// 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.
@property (assign, nonatomic, nullable) CGGradientRef topGradient;
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef topGradient;

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

/// 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.
@property (assign, nonatomic, nullable) CGGradientRef bottomGradient;
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef bottomGradient;

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

/// The drawing direction of the line gradient color
@property (nonatomic) BEMLineGradientDirection lineGradientDirection;
Expand Down
22 changes: 11 additions & 11 deletions Classes/BEMLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ - (void)drawRect:(CGRect)rect {
if (self.enableReferenceLines == YES) {
if (self.arrayOfVerticalReferenceLinePoints.count > 0) {
for (NSNumber *xNumber in self.arrayOfVerticalReferenceLinePoints) {
CGFloat xValue;
CGFloat xValue =[xNumber doubleValue];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after =.

if (self.verticalReferenceHorizontalFringeNegation != 0.0) {
if ([self.arrayOfVerticalReferenceLinePoints indexOfObject:xNumber] == 0) { // far left reference line
xValue = [xNumber floatValue] + self.verticalReferenceHorizontalFringeNegation;
} else if ([self.arrayOfVerticalReferenceLinePoints indexOfObject:xNumber] == [self.arrayOfVerticalReferenceLinePoints count]-1) { // far right reference line
xValue = [xNumber floatValue] - self.verticalReferenceHorizontalFringeNegation;
} else xValue = [xNumber floatValue];
} else xValue = [xNumber floatValue];

NSUInteger index = [self.arrayOfVerticalReferenceLinePoints indexOfObject:xNumber];
if (index == 0) { // far left reference line
xValue += self.verticalReferenceHorizontalFringeNegation;
} else if (index == [self.arrayOfVerticalReferenceLinePoints count]-1) { // far right reference line
xValue -= self.verticalReferenceHorizontalFringeNegation;
}
}
CGPoint initialPoint = CGPointMake(xValue, self.frame.size.height);
CGPoint finalPoint = CGPointMake(xValue, 0);

Expand Down Expand Up @@ -178,15 +178,15 @@ - (void)drawRect:(CGRect)rect {
CGContextSaveGState(ctx);
CGContextAddPath(ctx, [fillTop CGPath]);
CGContextClip(ctx);
CGContextDrawLinearGradient(ctx, self.topGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillTop.bounds)), 0);
CGContextDrawLinearGradient(ctx, self.topGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillTop.bounds)), (CGGradientDrawingOptions) 0);
CGContextRestoreGState(ctx);
}

if (self.bottomGradient != nil) {
CGContextSaveGState(ctx);
CGContextAddPath(ctx, [fillBottom CGPath]);
CGContextClip(ctx);
CGContextDrawLinearGradient(ctx, self.bottomGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillBottom.bounds)), 0);
CGContextDrawLinearGradient(ctx, self.bottomGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillBottom.bounds)), (CGGradientDrawingOptions) 0);
CGContextRestoreGState(ctx);
}

Expand Down Expand Up @@ -401,7 +401,7 @@ - (CALayer *)backgroundGradientLayerForLayer:(CAShapeLayer *)shapeLayer {
end = CGPointMake(CGRectGetMidX(shapeLayer.bounds), CGRectGetMaxY(shapeLayer.bounds));
}

CGContextDrawLinearGradient(imageCtx, self.lineGradient, start, end, 0);
CGContextDrawLinearGradient(imageCtx, self.lineGradient, start, end, (CGGradientDrawingOptions)0);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CALayer *gradientLayer = [CALayer layer];
Expand Down
8 changes: 4 additions & 4 deletions Classes/BEMSimpleLineGraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel


/// Fill gradient of the bottom part of the graph (between the line and the X-axis). When set, it will draw a gradient over top of the fill provided by the \p colorBottom and \p alphaBottom properties.
@property (assign, nonatomic, nullable) CGGradientRef gradientBottom;
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef gradientBottom;


/// Color of the top part of the graph (between the line and the top of the view the graph is drawn in).
Expand All @@ -252,15 +252,15 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel


/// Fill gradient of the top part of the graph (between the line and the top of the view the graph is drawn in). When set, it will draw a gradient over top of the fill provided by the \p colorTop and \p alphaTop properties.
@property (assign, nonatomic, nullable) CGGradientRef gradientTop;
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef gradientTop;


/// Color of the line of the graph.
@property (strong, nonatomic) IBInspectable UIColor *colorLine;


/// Fill gradient of the line of the graph, which will be scaled to the length of the graph. Overrides the line color provided by \p colorLine
@property (assign, nonatomic) CGGradientRef gradientLine;
@property (strong, nonatomic, nullable) __attribute__((NSObject)) CGGradientRef gradientLine;


/// The drawing direction of the line gradient color, which defaults to horizontal
Expand Down Expand Up @@ -473,7 +473,7 @@ IB_DESIGNABLE @interface BEMSimpleLineGraphView : UIView <UIGestureRecognizerDel
@param graph The graph object requesting the total number of points.
@param index The index from left to right of the points on the graph. The first value for the index is 0.
@return Return YES if you want the popup label to be displayed for this index. */
- (BOOL)lineGraph:(BEMSimpleLineGraphView *)graph alwaysDisplayPopUpAtIndex:(CGFloat)index;
- (BOOL)lineGraph:(BEMSimpleLineGraphView *)graph alwaysDisplayPopUpAtIndex:(NSUInteger)index;


/** Optional method to set the maximum value of the Y-Axis. If not implemented, the maximum value will be the biggest point of the graph.
Expand Down
1 change: 0 additions & 1 deletion Classes/BEMSimpleLineGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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

const CGFloat BEMNullGraphValue = CGFLOAT_MAX;

Expand Down
Loading