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

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
V2.0

    Deprecated some delegate methods and replaced with newer delegate methods with more parameters.
    Made some properties private.

New Features

    New delegate methods to specify line color and alpha.
    New delegate methods that notify the delegate when the graph starts and ends updates.
    Added new calculation methods to calculate the graph's sum, average, standard deviation, median, mode, and more.
    Added a new graph snapshot method which efficiently captures a UIImage of the graph.
    Updated Sample App to reflect new features and changes.
    Added pre-compiler check for the Objective-C Module Build Setting. Modules are used if enabled, otherwise traditional imports are used.
    Added a warning for projects without ARC.

Fixed Issues

    Added call to super in layoutSubviews.
    The reloadGraph method now calls setNeedsLayout instead of directly calling layoutSubviews.
    Improved memory performance with @autoreleasepool blocks.
    Added Type-Safety for 64-bit architecture.
    Fixed X-Axis layout issues.
    Fixed typos.
  • Loading branch information
Boris-Em committed Mar 2, 2014
2 parents a0e7e0a + 816ce68 commit 6659f9d
Show file tree
Hide file tree
Showing 28 changed files with 1,435 additions and 293 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
.Trashes
Icon?
ehthumbs.db
Thumbs.db
Thumbs.db
xcuserdata/
*.xcuserstate

*.xcuserstate
31 changes: 28 additions & 3 deletions Classes/BEMAnimations.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,49 @@
// BEMAnimations.h
// SimpleLineGraph
//
// Created by Bobo on 12/27/13.
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//

@import Foundation;
#if __has_feature(objc_modules)
// We recommend enabling Objective-C Modules in your project Build Settings for numerous benefits over regular #imports
@import Foundation;
@import UIKit;
@import CoreGraphics;
#else
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#endif

#import "BEMCircle.h"
#import "BEMLine.h"



@protocol BEMAnimationDelegate <NSObject>

@end


/// Class for the animation when the graph first gets created.
@interface BEMAnimations : NSObject



/// Animation of the dots
- (void)animationForDot:(NSInteger)dotIndex circleDot:(BEMCircle *)circleDot animationSpeed:(NSInteger)speed;


/// Animation of the graph
- (void)animationForLine:(NSInteger)lineIndex line:(BEMLine *)line animationSpeed:(NSInteger)speed;



/// Animation Delegate
@property (assign) id <BEMAnimationDelegate> delegate;

@end


@end
5 changes: 2 additions & 3 deletions Classes/BEMAnimations.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// BEMAnimations.m
// SimpleLineGraph
//
// Created by Bobo on 12/27/13.
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//

#import "BEMAnimations.h"

@implementation BEMAnimations

// Animation of the dots
- (void)animationForDot:(NSInteger)dotIndex circleDot:(BEMCircle *)circleDot animationSpeed:(NSInteger)speed {
if (speed == 0) {
circleDot.alpha = 0;
Expand All @@ -25,7 +25,6 @@ - (void)animationForDot:(NSInteger)dotIndex circleDot:(BEMCircle *)circleDot ani
}
}

// Animation of the graph
- (void)animationForLine:(NSInteger)lineIndex line:(BEMLine *)line animationSpeed:(NSInteger)speed {
if (speed == 0) {
line.alpha = 1.0;
Expand Down
18 changes: 16 additions & 2 deletions Classes/BEMCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
// BEMCircle.h
// SimpleLineGraph
//
// Created by Bobo on 12/27/13.
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//


@import UIKit;
#if __has_feature(objc_modules)
// We recommend enabling Objective-C Modules in your project Build Settings for numerous benefits over regular #imports
@import Foundation;
@import UIKit;
@import CoreGraphics;
#else
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#endif



/// Class to draw the cicrle for the points.
@interface BEMCircle : UIView

@property (assign, nonatomic) BOOL shouldDisplayConstantly;

@end
10 changes: 5 additions & 5 deletions Classes/BEMCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// BEMCircle.m
// SimpleLineGraph
//
// Created by Bobo on 12/27/13.
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//

#import "BEMCircle.h"

@implementation BEMCircle
@synthesize shouldDisplayConstantly;

- (id)initWithFrame:(CGRect)frame
{
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
Expand All @@ -20,8 +21,7 @@ - (id)initWithFrame:(CGRect)frame
return self;
}

- (void)drawRect:(CGRect)rect
{
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, rect);
[[UIColor whiteColor] set];
Expand Down
70 changes: 62 additions & 8 deletions Classes/BEMLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,84 @@
// BEMLine.h
// SimpleLineGraph
//
// Created by Bobo on 12/27/13.
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//


@import UIKit;
#if __has_feature(objc_modules)
// We recommend enabling Objective-C Modules in your project Build Settings for numerous benefits over regular #imports
@import Foundation;
@import UIKit;
@import CoreGraphics;
#else
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#endif



/// Class to draw the line of the graph
@interface BEMLine : UIView

@property (assign, nonatomic) CGPoint firstPoint;
@property (assign, nonatomic) CGPoint secondPoint;

// COLORS

//----- POINTS -----//

/// The previous point. Necessary for Bezier curve
@property (assign, nonatomic) CGPoint P0;

/// The starting point of the line
@property (assign, nonatomic) CGPoint P1;

/// The ending point of the line
@property (assign, nonatomic) CGPoint P2;

/// The next point. Necessary for Bezier curve
@property (assign, nonatomic) CGPoint P3;




//----- COLORS -----//

/// The line color
@property (strong, nonatomic) UIColor *color;

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

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


// ALPHA


//----- ALPHA -----//

/// The line alpha
@property (nonatomic) float lineAlpha;

/// The alpha value of the area above the line, inside of its superview
@property (nonatomic) float topAlpha;

/// The alpha value of the area below the line, inside of its superview
@property (nonatomic) float bottomAlpha;
@property (nonatomic) float lineAlpha;





//----- SIZE -----//

/// The width of the line
@property (nonatomic) float lineWidth;

@end

//----- BEZIER CURVE -----//

@property (nonatomic) BOOL bezierCurveIsEnabled;

@end
66 changes: 43 additions & 23 deletions Classes/BEMLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,80 @@
// BEMLine.m
// SimpleLineGraph
//
// Created by Bobo on 12/27/13.
// Created by Bobo on 12/27/13. Updated by Sam Spencer on 1/11/14.
// Copyright (c) 2013 Boris Emorine. All rights reserved.
// Copyright (c) 2014 Sam Spencer.
//

#import "BEMLine.h"

@implementation BEMLine

- (id)initWithFrame:(CGRect)frame
{
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code

self.backgroundColor = [UIColor clearColor];
}
return self;
}

- (void)drawRect:(CGRect)rect
{
//FILL TOP
- (void)drawRect:(CGRect)rect {

CGPoint CP1;
CGPoint CP2;

if (self.bezierCurveIsEnabled == YES) { // BEZIER CURVE
CP1 = CGPointMake(self.P1.x + (self.P2.x - self.P1.x)/3, self.P1.y - (self.P1.y - self.P2.y)/3 - (self.P0.y - self.P1.y)*0.3); // First control point
CP2 = CGPointMake(self.P1.x + 2*(self.P2.x - self.P1.x)/3, (self.P1.y - 2*(self.P1.y - self.P2.y)/3) + (self.P2.y - self.P3.y)*0.3); // Second control point
}

CGContextRef ctx = UIGraphicsGetCurrentContext();


// FILL TOP

CGContextSetFillColorWithColor(ctx, [self.topColor CGColor]);
CGContextSetAlpha(ctx, self.topAlpha);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, round(self.firstPoint.x), self.firstPoint.y);
CGContextAddLineToPoint(ctx, round(self.secondPoint.x), self.secondPoint.y);
CGContextAddLineToPoint(ctx, round(self.secondPoint.x), self.frame.origin.y);
CGContextAddLineToPoint(ctx, round(self.firstPoint.x), self.frame.origin.x);
CGContextMoveToPoint(ctx, round(self.P1.x), self.P1.y);
if (self.bezierCurveIsEnabled == YES) {
CGContextAddCurveToPoint(ctx, CP1.x, CP1.y, CP2.x, CP2.y, self.P2.x, self.P2.y);
} else {
CGContextAddLineToPoint(ctx, round(self.P2.x), self.P2.y);
}
CGContextAddLineToPoint(ctx, round(self.P2.x), self.frame.origin.y);
CGContextAddLineToPoint(ctx, round(self.P1.x), self.frame.origin.x);
CGContextClosePath(ctx);

CGContextDrawPath(ctx, kCGPathFill);

//FILL BOTOM
// FILL BOTOM
CGContextSetFillColorWithColor(ctx, [self.bottomColor CGColor]);
CGContextSetAlpha(ctx, self.bottomAlpha);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, round(self.firstPoint.x), self.firstPoint.y);
CGContextAddLineToPoint(ctx, round(self.secondPoint.x), self.secondPoint.y);
CGContextAddLineToPoint(ctx, round(self.secondPoint.x), self.frame.size.height);
CGContextAddLineToPoint(ctx, round(self.firstPoint.x), self.frame.size.height);
CGContextMoveToPoint(ctx, round(self.P1.x), self.P1.y);
if (self.bezierCurveIsEnabled == YES) {
CGContextAddCurveToPoint(ctx, CP1.x, CP1.y, CP2.x, CP2.y, self.P2.x, self.P2.y);
} else {
CGContextAddLineToPoint(ctx, round(self.P2.x), self.P2.y);
}
CGContextAddLineToPoint(ctx, round(self.P2.x), self.frame.size.height);
CGContextAddLineToPoint(ctx, round(self.P1.x), self.frame.size.height);
CGContextClosePath(ctx);

CGContextDrawPath(ctx, kCGPathFill);

//LINE GRAPH
UIBezierPath *path1 = [UIBezierPath bezierPath];
//BEZIER CURVE

UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 setLineWidth:self.lineWidth];
[path1 moveToPoint:self.firstPoint];
[path1 addLineToPoint:self.secondPoint];
path1.lineCapStyle = kCGLineCapRound;
[path1 moveToPoint:self.P1];
if (self.bezierCurveIsEnabled == YES) { // BEZIER CURVE
[path1 addCurveToPoint:self.P2 controlPoint1:CP1 controlPoint2:CP2];
} else { // SIMPLE LINE
[path1 addLineToPoint:self.P2];
}
path1.lineCapStyle = kCGLineCapSquare;
[self.color set];
[path1 strokeWithBlendMode:kCGBlendModeNormal alpha:self.lineAlpha];
}
Expand Down
Loading

0 comments on commit 6659f9d

Please sign in to comment.