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

Commit

Permalink
Merge pull request #1 from iRareMedia/master
Browse files Browse the repository at this point in the history
Interface Initialization & Reload Data
  • Loading branch information
Boris-Em committed Jan 4, 2014
2 parents a3060ee + b3d7266 commit 0c9c8f6
Show file tree
Hide file tree
Showing 22 changed files with 487 additions and 1,120 deletions.
5 changes: 2 additions & 3 deletions BEMSimpleLineGraph/BEMAnimations.h
Expand Up @@ -6,16 +6,15 @@
// Copyright (c) 2013 Boris Emorine. All rights reserved.
//

//Class for the animation when the graph first gets created.

#import <Foundation/Foundation.h>
@import Foundation;
#import "BEMCircle.h"
#import "BEMLine.h"

@protocol BEMAnimationDelegate <NSObject>

@end

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

- (void)animationForDot:(NSInteger)dotIndex circleDot:(BEMCircle *)circleDot animationSpeed:(NSInteger)speed;
Expand Down
53 changes: 16 additions & 37 deletions BEMSimpleLineGraph/BEMAnimations.m
Expand Up @@ -10,50 +10,29 @@

@implementation BEMAnimations

//Animation of the dots
- (void)animationForDot:(NSInteger)dotIndex circleDot:(BEMCircle *)circleDot animationSpeed:(NSInteger)speed
{
// Animation of the dots
- (void)animationForDot:(NSInteger)dotIndex circleDot:(BEMCircle *)circleDot animationSpeed:(NSInteger)speed {
if (speed == 0) {
circleDot.alpha = 0;
}

else
{
[UIView animateWithDuration:0.5
delay:dotIndex/(speed*2.0)
options:UIViewAnimationOptionCurveEaseOut
animations:^{
circleDot.alpha = 0.7;
} completion:^(BOOL finished){
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
circleDot.alpha = 0;
} completion:^(BOOL finished){

}];
}];
} else {
[UIView animateWithDuration:0.5 delay:dotIndex/(speed*2.0) options:UIViewAnimationOptionCurveEaseOut animations:^{
circleDot.alpha = 0.7;
} completion:^(BOOL finished){
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
circleDot.alpha = 0;
} completion:nil];
}];
}
}

//Animation of the graph
- (void)animationForLine:(NSInteger)lineIndex line:(BEMLine *)line animationSpeed:(NSInteger)speed
{
// Animation of the graph
- (void)animationForLine:(NSInteger)lineIndex line:(BEMLine *)line animationSpeed:(NSInteger)speed {
if (speed == 0) {
line.alpha = 1.0;
}

else
{
[UIView animateWithDuration:1.0
delay:lineIndex/(speed*2.0)
options:UIViewAnimationOptionCurveEaseOut
animations:^{
line.alpha = 1.0;
} completion:^(BOOL finished){

}];
} else {
[UIView animateWithDuration:1.0 delay:lineIndex/(speed*2.0) options:UIViewAnimationOptionCurveEaseOut animations:^{
line.alpha = 1.0;
} completion:nil];
}
}

Expand Down
4 changes: 2 additions & 2 deletions BEMSimpleLineGraph/BEMCircle.h
Expand Up @@ -6,10 +6,10 @@
// Copyright (c) 2013 Boris Emorine. All rights reserved.
//

//Class to draw the cicrle for the points.

#import <UIKit/UIKit.h>
@import UIKit;

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

@end
8 changes: 4 additions & 4 deletions BEMSimpleLineGraph/BEMLine.h
Expand Up @@ -6,22 +6,22 @@
// Copyright (c) 2013 Boris Emorine. All rights reserved.
//

//Class to draw the line of the graph

#import <UIKit/UIKit.h>
@import UIKit;

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

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

//COLORS
// COLORS
@property (strong, nonatomic) UIColor *color;
@property (strong, nonatomic) UIColor *topColor;
@property (strong, nonatomic) UIColor *bottomColor;


//ALPHA
// ALPHA
@property (nonatomic) float topAlpha;
@property (nonatomic) float bottomAlpha;
@property (nonatomic) float lineAlpha;
Expand Down
109 changes: 52 additions & 57 deletions BEMSimpleLineGraph/BEMSimpleLineGraphView.h
Expand Up @@ -6,129 +6,124 @@
// Copyright (c) 2013 Boris Emorine. All rights reserved.
//

#import <UIKit/UIKit.h>
@import UIKit;
#import "BEMCircle.h"
#import "BEMLine.h"
#import "BEMAnimations.h"

/// Line Graph Delegate. Used to pupulate the graph with data, similar to how a UITableView works.
@protocol BEMSimpleLineGraphDelegate <NSObject>

@required

/////////////////////////////////////REQUIRED TO SET UP THE GRAPH/////////////////////////////////////////
//
//* The number of points along the X-axis of the graph.
//
// @return Number of points.
//

/** The number of points along the X-axis of the graph.
@return Number of points. */
- (int)numberOfPointsInGraph;
//
//
//
//* The vertical position for a point at given index. It corresponds to the Y-axis value of the Graph.
//
// @param index The index from left to right of a given point (X-axis). The first value for the index is 0.
//
// @return The Y-axis value at a given index.
//



/** The vertical position for a point at given index. It corresponds to the Y-axis value of the Graph.
@param index The index from left to right of a given point (X-axis). The first value for the index is 0.
@return The Y-axis value at a given index. */
- (float)valueForIndex:(NSInteger)index;

////////////////////////////////////////////////////////////////////////////////////////////////////////


@optional

/////////////////////////////////FOR GRAPH TO RESPOND TO TOUCH EVENTS///////////////////////////////////
//
//* Gets called when the user starts touching the graph. The property 'enableTouchReport' must be set to YES.
//
// @param index The closest index (X-axis) from the location the user is currently touching.
//
- (void)didTouchGraphWhithClosestIndex:(int)index;
//
//
//
//* Gets called when the user stops touching the graph.
//
// @param index The closest index (X-axis) from the location the user last touched.
//
- (void)didReleaseGraphWhithClosestIndex:(float)index;

/** Gets called when the user starts touching the graph. The property 'enableTouchReport' must be set to YES.
@param index The closest index (X-axis) from the location the user is currently touching. */
- (void)didTouchGraphWithClosestIndex:(int)index;



/** Gets called when the user stops touching the graph.
@param index The closest index (X-axis) from the location the user last touched. */
- (void)didReleaseGraphWithClosestIndex:(float)index;

////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////TO SET UP THE X-AXIS SCALE//////////////////////////////////////
//
//* The number of free space between labels on the X-axis to avoid overlapping.
// For example returning '1' would mean that half of the labels on the X-axis are not displayed: the first is not displayed, the second is, the third is not etc.
// Returning '0' would mean that all of the labels will be displayed.
// Finally, returning a value equal to the number of labels will only display the first and last label.
//
// @return The number of labels to "jump" between each displayed label on the X-axis.
//

/** The number of free space between labels on the X-axis to avoid overlapping.
@discussion For example returning '1' would mean that half of the labels on the X-axis are not displayed: the first is not displayed, the second is, the third is not etc. Returning '0' would mean that all of the labels will be displayed. Finally, returning a value equal to the number of labels will only display the first and last label.
@return The number of labels to "jump" between each displayed label on the X-axis. */
- (int)numberOfGapsBetweenLabels;
//
//
//
//* The string to display on the label on the X-axis at a given index. Please note that the number of strings to be returned should be equal to the number of points in the Graph.
//
// @param index The index from left to right of a given label on the X-axis. Is the same index as the one for the points. The first value for the index is 0.
//



/** The string to display on the label on the X-axis at a given index. Please note that the number of strings to be returned should be equal to the number of points in the Graph.
@param index The index from left to right of a given label on the X-axis. Is the same index as the one for the points. The first value for the index is 0. */
- (NSString *)labelOnXAxisForIndex:(NSInteger)index;

////////////////////////////////////////////////////////////////////////////////////////////////////////


@end

@interface BEMSimpleLineGraphView : UIView <BEMAnimationDelegate, UIGestureRecognizerDelegate>

@property (assign) id <BEMSimpleLineGraphDelegate> delegate;
@property (assign) IBOutlet id <BEMSimpleLineGraphDelegate> delegate;

@property (strong, nonatomic) BEMAnimations *animationDelegate;

@property (strong, nonatomic) UIView *verticalLine;

@property (strong, nonatomic) UIFont *labelFont;


/// Reload the graph, all delegate methods are called again and the graph is reloaded. Similar to calling reloadData on a UITableView.
- (void)reloadGraph;


/////////////////////////////////////PROPERTIES TO CUSTOMIZE THE GRAPH//////////////////////////////////////////////


//Speed of the animation when the graph appears. From 0 to 10, 0 meaning no animation, 1 very slow and 10 very fast. Default value is 5.
/// Speed of the animation when the graph appears. From 0 to 10, 0 meaning no animation, 1 very slow and 10 very fast. Default value is 5.
@property (nonatomic) NSInteger animationGraphEntranceSpeed;


//If set to yes, the graph will respond to touch events. The 2 methods above should therefore be implemented. Default value is NO.
/// If set to yes, the graph will respond to touch events. The 2 methods above should therefore be implemented. Default value is NO.
@property (nonatomic) BOOL enableTouchReport;


//Color of the bottom part of the graph (between the line and the X-axis).
/// Color of the bottom part of the graph (between the line and the X-axis).
@property (strong, nonatomic) UIColor *colorBottom;


//Alpha of the bottom part of the graph (between the line and the X-axis).
/// Alpha of the bottom part of the graph (between the line and the X-axis).
@property (nonatomic) float alphaBottom;


//Color of the top part of the graph (between the line and the top of the view the graph is drawn in).
/// Color of the top part of the graph (between the line and the top of the view the graph is drawn in).
@property (strong, nonatomic) UIColor *colorTop;


//Alpha of the top part of the graph (between the line and the top of the view the graph is drawn in).
/// Alpha of the top part of the graph (between the line and the top of the view the graph is drawn in).
@property (nonatomic) float alphaTop;


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


//Alpha of the line of the graph.
/// Alpha of the line of the graph.
@property (nonatomic) float alphaLine;

//Width of the line of the graph. Default value is 1.0.

/// Width of the line of the graph. Default value is 1.0.
@property (nonatomic) float widthLine;

//Color of the label's text displayed on the X-Axis.

/// Color of the label's text displayed on the X-Axis.
@property (strong, nonatomic) UIColor *colorXaxisLabel;

@end

@end

0 comments on commit 0c9c8f6

Please sign in to comment.